permits schema update, search bug fix
This commit is contained in:
@@ -46,7 +46,6 @@ const permitSchema = new mongoose.Schema({
|
|||||||
professionalsList: Array,
|
professionalsList: Array,
|
||||||
inspections: Object,
|
inspections: Object,
|
||||||
createdAt: Date,
|
createdAt: Date,
|
||||||
updatedAt: Date,
|
|
||||||
createdBy: {
|
createdBy: {
|
||||||
type: mongoose.Types.ObjectId,
|
type: mongoose.Types.ObjectId,
|
||||||
ref: "user",
|
ref: "user",
|
||||||
@@ -55,9 +54,12 @@ const permitSchema = new mongoose.Schema({
|
|||||||
newPayment: Array,
|
newPayment: Array,
|
||||||
newConditions: Array,
|
newConditions: Array,
|
||||||
professionals: Object,
|
professionals: Object,
|
||||||
recordid: String,
|
recordId: String,
|
||||||
relatedRecords: Object,
|
relatedRecords: Object,
|
||||||
accelaStatus: String,
|
accelaStatus: String,
|
||||||
|
openDate: Date,
|
||||||
|
lastUpdatedDate: Date,
|
||||||
|
statusUpdated: Date,
|
||||||
}).index({ tenantId: 1, permitNumber: 1 }, { unique: true });
|
}).index({ tenantId: 1, permitNumber: 1 }, { unique: true });
|
||||||
|
|
||||||
export const permitFields = Object.keys(permitSchema.paths).filter(
|
export const permitFields = Object.keys(permitSchema.paths).filter(
|
||||||
|
|||||||
@@ -65,22 +65,6 @@ export async function listPermits(params: PageQueryParams, tenantId: string) {
|
|||||||
{
|
{
|
||||||
$match: { $and: [{ tenantId: tenantId }, ...filterObj] },
|
$match: { $and: [{ tenantId: tenantId }, ...filterObj] },
|
||||||
},
|
},
|
||||||
/* {
|
|
||||||
$lookup: {
|
|
||||||
from: "organizations",
|
|
||||||
localField: "county",
|
|
||||||
foreignField: "_id",
|
|
||||||
as: "countyRec",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$lookup: {
|
|
||||||
from: "organizations",
|
|
||||||
localField: "client",
|
|
||||||
foreignField: "_id",
|
|
||||||
as: "clientRec",
|
|
||||||
},
|
|
||||||
}, */
|
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: "users",
|
from: "users",
|
||||||
@@ -89,14 +73,6 @@ export async function listPermits(params: PageQueryParams, tenantId: string) {
|
|||||||
as: "assignedRec",
|
as: "assignedRec",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
$lookup: {
|
|
||||||
from: "users",
|
|
||||||
localField: "createdBy",
|
|
||||||
foreignField: "_id",
|
|
||||||
as: "createdRec",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
$project: {
|
$project: {
|
||||||
_id: 1,
|
_id: 1,
|
||||||
@@ -128,30 +104,9 @@ export async function listPermits(params: PageQueryParams, tenantId: string) {
|
|||||||
county: 1,
|
county: 1,
|
||||||
client: 1,
|
client: 1,
|
||||||
clientData: 1,
|
clientData: 1,
|
||||||
/* county: {
|
openDate: 1,
|
||||||
$let: {
|
lastUpdateDate: 1,
|
||||||
vars: { county: { $arrayElemAt: ["$countyRec", 0] } },
|
statusUpdated: 1,
|
||||||
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",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}, */
|
|
||||||
assignedTo: {
|
assignedTo: {
|
||||||
$let: {
|
$let: {
|
||||||
vars: { assigned: { $arrayElemAt: ["$assignedRec", 0] } },
|
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: [
|
$or: [
|
||||||
{ permitNumber: { $regex: regex } },
|
{ permitNumber: { $regex: regex } },
|
||||||
{ link: { $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: {
|
$lookup: {
|
||||||
from: "users",
|
from: "users",
|
||||||
@@ -302,14 +230,6 @@ export async function searchPermit(params: PageQueryParams, tenantId: string) {
|
|||||||
as: "assignedRec",
|
as: "assignedRec",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
$lookup: {
|
|
||||||
from: "users",
|
|
||||||
localField: "createdBy",
|
|
||||||
foreignField: "_id",
|
|
||||||
as: "createdRec",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
$project: {
|
$project: {
|
||||||
_id: 1,
|
_id: 1,
|
||||||
@@ -341,30 +261,9 @@ export async function searchPermit(params: PageQueryParams, tenantId: string) {
|
|||||||
county: 1,
|
county: 1,
|
||||||
client: 1,
|
client: 1,
|
||||||
clientData: 1,
|
clientData: 1,
|
||||||
/* county: {
|
openDate: 1,
|
||||||
$let: {
|
lastUpdateDate: 1,
|
||||||
vars: { county: { $arrayElemAt: ["$countyRec", 0] } },
|
statusUpdated: 1,
|
||||||
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",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}, */
|
|
||||||
assignedTo: {
|
assignedTo: {
|
||||||
$let: {
|
$let: {
|
||||||
vars: { assigned: { $arrayElemAt: ["$assignedRec", 0] } },
|
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",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user