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) {
|
if (cekFile) {
|
||||||
console.log('masuk file')
|
body.delete("data")
|
||||||
// for (var pair of body.entries()) {
|
for (var pair of body.entries()) {
|
||||||
// if (String(pair[0]).substring(0, 4) == "file") {
|
if (String(pair[0]).substring(0, 4) == "file") {
|
||||||
// const file = body.get(pair[0]) as File
|
const file = body.get(pair[0]) as File
|
||||||
// const fExt = file.name.split(".").pop()
|
const fExt = file.name.split(".").pop()
|
||||||
// const fName = file.name.replace("." + fExt, "")
|
const fName = file.name.replace("." + fExt, "")
|
||||||
|
|
||||||
// const upload = await funUploadFile({ file: file, dirId: DIR.project })
|
const upload = await funUploadFile({ file: file, dirId: DIR.project })
|
||||||
// if (upload.success) {
|
if (upload.success) {
|
||||||
// const insertToTable = await prisma.projectFile.create({
|
const insertToTable = await prisma.projectFile.create({
|
||||||
// data: {
|
data: {
|
||||||
// idStorage: upload.data.id,
|
idStorage: upload.data.id,
|
||||||
// idProject: id,
|
idProject: id,
|
||||||
// name: fName,
|
name: fName,
|
||||||
// extension: String(fExt),
|
extension: String(fExt),
|
||||||
|
|
||||||
// },
|
},
|
||||||
// select: {
|
select: {
|
||||||
// id: true
|
id: true
|
||||||
// }
|
}
|
||||||
// })
|
})
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// // create log user
|
// create log user
|
||||||
// const log = await createLogUserMobile({ act: 'CREATE', desc: 'User menambah file kegiatan', table: 'project', data: String(id), user: user.id })
|
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 });
|
return NextResponse.json({ success: true, message: "Berhasil mengupload file kegiatan" }, { status: 200 });
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { title } from 'process';
|
import { DIR, 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";
|
||||||
import _, { ceil } from "lodash";
|
import _, { ceil } from "lodash";
|
||||||
@@ -150,7 +149,6 @@ export async function GET(request: Request) {
|
|||||||
// CREATE PROJECT
|
// CREATE PROJECT
|
||||||
export async function POST(request: Request) {
|
export async function POST(request: Request) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const body = await request.formData()
|
const body = await request.formData()
|
||||||
const dataBody = body.get("data")
|
const dataBody = body.get("data")
|
||||||
const cekFile = body.has("file0")
|
const cekFile = body.has("file0")
|
||||||
@@ -206,6 +204,7 @@ export async function POST(request: Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cekFile) {
|
if (cekFile) {
|
||||||
|
body.delete("data")
|
||||||
for (var pair of body.entries()) {
|
for (var pair of body.entries()) {
|
||||||
if (String(pair[0]).substring(0, 4) == "file") {
|
if (String(pair[0]).substring(0, 4) == "file") {
|
||||||
const file = body.get(pair[0]) as File
|
const file = body.get(pair[0]) as File
|
||||||
@@ -347,7 +346,7 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
// create log user
|
// create log user
|
||||||
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User membuat data kegiatan', table: 'project', data: data.id, user: userMobile.id })
|
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) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user