add interactions to comments
This commit is contained in:
37
server/api/comments/[id].put.ts
Normal file
37
server/api/comments/[id].put.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import prisma from '~/lib/prisma';
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const id = event.context.params?.id;
|
||||
const body = await readBody(event);
|
||||
|
||||
if (!id) {
|
||||
return {
|
||||
success: false,
|
||||
message: 'Invalid comment ID.',
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const updatedComment = await prisma.comment.update({
|
||||
where: { id },
|
||||
data: {
|
||||
content: body.content,
|
||||
likes: body.likes,
|
||||
dislikes: body.dislikes,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: 'Comment updated successfully',
|
||||
data: updatedComment,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error updating comment:', error);
|
||||
return {
|
||||
success: false,
|
||||
message: 'An error occurred while updating the comment',
|
||||
error: error.message,
|
||||
};
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user