upd: api mobile
Deskripsi: - api project upload tambah file - api project delete file - api project tambah data upload file - api project check file NO Issues
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user