upd: api ai document divisi
Deskripsi: - list dokumen dan file divisi NO Issues
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import { createLogUser } from "@/module/user";
|
||||
import _ from "lodash";
|
||||
import moment from "moment";
|
||||
import { NextResponse } from "next/server";
|
||||
@@ -13,88 +11,95 @@ export async function GET(request: Request) {
|
||||
const idDivision = searchParams.get("division");
|
||||
const villageId = searchParams.get("desa");
|
||||
const path = searchParams.get("path");
|
||||
const category = searchParams.get("category");
|
||||
const active = searchParams.get("active");
|
||||
const search = searchParams.get("search");
|
||||
const page = searchParams.get("page");
|
||||
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 = {
|
||||
isActive: true,
|
||||
idDivision: String(idDivision),
|
||||
path: (path == "undefined" || path == "null" || path == "" || path == null) ? "home" : path
|
||||
Division: {
|
||||
idVillage: String(villageId)
|
||||
},
|
||||
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[] = [];
|
||||
|
||||
if (category == "folder") {
|
||||
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({
|
||||
where: {
|
||||
isActive: true,
|
||||
idDivision: String(idDivision),
|
||||
DivisionDocumentFolderFile: {
|
||||
isActive: true
|
||||
}
|
||||
},
|
||||
select: {
|
||||
DivisionDocumentFolderFile: {
|
||||
select: {
|
||||
idStorage: true,
|
||||
id: true,
|
||||
category: true,
|
||||
name: true,
|
||||
extension: true,
|
||||
path: true,
|
||||
User: {
|
||||
select: {
|
||||
name: true
|
||||
}
|
||||
},
|
||||
createdAt: true,
|
||||
updatedAt: true
|
||||
}
|
||||
}
|
||||
},
|
||||
orderBy: {
|
||||
DivisionDocumentFolderFile: {
|
||||
createdAt: 'desc'
|
||||
if (path == "home" || path == "null" || path == "undefined" || path == null || path == undefined || path == "") {
|
||||
const dataShare = await prisma.divisionDocumentShare.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
idDivision: String(idDivision),
|
||||
DivisionDocumentFolderFile: {
|
||||
isActive: true
|
||||
}
|
||||
},
|
||||
select: {
|
||||
DivisionDocumentFolderFile: {
|
||||
select: {
|
||||
idStorage: true,
|
||||
id: true,
|
||||
category: true,
|
||||
name: true,
|
||||
extension: true,
|
||||
path: true,
|
||||
User: {
|
||||
select: {
|
||||
name: true
|
||||
}
|
||||
},
|
||||
createdAt: true,
|
||||
updatedAt: true
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
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
|
||||
}))
|
||||
|
||||
} else {
|
||||
kondisi = {
|
||||
isActive: true,
|
||||
path: (path == "undefined" || path == "null" || path == null) ? "home" : path
|
||||
},
|
||||
orderBy: {
|
||||
DivisionDocumentFolderFile: {
|
||||
createdAt: 'desc'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
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({
|
||||
skip: dataSkip,
|
||||
take: getFix,
|
||||
where: kondisi,
|
||||
select: {
|
||||
id: true,
|
||||
@@ -130,15 +135,8 @@ export async function GET(request: Request) {
|
||||
|
||||
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: fixData }, { status: 200 });
|
||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan item", data: formatData }, { status: 200 });
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
Reference in New Issue
Block a user