Merge pull request #53 from calcom/fix/51-delete-schedule-unset-default
commit
70fd578a0f
|
@ -100,7 +100,7 @@ export async function attendeeById(req: NextApiRequest, res: NextApiResponse<Att
|
|||
const attendees = userBookings.map((booking) => booking.attendees).flat();
|
||||
const attendeeIds = attendees.map((attendee) => attendee.id);
|
||||
// Here we make sure to only return attendee's of the user's own bookings.
|
||||
if (!attendeeIds.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" });
|
||||
if (!attendeeIds.includes(safeQuery.data.id)) res.status(401).json({ message: "Unauthorized" });
|
||||
else {
|
||||
switch (method) {
|
||||
case "GET":
|
||||
|
|
|
@ -126,6 +126,20 @@ export async function scheduleById(req: NextApiRequest, res: NextApiResponse<Sch
|
|||
break;
|
||||
|
||||
case "DELETE":
|
||||
// Look for user to check if schedule is user's default
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) throw new Error("User not found");
|
||||
if (user.defaultScheduleId === safeQuery.data.id) {
|
||||
// unset default
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
id: userId,
|
||||
},
|
||||
data: {
|
||||
defaultScheduleId: undefined,
|
||||
},
|
||||
});
|
||||
}
|
||||
await prisma.schedule
|
||||
.delete({ where: { id: safeQuery.data.id } })
|
||||
.then(() =>
|
||||
|
|
|
@ -91,7 +91,7 @@ export async function userById(req: NextApiRequest, res: NextApiResponse<UserRes
|
|||
const safeBody = schemaUserBodyParams.safeParse(body);
|
||||
if (!safeQuery.success) throw new Error("Invalid request query", safeQuery.error);
|
||||
const userId = req.userId;
|
||||
if (safeQuery.data.id !== userId) res.status(401).json({ message: "Unauthorized" });
|
||||
if (safeQuery.data.id !== userId) res.status(401).json({ message: "Unauthorized" });
|
||||
else {
|
||||
switch (method) {
|
||||
case "GET":
|
||||
|
|
Loading…
Reference in New Issue