upd: document
Deskripsi: - pindah item No Issues
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
|
||||
// MOVE ITEM
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
@@ -9,6 +11,35 @@ export async function POST(request: Request) {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { path, dataItem } = (await request.json());
|
||||
|
||||
|
||||
if (path != "home") {
|
||||
const cekPath = await prisma.divisionDocumentFolderFile.count({
|
||||
where: {
|
||||
isActive: true,
|
||||
id: path
|
||||
}
|
||||
})
|
||||
|
||||
if (cekPath == 0) {
|
||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan path, data tidak ditemukan" }, { status: 404 });
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < dataItem.length; i++) {
|
||||
const id = dataItem[i].id;
|
||||
const cekFile = await prisma.divisionDocumentFolderFile.update({
|
||||
where: {
|
||||
id: id
|
||||
},
|
||||
data: {
|
||||
path: path
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil memindahkan item" }, { status: 200 });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
@@ -17,6 +17,7 @@ export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const idDivision = searchParams.get("division");
|
||||
const path = searchParams.get("path");
|
||||
const category = searchParams.get("category");
|
||||
|
||||
const cekDivision = await prisma.division.count({
|
||||
where: {
|
||||
@@ -43,14 +44,26 @@ export async function GET(request: Request) {
|
||||
}
|
||||
|
||||
|
||||
let kondisi: any = {
|
||||
isActive: true,
|
||||
idDivision: String(idDivision),
|
||||
path: (path == "undefined" || path == "null" || path == "" || path == null) ? "home" : path
|
||||
}
|
||||
|
||||
if (category == "folder") {
|
||||
kondisi = {
|
||||
isActive: true,
|
||||
idDivision: String(idDivision),
|
||||
path: (path == "undefined" || path == "null" || path == "" || path == null) ? "home" : path,
|
||||
category: "FOLDER"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const data = await prisma.divisionDocumentFolderFile.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
idDivision: String(idDivision),
|
||||
path: (path == "undefined" || path == "null" || path == "" || path == null) ? "home" : path
|
||||
},
|
||||
where: kondisi,
|
||||
select: {
|
||||
id: true,
|
||||
category: true,
|
||||
|
||||
Reference in New Issue
Block a user