diff --git a/src/app/api/project/file/[id]/route.ts b/src/app/api/project/file/[id]/route.ts index 4eba164..7726c46 100644 --- a/src/app/api/project/file/[id]/route.ts +++ b/src/app/api/project/file/[id]/route.ts @@ -162,10 +162,9 @@ export async function POST(request: Request, context: { params: { id: string } } if (cekFile) { - let a = 0 const root = path.join(process.cwd(), "./public/file/project/"); for (var pair of body.entries()) { - if (String(pair[0]) == "file" + a) { + 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, "") @@ -189,7 +188,6 @@ export async function POST(request: Request, context: { params: { id: string } } // Tulis file ke sistem fs.writeFileSync(filePath, buffer); } - a++ } } diff --git a/src/app/api/project/route.ts b/src/app/api/project/route.ts index 6eb8346..8e52e54 100644 --- a/src/app/api/project/route.ts +++ b/src/app/api/project/route.ts @@ -128,10 +128,9 @@ export async function POST(request: Request) { } if (cekFile) { - let a = 0 const root = path.join(process.cwd(), "./public/file/project/"); for (var pair of body.entries()) { - if (String(pair[0]) == "file" + a) { + 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, "") @@ -155,12 +154,11 @@ export async function POST(request: Request) { // Tulis file ke sistem fs.writeFileSync(filePath, buffer); } - a++ } } - return NextResponse.json({ success: true, message: "Berhasil membuat kegiatan", data: data, }, { status: 200 }); + return NextResponse.json({ success: true, message: "Berhasil membuat kegiatan" }, { status: 200 }); } catch (error) { console.error(error); diff --git a/src/app/api/task/file/[id]/route.ts b/src/app/api/task/file/[id]/route.ts index 0998ba0..bc79ab9 100644 --- a/src/app/api/task/file/[id]/route.ts +++ b/src/app/api/task/file/[id]/route.ts @@ -111,10 +111,9 @@ export async function POST(request: Request, context: { params: { id: string } } let fileFix: any[] = [] if (cekFile) { - let a = 0 const root = path.join(process.cwd(), "./public/file/task/"); for (var pair of body.entries()) { - if (String(pair[0]) == "file" + a) { + 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, "") @@ -149,7 +148,6 @@ export async function POST(request: Request, context: { params: { id: string } } fileFix.push(dataFile) } - a++ } const insertFile = await prisma.divisionProjectFile.createMany({ diff --git a/src/app/api/task/route.ts b/src/app/api/task/route.ts index 2e27cc6..aeeabfa 100644 --- a/src/app/api/task/route.ts +++ b/src/app/api/task/route.ts @@ -152,10 +152,9 @@ export async function POST(request: Request) { let fileFix: any[] = [] if (cekFile) { - let a = 0 const root = path.join(process.cwd(), "./public/file/task/"); for (var pair of body.entries()) { - if (String(pair[0]) == "file" + a) { + 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, "") @@ -190,7 +189,6 @@ export async function POST(request: Request) { fileFix.push(dataFile) } - a++ } const insertFile = await prisma.divisionProjectFile.createMany({