feat: begin work on beer type page and associated api routes

This commit is contained in:
Aaron William Po
2023-09-17 20:27:33 -04:00
parent 7c42146751
commit 6b8682e686
12 changed files with 377 additions and 28 deletions

View File

@@ -0,0 +1,24 @@
import DBClient from '@/prisma/DBClient';
import { z } from 'zod';
import BeerTypeQueryResult from './schema/BeerTypeQueryResult';
const getAllBeerTypes = async (
pageNum: number,
pageSize: number,
): Promise<z.infer<typeof BeerTypeQueryResult>[]> => {
const types = await DBClient.instance.beerType.findMany({
take: pageSize,
skip: (pageNum - 1) * pageSize,
select: {
id: true,
name: true,
postedBy: { select: { id: true, username: true } },
createdAt: true,
updatedAt: true,
},
});
return types;
};
export default getAllBeerTypes;

View File

@@ -0,0 +1,14 @@
import { z } from 'zod';
const BeerTypeQueryResult = z.object({
id: z.string().cuid(),
name: z.string(),
postedBy: z.object({
id: z.string().cuid(),
username: z.string(),
}),
createdAt: z.coerce.date(),
updatedAt: z.coerce.date().nullable(),
});
export default BeerTypeQueryResult;