mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 18:52:06 +00:00
Update api routes and begin to extract controllers out of routing logic
This commit is contained in:
23
src/services/BeerStyleComment/updateBeerStyleCommentById.ts
Normal file
23
src/services/BeerStyleComment/updateBeerStyleCommentById.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import DBClient from '@/prisma/DBClient';
|
||||
import { z } from 'zod';
|
||||
import CreateCommentValidationSchema from '../schema/CommentSchema/CreateCommentValidationSchema';
|
||||
|
||||
interface UpdateBeerStyleCommentByIdParams {
|
||||
body: z.infer<typeof CreateCommentValidationSchema>;
|
||||
id: string;
|
||||
}
|
||||
|
||||
const updateBeerStyleCommentById = ({ body, id }: UpdateBeerStyleCommentByIdParams) => {
|
||||
const { content, rating } = body;
|
||||
|
||||
return DBClient.instance.beerStyleComment.update({
|
||||
where: { id },
|
||||
data: {
|
||||
content,
|
||||
rating,
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export default updateBeerStyleCommentById;
|
||||
55
src/services/UserAccount/UpdateUserAvatarByIdParams.ts
Normal file
55
src/services/UserAccount/UpdateUserAvatarByIdParams.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import DBClient from '@/prisma/DBClient';
|
||||
import GetUserSchema from '@/services/User/schema/GetUserSchema';
|
||||
import { z } from 'zod';
|
||||
|
||||
export interface UpdateUserAvatarByIdParams {
|
||||
id: string;
|
||||
data: {
|
||||
avatar: {
|
||||
alt: string;
|
||||
path: string;
|
||||
caption: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
const updateUserAvatarById = async ({ id, data }: UpdateUserAvatarByIdParams) => {
|
||||
const user: z.infer<typeof GetUserSchema> = await DBClient.instance.user.update({
|
||||
where: { id },
|
||||
data: {
|
||||
userAvatar: data.avatar
|
||||
? {
|
||||
upsert: {
|
||||
create: {
|
||||
alt: data.avatar.alt,
|
||||
path: data.avatar.path,
|
||||
caption: data.avatar.caption,
|
||||
},
|
||||
update: {
|
||||
alt: data.avatar.alt,
|
||||
path: data.avatar.path,
|
||||
caption: data.avatar.caption,
|
||||
},
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
email: true,
|
||||
bio: true,
|
||||
userAvatar: true,
|
||||
accountIsVerified: true,
|
||||
createdAt: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
updatedAt: true,
|
||||
dateOfBirth: true,
|
||||
role: true,
|
||||
},
|
||||
});
|
||||
|
||||
return user;
|
||||
};
|
||||
|
||||
export default updateUserAvatarById;
|
||||
Reference in New Issue
Block a user