generated from nhcarrigan/template
feat: ability to edit and delete comments
This commit is contained in:
@@ -54,6 +54,7 @@ export class CommentService {
|
||||
return {
|
||||
id: comment.id,
|
||||
content: comment.content,
|
||||
rawContent: comment.rawContent || undefined,
|
||||
userId: comment.userId,
|
||||
user: {
|
||||
id: comment.user.id,
|
||||
@@ -107,6 +108,7 @@ export class CommentService {
|
||||
const comment = await this.prisma.comment.create({
|
||||
data: {
|
||||
content: sanitizedContent,
|
||||
rawContent: data.content,
|
||||
userId,
|
||||
gameId,
|
||||
},
|
||||
@@ -124,6 +126,7 @@ export class CommentService {
|
||||
const comment = await this.prisma.comment.create({
|
||||
data: {
|
||||
content: sanitizedContent,
|
||||
rawContent: data.content,
|
||||
userId,
|
||||
bookId,
|
||||
},
|
||||
@@ -141,6 +144,7 @@ export class CommentService {
|
||||
const comment = await this.prisma.comment.create({
|
||||
data: {
|
||||
content: sanitizedContent,
|
||||
rawContent: data.content,
|
||||
userId,
|
||||
musicId,
|
||||
},
|
||||
@@ -167,6 +171,7 @@ export class CommentService {
|
||||
const comment = await this.prisma.comment.create({
|
||||
data: {
|
||||
content: sanitizedContent,
|
||||
rawContent: data.content,
|
||||
userId,
|
||||
artId,
|
||||
},
|
||||
@@ -193,6 +198,7 @@ export class CommentService {
|
||||
const comment = await this.prisma.comment.create({
|
||||
data: {
|
||||
content: sanitizedContent,
|
||||
rawContent: data.content,
|
||||
userId,
|
||||
showId,
|
||||
},
|
||||
@@ -219,6 +225,7 @@ export class CommentService {
|
||||
const comment = await this.prisma.comment.create({
|
||||
data: {
|
||||
content: sanitizedContent,
|
||||
rawContent: data.content,
|
||||
userId,
|
||||
mangaId,
|
||||
},
|
||||
@@ -227,9 +234,57 @@ export class CommentService {
|
||||
return this.mapComment(comment);
|
||||
}
|
||||
|
||||
async getCommentById(commentId: string) {
|
||||
return this.prisma.comment.findUnique({
|
||||
where: { id: commentId },
|
||||
include: { user: true },
|
||||
});
|
||||
}
|
||||
|
||||
async updateComment(
|
||||
commentId: string,
|
||||
content: string
|
||||
): Promise<Comment> {
|
||||
const sanitizedContent = this.sanitizeMarkdown(content);
|
||||
const comment = await this.prisma.comment.update({
|
||||
where: { id: commentId },
|
||||
data: {
|
||||
content: sanitizedContent,
|
||||
rawContent: content,
|
||||
},
|
||||
include: { user: true },
|
||||
});
|
||||
return this.mapComment(comment);
|
||||
}
|
||||
|
||||
async deleteComment(commentId: string): Promise<void> {
|
||||
await this.prisma.comment.delete({
|
||||
where: { id: commentId },
|
||||
});
|
||||
}
|
||||
|
||||
async verifyCommentOwnership(
|
||||
commentId: string,
|
||||
resourceType: "game" | "book" | "music" | "art" | "show" | "manga",
|
||||
resourceId: string
|
||||
): Promise<{ exists: boolean; comment?: { userId: string } }> {
|
||||
const fieldMap = {
|
||||
game: "gameId",
|
||||
book: "bookId",
|
||||
music: "musicId",
|
||||
art: "artId",
|
||||
show: "showId",
|
||||
manga: "mangaId",
|
||||
};
|
||||
|
||||
const comment = await this.prisma.comment.findFirst({
|
||||
where: {
|
||||
id: commentId,
|
||||
[fieldMap[resourceType]]: resourceId,
|
||||
},
|
||||
select: { userId: true },
|
||||
});
|
||||
|
||||
return comment ? { exists: true, comment } : { exists: false };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user