permits schema update, search bug fix

This commit is contained in:
2025-03-05 12:19:20 +05:30
parent c00e68bb47
commit 13f8c91201
2 changed files with 11 additions and 121 deletions

View File

@@ -46,7 +46,6 @@ const permitSchema = new mongoose.Schema({
professionalsList: Array,
inspections: Object,
createdAt: Date,
updatedAt: Date,
createdBy: {
type: mongoose.Types.ObjectId,
ref: "user",
@@ -55,9 +54,12 @@ const permitSchema = new mongoose.Schema({
newPayment: Array,
newConditions: Array,
professionals: Object,
recordid: String,
recordId: String,
relatedRecords: Object,
accelaStatus: String,
openDate: Date,
lastUpdatedDate: Date,
statusUpdated: Date,
}).index({ tenantId: 1, permitNumber: 1 }, { unique: true });
export const permitFields = Object.keys(permitSchema.paths).filter(

View File

@@ -65,22 +65,6 @@ export async function listPermits(params: PageQueryParams, tenantId: string) {
{
$match: { $and: [{ tenantId: tenantId }, ...filterObj] },
},
/* {
$lookup: {
from: "organizations",
localField: "county",
foreignField: "_id",
as: "countyRec",
},
},
{
$lookup: {
from: "organizations",
localField: "client",
foreignField: "_id",
as: "clientRec",
},
}, */
{
$lookup: {
from: "users",
@@ -89,14 +73,6 @@ export async function listPermits(params: PageQueryParams, tenantId: string) {
as: "assignedRec",
},
},
{
$lookup: {
from: "users",
localField: "createdBy",
foreignField: "_id",
as: "createdRec",
},
},
{
$project: {
_id: 1,
@@ -128,30 +104,9 @@ export async function listPermits(params: PageQueryParams, tenantId: string) {
county: 1,
client: 1,
clientData: 1,
/* county: {
$let: {
vars: { county: { $arrayElemAt: ["$countyRec", 0] } },
in: {
_id: "$$county._id",
pid: "$$county.pid",
name: "$$county.name",
type: "$$county.type",
avatar: "$$county.avatar",
},
},
},
client: {
$let: {
vars: { client: { $arrayElemAt: ["$clientRec", 0] } },
in: {
_id: "$$client._id",
pid: "$$client.pid",
name: "$$client.name",
type: "$$client.type",
avatar: "$$client.avatar",
},
},
}, */
openDate: 1,
lastUpdateDate: 1,
statusUpdated: 1,
assignedTo: {
$let: {
vars: { assigned: { $arrayElemAt: ["$assignedRec", 0] } },
@@ -163,17 +118,6 @@ export async function listPermits(params: PageQueryParams, tenantId: string) {
},
},
},
createdBy: {
$let: {
vars: { created: { $arrayElemAt: ["$createdRec", 0] } },
in: {
_id: "$$created._id",
pid: "$$created.pid",
name: "$$created.name",
avatar: "$$created.avatar",
},
},
},
},
},
{
@@ -274,26 +218,10 @@ export async function searchPermit(params: PageQueryParams, tenantId: string) {
$or: [
{ permitNumber: { $regex: regex } },
{ link: { $regex: regex } },
{ address: { $regex: regex } },
{ "address.full_address": { $regex: regex } },
],
},
},
/* {
$lookup: {
from: "organizations",
localField: "county",
foreignField: "_id",
as: "countyRec",
},
},
{
$lookup: {
from: "organizations",
localField: "client",
foreignField: "_id",
as: "clientRec",
},
}, */
{
$lookup: {
from: "users",
@@ -302,14 +230,6 @@ export async function searchPermit(params: PageQueryParams, tenantId: string) {
as: "assignedRec",
},
},
{
$lookup: {
from: "users",
localField: "createdBy",
foreignField: "_id",
as: "createdRec",
},
},
{
$project: {
_id: 1,
@@ -341,30 +261,9 @@ export async function searchPermit(params: PageQueryParams, tenantId: string) {
county: 1,
client: 1,
clientData: 1,
/* county: {
$let: {
vars: { county: { $arrayElemAt: ["$countyRec", 0] } },
in: {
_id: "$$county._id",
pid: "$$county.pid",
name: "$$county.name",
type: "$$county.type",
avatar: "$$county.avatar",
},
},
},
client: {
$let: {
vars: { client: { $arrayElemAt: ["$clientRec", 0] } },
in: {
_id: "$$client._id",
pid: "$$client.pid",
name: "$$client.name",
type: "$$client.type",
avatar: "$$client.avatar",
},
},
}, */
openDate: 1,
lastUpdateDate: 1,
statusUpdated: 1,
assignedTo: {
$let: {
vars: { assigned: { $arrayElemAt: ["$assignedRec", 0] } },
@@ -376,17 +275,6 @@ export async function searchPermit(params: PageQueryParams, tenantId: string) {
},
},
},
createdBy: {
$let: {
vars: { created: { $arrayElemAt: ["$createdRec", 0] } },
in: {
_id: "$$created._id",
pid: "$$created.pid",
name: "$$created.name",
avatar: "$$created.avatar",
},
},
},
},
},
{