Skip to content

Instantly share code, notes, and snippets.

@nmquebb
Last active March 17, 2023 17:38
Show Gist options
  • Select an option

  • Save nmquebb/536a98bf19bbd2c16d47b4624104ea6a to your computer and use it in GitHub Desktop.

Select an option

Save nmquebb/536a98bf19bbd2c16d47b4624104ea6a to your computer and use it in GitHub Desktop.
const fileSchema = z.union([
z.object({
type: z.literal('image'),
width: z.number().int(),
height: z.number().int(),
}),
z.object({
type: z.literal('pdf'),
pages: z.number().int(),
}),
]);
export const prisma = new PrismaClient().$extends({
model: {
file: {
async findUniqueExtended(args: Prisma.FileFindUniqueArgs) {
const file = await prisma.file.findUnique({
...args,
include: {
...args.include,
fileImage: true,
filePdf: true,
},
});
return fileSchema.parse({
...file.fileImage,
...file.filePdf,
...file,
});
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment