upd: api diskusi umum
Deskripsi: - tambah file pada data diskusi umum - detail file pada get one diskusi umum No Issues
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { DIR, funUploadFile, prisma } from "@/module/_global";
|
||||
import { funGetUserById } from "@/module/auth";
|
||||
import { createLogUserMobile } from "@/module/user";
|
||||
import _ from "lodash";
|
||||
@@ -112,13 +112,20 @@ export async function GET(request: Request) {
|
||||
// CREATE DISCUSSION GENERALE
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const { idGroup, user, title, desc, member } = await request.json();
|
||||
|
||||
if (user == "null" || user == undefined || user == "") {
|
||||
const body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
const cekFile = body.has("file0")
|
||||
|
||||
// const { idGroup, user, title, desc, member } = await request.json();
|
||||
const { idGroup, user, title, desc, member } = JSON.parse(dataBody as string)
|
||||
|
||||
const userMobile = await funGetUserById({ id: user })
|
||||
|
||||
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const userMobile = await funGetUserById({ id: user })
|
||||
const userId = user
|
||||
const userRoleLogin = userMobile.idUserRole
|
||||
|
||||
@@ -145,6 +152,29 @@ export async function POST(request: Request) {
|
||||
data: dataMember
|
||||
})
|
||||
|
||||
|
||||
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.discussion })
|
||||
if (upload.success) {
|
||||
await prisma.discussionFile.create({
|
||||
data: {
|
||||
idStorage: upload.data.id,
|
||||
idDiscussion: data.id,
|
||||
name: fName,
|
||||
extension: String(fExt)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const memberNotifMobile = await prisma.discussionMember.findMany({
|
||||
where: {
|
||||
idDiscussion: data.id
|
||||
|
||||
Reference in New Issue
Block a user