Merge pull request 'upd: api diskusi divisi' (#5) from amalia/19-jan-26 into join
Reviewed-on: http://wibugit.wibudev.com/wibu/sistem-desa-mandiri/pulls/5
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { countTime, prisma } from "@/module/_global";
|
import { countTime, DIR, funUploadFile, prisma } from "@/module/_global";
|
||||||
import { funGetUserById } from "@/module/auth";
|
import { funGetUserById } from "@/module/auth";
|
||||||
import { createLogUserMobile } from "@/module/user";
|
import { createLogUserMobile } from "@/module/user";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
@@ -227,7 +227,13 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
|||||||
export async function POST(request: Request, context: { params: { id: string } }) {
|
export async function POST(request: Request, context: { params: { id: string } }) {
|
||||||
try {
|
try {
|
||||||
const { id } = context.params
|
const { id } = context.params
|
||||||
const { title, desc, user } = (await request.json())
|
const body = await request.formData()
|
||||||
|
const dataBody = body.get("data")
|
||||||
|
const cekFile = body.has("file0")
|
||||||
|
|
||||||
|
// const { title, desc, user } = (await request.json())
|
||||||
|
const { title, desc, user, oldFile } = JSON.parse(dataBody as string)
|
||||||
|
|
||||||
|
|
||||||
const userMobile = await funGetUserById({ id: String(user) })
|
const userMobile = await funGetUserById({ id: String(user) })
|
||||||
|
|
||||||
@@ -254,6 +260,41 @@ export async function POST(request: Request, context: { params: { id: string } }
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (oldFile.length > 0) {
|
||||||
|
for (let index = 0; index < oldFile.length; index++) {
|
||||||
|
const element = oldFile[index];
|
||||||
|
if (element.delete) {
|
||||||
|
await prisma.divisionDiscussionFile.delete({
|
||||||
|
where: {
|
||||||
|
id: element.id
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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: id,
|
||||||
|
name: fName,
|
||||||
|
extension: String(fExt)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// create log user
|
// create log user
|
||||||
const log = await createLogUserMobile({ act: 'UPDATE', desc: 'User mengupdate data diskusi', table: 'divisionDisscussion', data: id, user: userMobile.id })
|
const log = await createLogUserMobile({ act: 'UPDATE', desc: 'User mengupdate data diskusi', table: 'divisionDisscussion', data: id, user: userMobile.id })
|
||||||
return NextResponse.json({ success: true, message: "Berhasil mengedit diskusi" }, { status: 200 });
|
return NextResponse.json({ success: true, message: "Berhasil mengedit diskusi" }, { status: 200 });
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { DivisionDiscussionFile } from './../../../../../node_modules/.prisma/client/index.d';
|
|
||||||
import { DIR, funSendWebPush, funUploadFile, prisma } from "@/module/_global";
|
import { DIR, funSendWebPush, funUploadFile, prisma } from "@/module/_global";
|
||||||
import { funGetUserById } from "@/module/auth";
|
import { funGetUserById } from "@/module/auth";
|
||||||
import { createLogUserMobile } from "@/module/user";
|
import { createLogUserMobile } from "@/module/user";
|
||||||
|
|||||||
Reference in New Issue
Block a user