mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
Feat: add glassware, abv range, and ibu range to beer style table
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { UserExtendedNextApiRequest } from '@/config/auth/types';
|
||||
import getCurrentUser from '@/config/nextConnect/middleware/getCurrentUser';
|
||||
import validateRequest from '@/config/nextConnect/middleware/validateRequest';
|
||||
import ServerError from '@/config/util/ServerError';
|
||||
import DBClient from '@/prisma/DBClient';
|
||||
|
||||
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
|
||||
@@ -15,6 +16,11 @@ const BeerStyleValidationSchema = z.object({
|
||||
id: z.string().cuid(),
|
||||
username: z.string(),
|
||||
}),
|
||||
glassware: z.object({
|
||||
id: z.string().cuid(),
|
||||
name: z.string(),
|
||||
description: z.string(),
|
||||
}),
|
||||
description: z.string(),
|
||||
createdAt: z.date(),
|
||||
updatedAt: z.date().nullable(),
|
||||
@@ -25,6 +31,9 @@ const CreateBeerStyleValidationSchema = BeerStyleValidationSchema.omit({
|
||||
postedBy: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
glassware: true,
|
||||
}).extend({
|
||||
glasswareId: z.string().cuid(),
|
||||
});
|
||||
|
||||
interface CreateBeerStyleRequest extends UserExtendedNextApiRequest {
|
||||
@@ -43,13 +52,22 @@ const createBeerStyle = async (
|
||||
res: NextApiResponse<z.infer<typeof APIResponseValidationSchema>>,
|
||||
) => {
|
||||
const user = req.user!;
|
||||
const { name, description } = req.body;
|
||||
const { name, description, glasswareId } = req.body;
|
||||
|
||||
const glassware = await DBClient.instance.glassware.findUnique({
|
||||
where: { id: glasswareId },
|
||||
});
|
||||
|
||||
if (!glassware) {
|
||||
throw new ServerError('Glassware not found', 404);
|
||||
}
|
||||
|
||||
const newBeerStyle = await DBClient.instance.beerStyle.create({
|
||||
data: {
|
||||
description,
|
||||
name,
|
||||
postedBy: { connect: { id: user.id } },
|
||||
glassware: { connect: { id: glassware.id } },
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
|
||||
Reference in New Issue
Block a user