Fix type error with null being an invalid value (#213)

pull/9078/head
Alex van Andel 2022-11-18 11:38:49 +00:00 committed by GitHub
parent 51bc3d93c1
commit e5827b035d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -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<typeof data.metadata> | 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) };
}

View File

@ -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<typeof data.metadata> | 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 },