minor change

feat/add-edit-event-type-children-via-api
alishaz-polymath 2023-10-10 15:42:38 +04:00
parent efe2a8baf5
commit fbd39f1eca
2 changed files with 6 additions and 4 deletions

View File

@ -213,16 +213,19 @@ export async function patchHandler(req: NextApiRequest) {
...parsedBody
} = schemaEventTypeEditBodyParams.parse(body);
// validate children ownership
const validatedChildren =
parsedBody.teamId && parsedChildren
? parsedChildren.filter((child) => isUserMemberOfTeam(parsedBody.teamId, child.userId))
: [];
const data: Prisma.EventTypeUpdateArgs["data"] = {
...parsedBody,
bookingLimits: bookingLimits === null ? Prisma.DbNull : bookingLimits,
durationLimits: durationLimits === null ? Prisma.DbNull : durationLimits,
...(parsedChildren
...(validatedChildren
? {
children: {
connect: parsedChildren.map((child) => ({ id: child.id })),
connect: validatedChildren.map((child) => ({ id: child.id })),
},
}
: {}),

View File

@ -273,7 +273,6 @@ async function postHandler(req: NextApiRequest) {
...parsedBody
} = schemaEventTypeCreateBodyParams.parse(body || {});
// validate that these child event type owners are members of parent
const validatedChildren =
parsedBody.teamId && parsedChildren
? parsedChildren.filter((child) => isUserMemberOfTeam(parsedBody.teamId, child.userId))