Files
DAV/server/api/comments/[id].put.ts
Do-raa e24b3e1955
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
add interactions to comments
2024-12-23 15:44:36 +01:00

38 lines
804 B
TypeScript

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,
};
}
});