mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
feat: begin work on beer type page and associated api routes
This commit is contained in:
24
src/services/BeerTypes/getAllBeerTypes.ts
Normal file
24
src/services/BeerTypes/getAllBeerTypes.ts
Normal 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;
|
||||
14
src/services/BeerTypes/schema/BeerTypeQueryResult.ts
Normal file
14
src/services/BeerTypes/schema/BeerTypeQueryResult.ts
Normal 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;
|
||||
Reference in New Issue
Block a user