Files
the-biergarten-app/src/services/posts/BeerPost/createNewBeerPost.ts
Aaron William Po fd641c36ab Refactor: begin reorganizing services dir.
- Renamed files and directories to reflect the new structure
- Moved comment-related services to the 'comments' directory
- Moved image-related services to the 'images' directory
- Moved like-related services to the 'likes' directory
- Moved post-related services to the 'posts' directory
- Moved user-related services to the 'users' directory
2023-12-10 14:15:31 -05:00

57 lines
1.3 KiB
TypeScript

import DBClient from '@/prisma/DBClient';
import { z } from 'zod';
import BeerPostQueryResult from './schema/BeerPostQueryResult';
import CreateBeerPostValidationSchema from './schema/CreateBeerPostValidationSchema';
const CreateBeerPostWithUserSchema = CreateBeerPostValidationSchema.extend({
userId: z.string().cuid(),
});
const createNewBeerPost = ({
name,
description,
abv,
ibu,
styleId,
breweryId,
userId,
}: z.infer<typeof CreateBeerPostWithUserSchema>): Promise<
z.infer<typeof BeerPostQueryResult>
> => {
return DBClient.instance.beerPost.create({
data: {
name,
description,
abv,
ibu,
style: { connect: { id: styleId } },
postedBy: { connect: { id: userId } },
brewery: { connect: { id: breweryId } },
},
select: {
id: true,
name: true,
description: true,
abv: true,
ibu: true,
createdAt: true,
updatedAt: true,
beerImages: {
select: {
alt: true,
path: true,
caption: true,
id: true,
createdAt: true,
updatedAt: true,
},
},
brewery: { select: { id: true, name: true } },
style: { select: { id: true, name: true, description: true } },
postedBy: { select: { id: true, username: true } },
},
});
};
export default createNewBeerPost;