From e5827b035d696257609c3da413a26046e947c189 Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Fri, 18 Nov 2022 11:38:49 +0000 Subject: [PATCH] Fix type error with null being an invalid value (#213) --- pages/api/teams/[teamId]/_patch.ts | 9 ++++++++- pages/api/teams/_post.ts | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pages/api/teams/[teamId]/_patch.ts b/pages/api/teams/[teamId]/_patch.ts index a8782d5a4c..701464223b 100644 --- a/pages/api/teams/[teamId]/_patch.ts +++ b/pages/api/teams/[teamId]/_patch.ts @@ -38,7 +38,14 @@ export async function patchHandler(req: NextApiRequest) { where: { id: teamId, members: { some: { userId, role: { in: ["OWNER", "ADMIN"] } } } }, }); if (!_team) throw new HttpError({ statusCode: 401, message: "Unauthorized: OWNER or ADMIN required" }); - const team = await prisma.team.update({ where: { id: teamId }, data }); + // TODO: Perhaps there is a better fix for this? + const cloneData: typeof data & { + metadata: NonNullable | undefined; + } = { + ...data, + metadata: data.metadata === null ? {} : data.metadata || undefined, + }; + const team = await prisma.team.update({ where: { id: teamId }, data: cloneData }); return { team: schemaTeamReadPublic.parse(team) }; } diff --git a/pages/api/teams/_post.ts b/pages/api/teams/_post.ts index 54b8706d55..41207255ce 100644 --- a/pages/api/teams/_post.ts +++ b/pages/api/teams/_post.ts @@ -24,9 +24,16 @@ import { schemaTeamBodyParams, schemaTeamReadPublic } from "@lib/validations/tea async function postHandler(req: NextApiRequest) { const { prisma, body, userId } = req; const data = schemaTeamBodyParams.parse(body); + // TODO: Perhaps there is a better fix for this? + const cloneData: typeof data & { + metadata: NonNullable | undefined; + } = { + ...data, + metadata: data.metadata === null ? {} : data.metadata || undefined, + }; const team = await prisma.team.create({ data: { - ...data, + ...cloneData, members: { // We're also creating the relation membership of team ownership in this call. create: { userId, role: "OWNER", accepted: true },