feat: begin work on delete beer style

This commit is contained in:
Aaron William Po
2023-09-24 00:57:30 -04:00
parent cb26df286a
commit 17ec5ab459
4 changed files with 58 additions and 10 deletions

View File

@@ -0,0 +1,28 @@
import DBClient from '@/prisma/DBClient';
import { z } from 'zod';
import BeerPostQueryResult from './schema/BeerPostQueryResult';
const deleteBeerPostById = async (
id: string,
): Promise<z.infer<typeof BeerPostQueryResult> | null> => {
const deleted = await DBClient.instance.beerPost.delete({
where: { id },
select: {
id: true,
name: true,
brewery: { select: { id: true, name: true } },
description: true,
beerImages: { select: { id: true, path: true, caption: true, alt: true } },
ibu: true,
abv: true,
style: { select: { id: true, name: true, description: true } },
postedBy: { select: { id: true, username: true } },
createdAt: true,
updatedAt: true,
},
});
return deleted;
};
export default deleteBeerPostById;

View File

@@ -0,0 +1,24 @@
import { z } from 'zod';
import DBClient from '@/prisma/DBClient';
import BeerStyleQueryResult from './schema/BeerStyleQueryResult';
const deleteBeerStyleById = async (id: string) => {
const deleted = await DBClient.instance.beerStyle.delete({
where: { id },
select: {
id: true,
name: true,
createdAt: true,
updatedAt: true,
abvRange: true,
ibuRange: true,
description: true,
postedBy: { select: { id: true, username: true } },
glassware: { select: { id: true, name: true } },
},
});
return deleted as z.infer<typeof BeerStyleQueryResult> | null;
};
export default deleteBeerStyleById;

View File

@@ -6,7 +6,7 @@ const getAllBeerStyles = async (
pageNum: number,
pageSize: number,
): Promise<z.infer<typeof BeerStyleQueryResult>[]> => {
const styles = (await DBClient.instance.beerStyle.findMany({
const styles = await DBClient.instance.beerStyle.findMany({
take: pageSize,
skip: (pageNum - 1) * pageSize,
select: {
@@ -20,9 +20,9 @@ const getAllBeerStyles = async (
description: true,
glassware: { select: { id: true, name: true } },
},
})) as z.infer<typeof BeerStyleQueryResult>[];
});
return styles;
return styles as z.infer<typeof BeerStyleQueryResult>[];
};
export default getAllBeerStyles;