mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-04-06 02:19:05 +00:00
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
This commit is contained in:
56
src/services/posts/BeerPost/createNewBeerPost.ts
Normal file
56
src/services/posts/BeerPost/createNewBeerPost.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user