mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
Refactor: move service logic out of api routes and into separate files
This commit is contained in:
22
src/services/BeerComment/editBeerCommentById.ts
Normal file
22
src/services/BeerComment/editBeerCommentById.ts
Normal 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;
|
||||
11
src/services/BeerComment/findBeerCommentById.ts
Normal file
11
src/services/BeerComment/findBeerCommentById.ts
Normal 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;
|
||||
Reference in New Issue
Block a user