Update api routes and begin to extract controllers out of routing logic

This commit is contained in:
Aaron William Po
2023-12-03 11:51:54 -05:00
parent 080eb4c3c3
commit b45ed857d3
16 changed files with 345 additions and 408 deletions

View 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;

View 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;