Work on brewery page, refactors

Refactor query types to explicitly use z.infer
This commit is contained in:
Aaron William Po
2023-03-31 21:13:35 -04:00
parent d8a8dad37f
commit b69dbc95b4
33 changed files with 308 additions and 243 deletions

View File

@@ -1,24 +1,26 @@
import DBClient from '@/prisma/DBClient';
import { BeerPostQueryResult } from '@/services/BeerPost/schema/BeerPostQueryResult';
import beerPostQueryResult from '@/services/BeerPost/schema/BeerPostQueryResult';
import { z } from 'zod';
const prisma = DBClient.instance;
const getBeerPostById = async (id: string) => {
const beerPost: BeerPostQueryResult | null = await prisma.beerPost.findFirst({
select: {
id: true,
name: true,
ibu: true,
abv: true,
createdAt: true,
description: true,
postedBy: { select: { username: true, id: true } },
brewery: { select: { name: true, id: true } },
type: { select: { name: true, id: true } },
beerImages: { select: { alt: true, path: true, caption: true, id: true } },
},
where: { id },
});
const beerPost: z.infer<typeof beerPostQueryResult> | null =
await prisma.beerPost.findFirst({
select: {
id: true,
name: true,
ibu: true,
abv: true,
createdAt: true,
description: true,
postedBy: { select: { username: true, id: true } },
brewery: { select: { name: true, id: true } },
type: { select: { name: true, id: true } },
beerImages: { select: { alt: true, path: true, caption: true, id: true } },
},
where: { id },
});
return beerPost;
};