Update brewery/beer style to use tuples for ranges/coords. Seed updates.

This commit is contained in:
Aaron William Po
2023-09-22 02:17:05 -04:00
parent e95cb29189
commit 43220fe0e6
11 changed files with 37 additions and 17 deletions

View File

@@ -80,8 +80,10 @@ const BeerInfoHeader: FC<BeerInfoHeaderProps> = ({ beerPost }) => {
</Link> </Link>
</div> </div>
<div> <div>
<span className="mr-4 text-lg font-medium">{beerPost.abv}% ABV</span> <span className="mr-4 text-lg font-medium">
<span className="text-lg font-medium">{beerPost.ibu} IBU</span> {beerPost.abv.toFixed(1)}% ABV
</span>
<span className="text-lg font-medium">{beerPost.ibu.toFixed(1)} IBU</span>
</div> </div>
<div> <div>
{(!!likeCount || likeCount === 0) && ( {(!!likeCount || likeCount === 0) && (

View File

@@ -73,8 +73,8 @@ const BeerRecommendationsSection: FC<{
<span className="text-lg font-medium">{post.style.name}</span> <span className="text-lg font-medium">{post.style.name}</span>
</div> </div>
<div className="space-x-2"> <div className="space-x-2">
<span>{post.abv}% ABV</span> <span>{post.abv.toFixed(1)}% ABV</span>
<span>{post.ibu} IBU</span> <span>{post.ibu.toFixed(1)} IBU</span>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -41,8 +41,8 @@ const BeerCard: FC<{ post: z.infer<typeof BeerPostQueryResult> }> = ({ post }) =
<div> <div>
<p className="text-md lg:text-xl">{post.style.name}</p> <p className="text-md lg:text-xl">{post.style.name}</p>
<div className="space-x-3"> <div className="space-x-3">
<span className="text-sm lg:text-lg">{post.abv}% ABV</span> <span className="text-sm lg:text-lg">{post.abv.toFixed(1)}% ABV</span>
<span className="text-sm lg:text-lg">{post.ibu} IBU</span> <span className="text-sm lg:text-lg">{post.ibu.toFixed(1)} IBU</span>
</div> </div>
{!isLoading && ( {!isLoading && (
<span> <span>

View File

@@ -15,6 +15,16 @@ const BeerStyleCard: FC<{ beerStyle: z.infer<typeof BeerStyleQueryResult> }> = (
<h3 className="link-hover link overflow-hidden whitespace-normal text-2xl font-bold lg:truncate lg:text-3xl"> <h3 className="link-hover link overflow-hidden whitespace-normal text-2xl font-bold lg:truncate lg:text-3xl">
{beerStyle.name} {beerStyle.name}
</h3> </h3>
<div className="text-base-content text-sm">
ABV Range: <span>{beerStyle.abvRange[0].toFixed(1)}%</span>
<span> - </span>
<span>{beerStyle.abvRange[1].toFixed(1)}%</span>
</div>
<div className="text-base-content text-sm">
IBU Range: <span>{beerStyle.ibuRange[0].toFixed(1)}</span>
<span> - </span>
<span>{beerStyle.ibuRange[1].toFixed(1)}</span>
</div>
</Link> </Link>
</div> </div>
</div> </div>

View File

@@ -38,8 +38,12 @@ const createNewBeerPosts = async ({
const breweryPost = breweryPosts[Math.floor(Math.random() * breweryPosts.length)]; const breweryPost = breweryPosts[Math.floor(Math.random() * breweryPosts.length)];
const createdAt = faker.date.past({ years: 1 }); const createdAt = faker.date.past({ years: 1 });
const abv = Math.floor(Math.random() * (12 - 4) + 4); const [minABV, maxABV] = beerStyle.abvRange;
const ibu = Math.floor(Math.random() * (60 - 10) + 10); const [minIBU, maxIBU] = beerStyle.ibuRange;
const abv = parseFloat((Math.random() * (maxABV - minABV) + minABV).toFixed(1));
const ibu = Math.floor(Math.random() * (maxIBU - minIBU) + minIBU);
const name = faker.commerce.productName(); const name = faker.commerce.productName();
const description = faker.lorem.lines(20).replace(/(\r\n|\n|\r)/gm, ' '); const description = faker.lorem.lines(20).replace(/(\r\n|\n|\r)/gm, ' ');

View File

@@ -6,7 +6,7 @@ const getAllBeerStyles = async (
pageNum: number, pageNum: number,
pageSize: number, pageSize: number,
): Promise<z.infer<typeof BeerStyleQueryResult>[]> => { ): Promise<z.infer<typeof BeerStyleQueryResult>[]> => {
const styles = await DBClient.instance.beerStyle.findMany({ const styles = (await DBClient.instance.beerStyle.findMany({
take: pageSize, take: pageSize,
skip: (pageNum - 1) * pageSize, skip: (pageNum - 1) * pageSize,
select: { select: {
@@ -15,8 +15,10 @@ const getAllBeerStyles = async (
postedBy: { select: { id: true, username: true } }, postedBy: { select: { id: true, username: true } },
createdAt: true, createdAt: true,
updatedAt: true, updatedAt: true,
abvRange: true,
ibuRange: true,
}, },
}); })) as z.infer<typeof BeerStyleQueryResult>[];
return styles; return styles;
}; };

View File

@@ -9,6 +9,8 @@ const BeerStyleQueryResult = z.object({
}), }),
createdAt: z.coerce.date(), createdAt: z.coerce.date(),
updatedAt: z.coerce.date().nullable(), updatedAt: z.coerce.date().nullable(),
abvRange: z.tuple([z.number(), z.number()]),
ibuRange: z.tuple([z.number(), z.number()]),
}); });
export default BeerStyleQueryResult; export default BeerStyleQueryResult;

View File

@@ -21,7 +21,7 @@ const createNewBreweryPost = async ({
userId, userId,
}: z.infer<typeof CreateNewBreweryPostWithUserAndLocationSchema>) => { }: z.infer<typeof CreateNewBreweryPostWithUserAndLocationSchema>) => {
const breweryPost: z.infer<typeof BreweryPostQueryResult> = const breweryPost: z.infer<typeof BreweryPostQueryResult> =
await DBClient.instance.breweryPost.create({ (await DBClient.instance.breweryPost.create({
data: { data: {
name, name,
description, description,
@@ -47,7 +47,7 @@ const createNewBreweryPost = async ({
}, },
}, },
}, },
}); })) as z.infer<typeof BreweryPostQueryResult>;
return breweryPost; return breweryPost;
}; };

View File

@@ -10,7 +10,7 @@ const getAllBreweryPosts = async (pageNum?: number, pageSize?: number) => {
const take = pageNum && pageSize ? pageSize : undefined; const take = pageNum && pageSize ? pageSize : undefined;
const breweryPosts: z.infer<typeof BreweryPostQueryResult>[] = const breweryPosts: z.infer<typeof BreweryPostQueryResult>[] =
await prisma.breweryPost.findMany({ (await prisma.breweryPost.findMany({
skip, skip,
take, take,
select: { select: {
@@ -32,7 +32,7 @@ const getAllBreweryPosts = async (pageNum?: number, pageSize?: number) => {
dateEstablished: true, dateEstablished: true,
}, },
orderBy: { createdAt: 'desc' }, orderBy: { createdAt: 'desc' },
}); })) as z.infer<typeof BreweryPostQueryResult>[];
return breweryPosts; return breweryPosts;
}; };

View File

@@ -6,7 +6,7 @@ const prisma = DBClient.instance;
const getBreweryPostById = async (id: string) => { const getBreweryPostById = async (id: string) => {
const breweryPost: z.infer<typeof BreweryPostQueryResult> | null = const breweryPost: z.infer<typeof BreweryPostQueryResult> | null =
await prisma.breweryPost.findFirst({ (await prisma.breweryPost.findFirst({
select: { select: {
id: true, id: true,
location: { location: {
@@ -26,7 +26,7 @@ const getBreweryPostById = async (id: string) => {
dateEstablished: true, dateEstablished: true,
}, },
where: { id }, where: { id },
}); })) as z.infer<typeof BreweryPostQueryResult> | null;
return breweryPost; return breweryPost;
}; };

View File

@@ -7,7 +7,7 @@ const BreweryPostQueryResult = z.object({
location: z.object({ location: z.object({
city: z.string(), city: z.string(),
address: z.string(), address: z.string(),
coordinates: z.array(z.number()), coordinates: z.tuple([z.number(), z.number()]),
country: z.string().nullable(), country: z.string().nullable(),
stateOrProvince: z.string().nullable(), stateOrProvince: z.string().nullable(),
}), }),