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,30 +11,42 @@ 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 = {
isActive: true,
idDivision: String(idDivision),
path: (path == "undefined" || path == "null" || path == "" || path == null) ? "home" : path,
category: "FOLDER"
}
} else {
if (path == "home" || path == "null" || path == "undefined") {
const dataShare = await prisma.divisionDocumentShare.findMany({ const dataShare = await prisma.divisionDocumentShare.findMany({
where: { where: {
isActive: true, isActive: true,
@@ -84,17 +94,12 @@ export async function GET(request: Request) {
updatedAt: v.DivisionDocumentFolderFile.updatedAt, updatedAt: v.DivisionDocumentFolderFile.updatedAt,
share: true share: true
})) }))
} else {
kondisi = {
isActive: true,
path: (path == "undefined" || path == "null" || path == null) ? "home" : path
}
}
} }
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);