diff --git a/src/app/api/mobile/project/file/[id]/route.ts b/src/app/api/mobile/project/file/[id]/route.ts index 106d916..40d7648 100644 --- a/src/app/api/mobile/project/file/[id]/route.ts +++ b/src/app/api/mobile/project/file/[id]/route.ts @@ -159,34 +159,34 @@ export async function POST(request: Request, context: { params: { id: string } } } if (cekFile) { - console.log('masuk file') - // 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 = file.name.replace("." + fExt, "") + 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 = file.name.replace("." + fExt, "") - // const upload = await funUploadFile({ file: file, dirId: DIR.project }) - // if (upload.success) { - // const insertToTable = await prisma.projectFile.create({ - // data: { - // idStorage: upload.data.id, - // idProject: id, - // name: fName, - // extension: String(fExt), + const upload = await funUploadFile({ file: file, dirId: DIR.project }) + if (upload.success) { + const insertToTable = await prisma.projectFile.create({ + data: { + idStorage: upload.data.id, + idProject: id, + name: fName, + extension: String(fExt), - // }, - // select: { - // id: true - // } - // }) - // } - // } - // } + }, + select: { + id: true + } + }) + } + } + } } - // // create log user - // const log = await createLogUserMobile({ act: 'CREATE', desc: 'User menambah file kegiatan', table: 'project', data: String(id), user: user.id }) + // create log user + const log = await createLogUserMobile({ act: 'CREATE', desc: 'User menambah file kegiatan', table: 'project', data: String(id), user: user.id }) return NextResponse.json({ success: true, message: "Berhasil mengupload file kegiatan" }, { status: 200 }); } catch (error) { diff --git a/src/app/api/mobile/project/route.ts b/src/app/api/mobile/project/route.ts index 1eddfb8..afdee06 100644 --- a/src/app/api/mobile/project/route.ts +++ b/src/app/api/mobile/project/route.ts @@ -1,5 +1,4 @@ -import { title } from 'process'; -import { DIR, funSendWebPush, funUploadFile, prisma } from "@/module/_global"; +import { DIR, funUploadFile, prisma } from "@/module/_global"; import { funGetUserById } from "@/module/auth"; import { createLogUserMobile } from "@/module/user"; import _, { ceil } from "lodash"; @@ -150,7 +149,6 @@ export async function GET(request: Request) { // CREATE PROJECT export async function POST(request: Request) { try { - const body = await request.formData() const dataBody = body.get("data") const cekFile = body.has("file0") @@ -206,6 +204,7 @@ 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 @@ -347,7 +346,7 @@ export async function POST(request: Request) { // create log user const log = await createLogUserMobile({ act: 'CREATE', desc: 'User membuat data kegiatan', table: 'project', data: data.id, user: userMobile.id }) - return NextResponse.json({ success: true, message: "Berhasil membuat kegiatan"}, { status: 200 }); + return NextResponse.json({ success: true, message: "Berhasil membuat kegiatan" }, { status: 200 }); } catch (error) { console.error(error);