add archive script, proccessed routes
This commit is contained in:
115
src/processed/processed.service.ts
Normal file
115
src/processed/processed.service.ts
Normal file
@@ -0,0 +1,115 @@
|
||||
import { getFilterObject, getSortObject, PageQueryParams } from "../pagination";
|
||||
import { processedFields, processedModel } from "./processed.schema";
|
||||
|
||||
export async function listProcessedPermits(
|
||||
params: PageQueryParams,
|
||||
tenantId: string
|
||||
) {
|
||||
const page = params.page || 1;
|
||||
const pageSize = params.pageSize || 10;
|
||||
const sortObj = getSortObject(params, processedFields);
|
||||
const filterObj = getFilterObject(params, processedFields);
|
||||
|
||||
const pipeline: any = [
|
||||
{
|
||||
$match: { $and: [{ tenantId: tenantId }, ...filterObj] },
|
||||
},
|
||||
];
|
||||
|
||||
if (params.searchToken && params.searchToken != "") {
|
||||
const regex = new RegExp(params.searchToken, "i");
|
||||
pipeline.push({
|
||||
$match: {
|
||||
$or: [
|
||||
{ permitNumber: { $regex: regex } },
|
||||
{ link: { $regex: regex } },
|
||||
{ "address.full_address": { $regex: regex } },
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
pipeline.push(
|
||||
...[
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
localField: "assignedTo",
|
||||
foreignField: "_id",
|
||||
as: "assignedRec",
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
_id: 1,
|
||||
pid: 1,
|
||||
permitNumber: 1,
|
||||
permitDate: 1,
|
||||
stage: 1,
|
||||
status: 1,
|
||||
link: 1,
|
||||
address: 1,
|
||||
recordType: 1,
|
||||
description: 1,
|
||||
applicationDetails: 1,
|
||||
applicationInfo: 1,
|
||||
applicationInfoTable: 1,
|
||||
conditions: 1,
|
||||
ownerDetails: 1,
|
||||
parcelInfo: 1,
|
||||
paymentData: 1,
|
||||
inspections: 1,
|
||||
newProcessingStatus: 1,
|
||||
newPayment: 1,
|
||||
newConditions: 1,
|
||||
professionals: 1,
|
||||
recordid: 1,
|
||||
relatedRecords: 1,
|
||||
accelaStatus: 1,
|
||||
createdAt: 1,
|
||||
county: 1,
|
||||
client: 1,
|
||||
clientData: 1,
|
||||
openDate: 1,
|
||||
lastUpdateDate: 1,
|
||||
statusUpdated: 1,
|
||||
assignedTo: {
|
||||
$let: {
|
||||
vars: { assigned: { $arrayElemAt: ["$assignedRec", 0] } },
|
||||
in: {
|
||||
_id: "$$assigned._id",
|
||||
pid: "$$assigned.pid",
|
||||
name: "$$assigned.name",
|
||||
avatar: "$$assigned.avatar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$facet: {
|
||||
metadata: [{ $count: "count" }],
|
||||
data: [
|
||||
{ $skip: (page - 1) * pageSize },
|
||||
{ $limit: pageSize },
|
||||
{ $sort: sortObj },
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
const permitsList = await processedModel.aggregate(pipeline);
|
||||
|
||||
if (permitsList[0].data.length === 0)
|
||||
return { permits: [], metadata: { count: 0, page, pageSize } };
|
||||
|
||||
return {
|
||||
permits: permitsList[0]?.data,
|
||||
metadata: {
|
||||
count: permitsList[0].metadata[0].count,
|
||||
page,
|
||||
pageSize,
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user