Availability default bug (#4345)

Co-authored-by: Nitesh Singh <[email protected]>
Co-authored-by: gitstart <[email protected]>
Co-authored-by: Grace Nshokano <[email protected]>
Co-authored-by: Thiago Nascimbeni <[email protected]>
Co-authored-by: gitstart <[email protected]>
Co-authored-by: Olusanya Timothy <[email protected]>
Co-authored-by: seunexplicit <[email protected]>
Co-authored-by: Matheus Muniz <[email protected]>

Co-authored-by: gitstart <[email protected]>
Co-authored-by: Nitesh Singh <[email protected]>
Co-authored-by: Grace Nshokano <[email protected]>
Co-authored-by: Thiago Nascimbeni <[email protected]>
Co-authored-by: gitstart <[email protected]>
Co-authored-by: Olusanya Timothy <[email protected]>
Co-authored-by: seunexplicit <[email protected]>
Co-authored-by: Matheus Muniz <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
1 file changed
+14 -2
@@ -155,13 +155,25 @@ export const availabilityRouter = createProtectedRouter()
if (scheduleToDelete?.userId !== user.id) throw new TRPCError({ code: "UNAUTHORIZED" });
if (user.defaultScheduleId === input.scheduleId) {
// unset default
// set a new default or unset default if no other schedule
const scheduleToSetAsDefault = await prisma.schedule.findFirst({
where: {
userId: user.id,
NOT: {
id: input.scheduleId,
},
},
select: {
id: true,
},
});
await prisma.user.update({
where: {
id: user.id,
},
data: {
defaultScheduleId: undefined,
defaultScheduleId: scheduleToSetAsDefault?.id,
},
});
}