Last active
March 17, 2023 17:38
-
-
Save nmquebb/536a98bf19bbd2c16d47b4624104ea6a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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