upd: api ai document divisi

Deskripsi:
- list dokumen dan file divisi

NO Issues
This commit is contained in:
2025-09-19 10:56:02 +08:00
parent e49fb11c94
commit 18589b7de7

View File

@@ -1,6 +1,4 @@
import { prisma } from "@/module/_global"; import { prisma } from "@/module/_global";
import { funGetUserByCookies } from "@/module/auth";
import { createLogUser } from "@/module/user";
import _ from "lodash"; import _ from "lodash";
import moment from "moment"; import moment from "moment";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
@@ -13,88 +11,95 @@ export async function GET(request: Request) {
const idDivision = searchParams.get("division"); const idDivision = searchParams.get("division");
const villageId = searchParams.get("desa"); const villageId = searchParams.get("desa");
const path = searchParams.get("path"); const path = searchParams.get("path");
const category = searchParams.get("category");
const active = searchParams.get("active"); const active = searchParams.get("active");
const search = searchParams.get("search"); const search = searchParams.get("search");
const page = searchParams.get("page"); const page = searchParams.get("page");
const get = searchParams.get("get"); const get = searchParams.get("get");
let getFix = 10;
if (get == null || get == undefined || get == "" || _.isNaN(Number(get))) {
getFix = 10;
} else {
getFix = Number(get);
}
const dataSkip = page == null || page == undefined ? 0 : Number(page) * getFix - getFix;
let kondisi: any = { let kondisi: any = {
isActive: true, Division: {
idDivision: String(idDivision), idVillage: String(villageId)
path: (path == "undefined" || path == "null" || path == "" || path == null) ? "home" : path },
isActive: active == 'false' ? false : true,
path: (path == "undefined" || path == "null" || path == "" || path == null || path == undefined) ? "home" : path,
name: {
contains: (search == undefined || search == "null") ? "" : search,
mode: "insensitive"
}
}
if (idDivision != "null" && idDivision != undefined && idDivision != "") {
kondisi = {
...kondisi,
idDivision: String(idDivision)
}
} }
let formatDataShare: any[] = []; let formatDataShare: any[] = [];
if (category == "folder") { if (path == "home" || path == "null" || path == "undefined" || path == null || path == undefined || path == "") {
kondisi = { const dataShare = await prisma.divisionDocumentShare.findMany({
isActive: true, where: {
idDivision: String(idDivision), isActive: true,
path: (path == "undefined" || path == "null" || path == "" || path == null) ? "home" : path, idDivision: String(idDivision),
category: "FOLDER" DivisionDocumentFolderFile: {
} isActive: true
} else { }
if (path == "home" || path == "null" || path == "undefined") { },
const dataShare = await prisma.divisionDocumentShare.findMany({ select: {
where: { DivisionDocumentFolderFile: {
isActive: true, select: {
idDivision: String(idDivision), idStorage: true,
DivisionDocumentFolderFile: { id: true,
isActive: true category: true,
} name: true,
}, extension: true,
select: { path: true,
DivisionDocumentFolderFile: { User: {
select: { select: {
idStorage: true, name: true
id: true, }
category: true, },
name: true, createdAt: true,
extension: true, updatedAt: true
path: true,
User: {
select: {
name: true
}
},
createdAt: true,
updatedAt: true
}
}
},
orderBy: {
DivisionDocumentFolderFile: {
createdAt: 'desc'
} }
} }
}) },
orderBy: {
formatDataShare = dataShare.map((v: any) => ({ DivisionDocumentFolderFile: {
..._.omit(v, ["DivisionDocumentFolderFile"]), createdAt: 'desc'
idStorage: v.DivisionDocumentFolderFile.idStorage, }
id: v.DivisionDocumentFolderFile.id,
category: v.DivisionDocumentFolderFile.category,
name: v.DivisionDocumentFolderFile.name,
extension: v.DivisionDocumentFolderFile.extension,
path: v.DivisionDocumentFolderFile.path,
createdBy: v.DivisionDocumentFolderFile.User.name,
createdAt: v.DivisionDocumentFolderFile.createdAt,
updatedAt: v.DivisionDocumentFolderFile.updatedAt,
share: true
}))
} else {
kondisi = {
isActive: true,
path: (path == "undefined" || path == "null" || path == null) ? "home" : path
} }
} })
formatDataShare = dataShare.map((v: any) => ({
..._.omit(v, ["DivisionDocumentFolderFile"]),
idStorage: v.DivisionDocumentFolderFile.idStorage,
id: v.DivisionDocumentFolderFile.id,
category: v.DivisionDocumentFolderFile.category,
name: v.DivisionDocumentFolderFile.name,
extension: v.DivisionDocumentFolderFile.extension,
path: v.DivisionDocumentFolderFile.path,
createdBy: v.DivisionDocumentFolderFile.User.name,
createdAt: v.DivisionDocumentFolderFile.createdAt,
updatedAt: v.DivisionDocumentFolderFile.updatedAt,
share: true
}))
} }
const data = await prisma.divisionDocumentFolderFile.findMany({ const data = await prisma.divisionDocumentFolderFile.findMany({
skip: dataSkip,
take: getFix,
where: kondisi, where: kondisi,
select: { select: {
id: true, id: true,
@@ -130,15 +135,8 @@ export async function GET(request: Request) {
const formatData = _.orderBy(allData, ['category', 'createdAt'], ['desc', 'desc']); const formatData = _.orderBy(allData, ['category', 'createdAt'], ['desc', 'desc']);
const fixData = formatData.map((v: any) => ({
..._.omit(v, ["createdAt", "updatedAt"]),
createdAt: moment(v.createdAt).format("DD-MM-YYYY HH:mm"),
updatedAt: moment(v.updatedAt).format("DD-MM-YYYY HH:mm"),
}))
return NextResponse.json({ success: true, message: "Berhasil mendapatkan item", data: formatData }, { status: 200 });
return NextResponse.json({ success: true, message: "Berhasil mendapatkan item", data: fixData }, { status: 200 });
} catch (error) { } catch (error) {
console.error(error); console.error(error);