BeerPostQueryResult type now inferred from zod schema

This commit is contained in:
Aaron William Po
2023-02-20 14:26:58 -05:00
parent 4cd2ab476f
commit c818dc6525
16 changed files with 75 additions and 58 deletions

View File

@@ -1,8 +1,9 @@
import DBClient from '@/prisma/DBClient';
import { z } from 'zod';
import BeerPostValidationSchema from './schema/CreateBeerPostValidationSchema';
import { BeerPostQueryResult } from './schema/BeerPostQueryResult';
import CreateBeerPostValidationSchema from './schema/CreateBeerPostValidationSchema';
const CreateBeerPostWithUserSchema = BeerPostValidationSchema.extend({
const CreateBeerPostWithUserSchema = CreateBeerPostValidationSchema.extend({
userId: z.string().uuid(),
});
@@ -15,7 +16,7 @@ const createNewBeerPost = async ({
breweryId,
userId,
}: z.infer<typeof CreateBeerPostWithUserSchema>) => {
const newBeerPost = await DBClient.instance.beerPost.create({
const newBeerPost: BeerPostQueryResult = await DBClient.instance.beerPost.create({
data: {
name,
description,
@@ -25,6 +26,18 @@ const createNewBeerPost = async ({
postedBy: { connect: { id: userId } },
brewery: { connect: { id: breweryId } },
},
select: {
id: true,
name: true,
description: true,
abv: true,
ibu: true,
createdAt: true,
beerImages: { select: { id: true, path: true, caption: true, alt: true } },
brewery: { select: { id: true, name: true } },
type: { select: { id: true, name: true } },
postedBy: { select: { id: true, username: true } },
},
});
return newBeerPost;
};