mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
- 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
57 lines
1.3 KiB
TypeScript
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;
|