diff --git a/bun.lockb b/bun.lockb index 11ec4c0..7db5e01 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/src/app/api/mobile/division/[id]/detail/route.ts b/src/app/api/mobile/division/[id]/detail/route.ts index a1d6b44..1d74a28 100644 --- a/src/app/api/mobile/division/[id]/detail/route.ts +++ b/src/app/api/mobile/division/[id]/detail/route.ts @@ -152,6 +152,7 @@ export async function GET(request: Request, context: { params: { id: string } }) name: true, extension: true, path: true, + idStorage: true } }, createdAt: true @@ -166,13 +167,14 @@ export async function GET(request: Request, context: { params: { id: string } }) id: v.DivisionDocumentFolderFile.id, name: v.DivisionDocumentFolderFile.name, extension: v.DivisionDocumentFolderFile.extension, + idStorage: v.DivisionDocumentFolderFile.idStorage, path: 'home', share: true })) const dataDokumen = await prisma.divisionDocumentFolderFile.findMany({ skip: 0, - take: 5, + take: 4, where: { idDivision: String(id), isActive: true, @@ -183,7 +185,8 @@ export async function GET(request: Request, context: { params: { id: string } }) name: true, extension: true, path: true, - createdAt: true + createdAt: true, + idStorage: true }, orderBy: { createdAt: "desc" @@ -200,6 +203,7 @@ export async function GET(request: Request, context: { params: { id: string } }) } allData = _.orderBy(fixData, ['createdAt'], ['desc']); + allData.slice(0, 4) } else if (kategori == "new-discussion") { const diskusi = await prisma.divisionDisscussion.findMany({ diff --git a/src/app/api/mobile/document/upload/route.ts b/src/app/api/mobile/document/upload/route.ts index fbb3963..95a0a53 100644 --- a/src/app/api/mobile/document/upload/route.ts +++ b/src/app/api/mobile/document/upload/route.ts @@ -10,8 +10,6 @@ export async function POST(request: Request) { try { const body = await request.formData() const dataBody = body.get("data") - const file = body.get("file") as File - const fileName = file.name const { idPath, idDivision, user } = JSON.parse(dataBody as string) @@ -57,39 +55,48 @@ export async function POST(request: Request) { ..._.omit(v, [""]), file: v.name + '.' + v.extension, })) - - const cek = dataOmit.some((i: any) => i.file == fileName) - - if (cek) { - return NextResponse.json({ success: false, message: "Terdapat file dengan nama yang sama" }, { status: 200 }); - } - - - const fExt = file.name.split(".").pop() - const fName = file.name.replace("." + fExt, "") - const upload = await funUploadFile({ file: file, dirId: DIR.document }) - if (upload.success) { - const dataInsert = await prisma.divisionDocumentFolderFile.create({ - data: { - name: fName, - path: idPath, - idDivision, - category: "FILE", - extension: String(fExt), - createdBy: userMobile.id, - idStorage: upload.data.id - }, - select: { - id: true + let failed = 0 + 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 fileName = file.name + const fExt = file.name.split(".").pop() + let fName = file.name.replace("." + fExt, "") + const cek = dataOmit.some((i: any) => i.file == fileName) + if (cek) { + const random = Math.floor(Math.random() * 1000) + fName = `${fName}_${random}` } - }); + const upload = await funUploadFile({ file: file, dirId: DIR.document }) + if (upload.success) { + const dataInsert = await prisma.divisionDocumentFolderFile.create({ + data: { + name: fName, + path: idPath, + idDivision, + category: "FILE", + extension: String(fExt), + createdBy: userMobile.id, + idStorage: upload.data.id + }, + select: { + id: true + } + }); - // create log user - const log = await createLogUserMobile({ act: 'CREATE', desc: 'User mengupload file baru', table: 'divisionDocumentFolderFile', data: dataInsert.id, user: userMobile.id }) - return NextResponse.json({ success: true, message: "Berhasil upload file" }, { status: 200 }); - } else { - return NextResponse.json({ success: false, message: "Gagal upload file, coba lagi nanti" }, { status: 200 }); + // create log user + const log = await createLogUserMobile({ act: 'CREATE', desc: 'User mengupload file baru', table: 'divisionDocumentFolderFile', data: dataInsert.id, user: userMobile.id }) + } else { + failed++ + } + } } + + if (failed > 0) { + return NextResponse.json({ success: false, message: "Beberapa file gagal diupload", failed }, { status: 200 }); + } + return NextResponse.json({ success: true, message: "Berhasil upload file" }, { status: 200 }); } catch (error) { console.error(error); return NextResponse.json({ success: false, message: "Gagal upload file, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); diff --git a/src/app/api/mobile/project/[id]/route.ts b/src/app/api/mobile/project/[id]/route.ts index 9bbd6d7..e261dae 100644 --- a/src/app/api/mobile/project/[id]/route.ts +++ b/src/app/api/mobile/project/[id]/route.ts @@ -81,8 +81,8 @@ export async function GET(request: Request, context: { params: { id: string } }) dateEnd: moment(v.dateEnd).format("DD-MM-YYYY"), createdAt: moment(v.createdAt).format("DD-MM-YYYY HH:mm"), })) - const dataFix = _.orderBy(formatData, 'createdAt', 'asc') - allData = dataFix + // const dataFix = _.orderBy(formatData, 'createdAt', 'asc') + allData = formatData } else if (kategori == "file") { const dataFile = await prisma.projectFile.findMany({ diff --git a/src/app/api/version-app/route.ts b/src/app/api/version-app/route.ts index eeee64a..a3effd9 100644 --- a/src/app/api/version-app/route.ts +++ b/src/app/api/version-app/route.ts @@ -2,7 +2,7 @@ import { NextResponse } from "next/server"; export async function GET(request: Request) { try { - return NextResponse.json({ success: true, version: "1.5.6", tahap: "beta", update: "-fix mobile api" }, { status: 200 }); + return NextResponse.json({ success: true, version: "1.5.7", tahap: "beta", update: "-fix mobile api" }, { status: 200 }); } catch (error) { console.error(error); return NextResponse.json({ success: false, version: "Gagal mendapatkan version, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 }); diff --git a/src/module/_global/fun/count_time.ts b/src/module/_global/fun/count_time.ts index fe57234..5a26efa 100644 --- a/src/module/_global/fun/count_time.ts +++ b/src/module/_global/fun/count_time.ts @@ -23,8 +23,6 @@ export function countTime(date: Date) { return `${hours} jam` } else if (minutes > 0) { return `${minutes} mnt` - } else if (seconds > 10) { - return `${seconds} dtk` } else { return `baru saja` }