Refactor: move service logic out of api routes and into separate files

This commit is contained in:
Aaron William Po
2023-05-14 17:12:14 -04:00
parent 60e76089f3
commit 5c91c6ab08
11 changed files with 118 additions and 54 deletions

View File

@@ -0,0 +1,22 @@
import DBClient from '@/prisma/DBClient';
interface EditBeerCommentByIdArgs {
id: string;
content: string;
rating: number;
}
const editBeerCommentById = async ({ id, content, rating }: EditBeerCommentByIdArgs) => {
const updated = await DBClient.instance.beerComment.update({
where: { id },
data: {
content,
rating,
updatedAt: new Date(),
},
});
return updated;
};
export default editBeerCommentById;

View File

@@ -0,0 +1,11 @@
import DBClient from '@/prisma/DBClient';
const findBeerCommentById = async (id: string) => {
const comment = await DBClient.instance.beerComment.findUnique({
where: { id },
});
return comment;
};
export default findBeerCommentById;