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,13 +1,14 @@
import DBClient from '@/prisma/DBClient';
import { BeerPostQueryResult } from '@/services/BeerPost/schema/BeerPostQueryResult';
import { BeerCommentQueryResultArrayT } from './schema/BeerCommentQueryResult';
import beerPostQueryResult from '@/services/BeerPost/schema/BeerPostQueryResult';
import { z } from 'zod';
import BeerCommentQueryResult from './schema/BeerCommentQueryResult';
const getAllBeerComments = async (
{ id }: Pick<BeerPostQueryResult, 'id'>,
{ id }: Pick<z.infer<typeof beerPostQueryResult>, 'id'>,
{ pageSize, pageNum = 0 }: { pageSize: number; pageNum?: number },
) => {
const skip = (pageNum - 1) * pageSize;
const beerComments: BeerCommentQueryResultArrayT =
const beerComments: z.infer<typeof BeerCommentQueryResult>[] =
await DBClient.instance.beerComment.findMany({
skip,
take: pageSize,

View File

@@ -1,8 +1,8 @@
import { z } from 'zod';
export const BeerCommentQueryResult = z.object({
const BeerCommentQueryResult = z.object({
id: z.string().uuid(),
content: z.string().min(1).max(300),
content: z.string().min(1).max(500),
rating: z.number().int().min(1).max(5),
createdAt: z.coerce.date(),
postedBy: z.object({
@@ -10,6 +10,5 @@ export const BeerCommentQueryResult = z.object({
username: z.string().min(1).max(50),
}),
});
export const BeerCommentQueryResultArray = z.array(BeerCommentQueryResult);
export type BeerCommentQueryResultT = z.infer<typeof BeerCommentQueryResult>;
export type BeerCommentQueryResultArrayT = z.infer<typeof BeerCommentQueryResultArray>;
export default BeerCommentQueryResult;