feat: tambah model DiscussionCommentFile dan endpoint attachment komentar
- Tambah model DiscussionCommentFile dengan relasi ke DiscussionComment - Jalankan migrasi 20260609083038_add_discussion_comment_file - POST komentar mendukung multipart/form-data untuk upload file (backward compatible) - GET cat=komentar menyertakan data DiscussionCommentFile dalam response
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "DiscussionCommentFile" (
|
||||
"id" TEXT NOT NULL,
|
||||
"idComment" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"extension" TEXT NOT NULL,
|
||||
"idStorage" TEXT,
|
||||
"isActive" BOOLEAN NOT NULL DEFAULT true,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "DiscussionCommentFile_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "DiscussionCommentFile" ADD CONSTRAINT "DiscussionCommentFile_idComment_fkey" FOREIGN KEY ("idComment") REFERENCES "DiscussionComment"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
@@ -669,16 +669,29 @@ model DiscussionMember {
|
||||
}
|
||||
|
||||
model DiscussionComment {
|
||||
id String @id @default(cuid())
|
||||
Discussion Discussion @relation(fields: [idDiscussion], references: [id])
|
||||
idDiscussion String
|
||||
User User @relation(fields: [idUser], references: [id])
|
||||
idUser String
|
||||
comment String @db.Text
|
||||
isActive Boolean @default(true)
|
||||
isEdited Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
id String @id @default(cuid())
|
||||
Discussion Discussion @relation(fields: [idDiscussion], references: [id])
|
||||
idDiscussion String
|
||||
User User @relation(fields: [idUser], references: [id])
|
||||
idUser String
|
||||
comment String @db.Text
|
||||
isActive Boolean @default(true)
|
||||
isEdited Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
DiscussionCommentFile DiscussionCommentFile[]
|
||||
}
|
||||
|
||||
model DiscussionCommentFile {
|
||||
id String @id @default(cuid())
|
||||
Comment DiscussionComment @relation(fields: [idComment], references: [id])
|
||||
idComment String
|
||||
name String
|
||||
extension String
|
||||
idStorage String?
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model DiscussionFile {
|
||||
|
||||
@@ -76,6 +76,15 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
name: true,
|
||||
img: true
|
||||
}
|
||||
},
|
||||
DiscussionCommentFile: {
|
||||
where: { isActive: true },
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
extension: true,
|
||||
idStorage: true
|
||||
}
|
||||
}
|
||||
},
|
||||
orderBy: {
|
||||
@@ -84,11 +93,12 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
})
|
||||
|
||||
dataFix = data.map((v: any) => ({
|
||||
..._.omit(v, ["createdAt", "User", "updatedAt"]),
|
||||
..._.omit(v, ["createdAt", "User", "updatedAt", "DiscussionCommentFile"]),
|
||||
createdAt: countTime(v.createdAt),
|
||||
updatedAt: moment(v.updatedAt).format("ll"),
|
||||
username: v.User.name,
|
||||
img: v.User.img
|
||||
img: v.User.img,
|
||||
files: v.DiscussionCommentFile
|
||||
}))
|
||||
|
||||
} else if (kategori == "anggota") {
|
||||
|
||||
Reference in New Issue
Block a user