misc: Rename beer type to beer style

This commit is contained in:
Aaron William Po
2023-09-18 15:44:56 -04:00
parent 6b8682e686
commit af09928c3c
30 changed files with 1192 additions and 183 deletions

View File

@@ -12,7 +12,7 @@ const createNewBeerPost = async ({
description,
abv,
ibu,
typeId,
styleId,
breweryId,
userId,
}: z.infer<typeof CreateBeerPostWithUserSchema>) => {
@@ -23,7 +23,7 @@ const createNewBeerPost = async ({
description,
abv,
ibu,
type: { connect: { id: typeId } },
style: { connect: { id: styleId } },
postedBy: { connect: { id: userId } },
brewery: { connect: { id: breweryId } },
},
@@ -36,7 +36,7 @@ const createNewBeerPost = async ({
createdAt: true,
beerImages: { select: { id: true, path: true, caption: true, alt: true } },
brewery: { select: { id: true, name: true } },
type: { select: { id: true, name: true } },
style: { select: { id: true, name: true, description: true } },
postedBy: { select: { id: true, username: true } },
},
});

View File

@@ -16,7 +16,7 @@ const getAllBeerPosts = async (pageNum: number, pageSize: number) => {
abv: true,
description: true,
createdAt: true,
type: { select: { name: true, id: true } },
style: { select: { name: true, id: true, description: true } },
brewery: { select: { name: true, id: true } },
postedBy: { select: { id: true, username: true } },
beerImages: { select: { path: true, caption: true, id: true, alt: true } },

View File

@@ -16,7 +16,7 @@ const getBeerPostById = async (id: string) => {
description: true,
postedBy: { select: { username: true, id: true } },
brewery: { select: { name: true, id: true } },
type: { select: { name: true, id: true } },
style: { select: { name: true, id: true, description: true } },
beerImages: { select: { alt: true, path: true, caption: true, id: true } },
},
where: { id },

View File

@@ -19,7 +19,7 @@ const getBeerRecommendations = async ({
const beerRecommendations: z.infer<typeof BeerPostQueryResult>[] =
await DBClient.instance.beerPost.findMany({
where: {
OR: [{ typeId: beerPost.type.id }, { breweryId: beerPost.brewery.id }],
OR: [{ styleId: beerPost.style.id }, { breweryId: beerPost.brewery.id }],
NOT: { id: beerPost.id },
},
select: {
@@ -29,7 +29,7 @@ const getBeerRecommendations = async ({
abv: true,
description: true,
createdAt: true,
type: { select: { name: true, id: true } },
style: { select: { name: true, id: true, description: true } },
brewery: { select: { name: true, id: true } },
postedBy: { select: { id: true, username: true } },
beerImages: { select: { path: true, caption: true, id: true, alt: true } },
@@ -40,7 +40,7 @@ const getBeerRecommendations = async ({
const count = await DBClient.instance.beerPost.count({
where: {
OR: [{ typeId: beerPost.type.id }, { breweryId: beerPost.brewery.id }],
OR: [{ styleId: beerPost.style.id }, { breweryId: beerPost.brewery.id }],
NOT: { id: beerPost.id },
},
});

View File

@@ -10,7 +10,7 @@ const BeerPostQueryResult = z.object({
),
ibu: z.number(),
abv: z.number(),
type: z.object({ id: z.string(), name: z.string() }),
style: z.object({ id: z.string(), name: z.string(), description: z.string() }),
postedBy: z.object({ id: z.string(), username: z.string() }),
createdAt: z.coerce.date(),
});

View File

@@ -26,10 +26,10 @@ const CreateBeerPostValidationSchema = z.object({
})
.min(2, { message: 'IBU must be greater than 2.' })
.max(100, { message: 'IBU must be less than 100.' }),
typeId: z
styleId: z
.string({
required_error: 'Type id is required.',
invalid_type_error: 'Type id must be a string.',
required_error: 'Style id is required.',
invalid_type_error: 'Style id must be a string.',
})
.cuid({ message: 'Invalid type id.' }),
breweryId: z

View File

@@ -1,12 +1,12 @@
import DBClient from '@/prisma/DBClient';
import { z } from 'zod';
import BeerTypeQueryResult from './schema/BeerTypeQueryResult';
import BeerStyleQueryResult from './schema/BeerStyleQueryResult';
const getAllBeerTypes = async (
const getAllBeerStyles = async (
pageNum: number,
pageSize: number,
): Promise<z.infer<typeof BeerTypeQueryResult>[]> => {
const types = await DBClient.instance.beerType.findMany({
): Promise<z.infer<typeof BeerStyleQueryResult>[]> => {
const styles = await DBClient.instance.beerStyle.findMany({
take: pageSize,
skip: (pageNum - 1) * pageSize,
select: {
@@ -18,7 +18,7 @@ const getAllBeerTypes = async (
},
});
return types;
return styles;
};
export default getAllBeerTypes;
export default getAllBeerStyles;

View File

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