upd: diskusi divisi
deskripsi: - schema db - api tambah detail dan update diskusi divisi NO Issues'
This commit is contained in:
@@ -70,6 +70,21 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
}))
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan komentar", data: omitMember }, { status: 200 });
|
||||
} else if (cat == "file") {
|
||||
const data = await prisma.divisionDiscussionFile.findMany({
|
||||
where: {
|
||||
idDiscussion: id,
|
||||
isActive: true
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
idStorage: true,
|
||||
name: true,
|
||||
extension: true
|
||||
}
|
||||
})
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan file", data: data }, { status: 200 });
|
||||
} else {
|
||||
const data = await prisma.divisionDisscussion.findUnique({
|
||||
where: {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { funSendWebPush, prisma } from "@/module/_global";
|
||||
import { DivisionDiscussionFile } from './../../../../../node_modules/.prisma/client/index.d';
|
||||
import { DIR, funSendWebPush, funUploadFile, prisma } from "@/module/_global";
|
||||
import { funGetUserById } from "@/module/auth";
|
||||
import { createLogUserMobile } from "@/module/user";
|
||||
import _ from "lodash";
|
||||
@@ -102,7 +103,14 @@ export async function GET(request: Request) {
|
||||
// CREATE DISCUSSION
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const { idDivision, desc, user } = (await request.json());
|
||||
const body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
const cekFile = body.has("file0")
|
||||
|
||||
// const { idDivision, desc, user } = (await request.json());
|
||||
const { idDivision, desc, user } = JSON.parse(String(dataBody));
|
||||
|
||||
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
|
||||
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||
@@ -135,6 +143,29 @@ export async function POST(request: Request) {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (cekFile) {
|
||||
body.delete("data")
|
||||
for (var pair of body.entries()) {
|
||||
if (String(pair[0]).substring(0, 4) == "file") {
|
||||
const file = body.get(pair[0]) as File
|
||||
const fExt = file.name.split(".").pop()
|
||||
const fName = decodeURIComponent(file.name.replace("." + fExt, ""))
|
||||
const upload = await funUploadFile({ file: file, dirId: DIR.discussionDivision })
|
||||
if (upload.success) {
|
||||
await prisma.divisionDiscussionFile.create({
|
||||
data: {
|
||||
idStorage: upload.data.id,
|
||||
idDiscussion: data.id,
|
||||
name: fName,
|
||||
extension: String(fExt)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const memberDivision = await prisma.divisionMember.findMany({
|
||||
where: {
|
||||
idDivision: idDivision
|
||||
|
||||
Reference in New Issue
Block a user