feat: add more metaFields to alerts
This commit is contained in:
@@ -17,6 +17,15 @@ export const alertsModel = mongoose.model(
|
||||
permitType: String,
|
||||
address: String,
|
||||
createdBy: { type: String, ref: "user" },
|
||||
changes: Object,
|
||||
updatedAt: Date,
|
||||
permitNumber: String,
|
||||
standardStatus: String,
|
||||
lot: String,
|
||||
block: String,
|
||||
jobNumber: String,
|
||||
stage: Object,
|
||||
dueDate: Date,
|
||||
},
|
||||
recipientType: {
|
||||
type: String,
|
||||
@@ -29,7 +38,7 @@ export const alertsModel = mongoose.model(
|
||||
type: [String],
|
||||
default: [],
|
||||
},
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
const alertResponse = z.object({
|
||||
@@ -45,6 +54,15 @@ const alertResponse = z.object({
|
||||
permitType: z.string().optional(),
|
||||
address: z.string().optional(),
|
||||
createdBy: z.any().optional(),
|
||||
changes: z.any().optional(),
|
||||
updatedAt: z.date().optional(),
|
||||
permitNumber: z.string().optional(),
|
||||
standardStatus: z.string().optional(),
|
||||
lot: z.string().optional(),
|
||||
block: z.string().optional(),
|
||||
jobNumber: z.string().optional(),
|
||||
stage: z.any().optional(),
|
||||
dueDate: z.date().optional(),
|
||||
})
|
||||
.optional(),
|
||||
recipientType: z.enum(["user", "team"]),
|
||||
@@ -66,5 +84,5 @@ export const { schemas: alertSchemas, $ref: $alert } = buildJsonSchemas(
|
||||
listAlertResponse,
|
||||
pageQueryParams,
|
||||
},
|
||||
{ $id: "alert" },
|
||||
{ $id: "alert" }
|
||||
);
|
||||
|
||||
@@ -17,7 +17,16 @@ export async function createAlert(
|
||||
permitType?: String;
|
||||
address?: String;
|
||||
createdBy?: String;
|
||||
},
|
||||
changes?: Object;
|
||||
updatedAt?: Date;
|
||||
permitNumber?: String;
|
||||
standardStatus?: String;
|
||||
lot?: String;
|
||||
block?: String;
|
||||
jobNumber?: String;
|
||||
stage?: Object;
|
||||
dueDate?: Date;
|
||||
}
|
||||
) {
|
||||
const newAlert = await alertsModel.create({
|
||||
tenantId,
|
||||
@@ -45,13 +54,13 @@ export async function createAlert(
|
||||
createdAt: new Date(),
|
||||
},
|
||||
},
|
||||
["alert:read"],
|
||||
["alert:read"]
|
||||
);
|
||||
}
|
||||
|
||||
export async function getUserAlerts(
|
||||
user: AuthenticatedUser,
|
||||
params: PageQueryParams,
|
||||
params: PageQueryParams
|
||||
) {
|
||||
const page = params.page || 1;
|
||||
const pageSize = params.pageSize || 10;
|
||||
@@ -95,7 +104,7 @@ export async function markAsRead(alertId: string, user: AuthenticatedUser) {
|
||||
const updatedAlert = await alertsModel.findOneAndUpdate(
|
||||
{ tenantId: user.tenantId, pid: alertId },
|
||||
{ $addToSet: { readBy: user.userId } },
|
||||
{ new: true },
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
if (!updatedAlert) return null;
|
||||
@@ -123,7 +132,7 @@ export async function markAllRead(user: AuthenticatedUser) {
|
||||
|
||||
const updatedResult = await alertsModel.updateMany(
|
||||
{ $or: filters },
|
||||
{ $addToSet: { readBy: user.userId } },
|
||||
{ $addToSet: { readBy: user.userId } }
|
||||
);
|
||||
|
||||
return updatedResult;
|
||||
|
||||
@@ -8,7 +8,7 @@ export async function createNote(
|
||||
input: CreateNoteInput,
|
||||
resourceId: string,
|
||||
resourceType: string,
|
||||
user: AuthenticatedUser,
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
const userIds = extractExpressions(input.content);
|
||||
|
||||
@@ -44,7 +44,7 @@ export async function createNote(
|
||||
orgs.push({ orgId: obj.client.toString(), taggedAt: new Date() });
|
||||
noteContent = noteContent.replaceAll(
|
||||
"{{client}}",
|
||||
`{{org-${obj.client.toString()}}}`,
|
||||
`{{org-${obj.client.toString()}}}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ export async function createNote(
|
||||
orgs.push({ orgId: process.env.SUNCOAST_ID, taggedAt: new Date() });
|
||||
noteContent = noteContent.replaceAll(
|
||||
"{{agent}}",
|
||||
`{{org-${process.env.SUNCOAST_ID}}}`,
|
||||
`{{org-${process.env.SUNCOAST_ID}}}`
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -75,7 +75,7 @@ export async function createNote(
|
||||
if (!obj.taggedOrgs) obj.taggedOrgs = [];
|
||||
|
||||
const orgIndex = obj.taggedOrgs.findIndex(
|
||||
(item) => item.orgId == org.orgId,
|
||||
(item) => item.orgId == org.orgId
|
||||
);
|
||||
if (orgIndex != -1) obj.taggedOrgs[orgIndex].taggedAt = new Date();
|
||||
else obj.taggedOrgs.push(org);
|
||||
@@ -85,7 +85,7 @@ export async function createNote(
|
||||
if (!obj.taggedUsers) obj.taggedUsers = [];
|
||||
|
||||
const userIndex = obj.taggedUsers.findIndex(
|
||||
(item) => item.userId == user.userId,
|
||||
(item) => item.userId == user.userId
|
||||
);
|
||||
if (userIndex != -1) obj.taggedUsers[userIndex].taggedAt = new Date();
|
||||
else obj.taggedUsers.push(user);
|
||||
@@ -93,7 +93,7 @@ export async function createNote(
|
||||
|
||||
if (taggedUsers.length > 0) {
|
||||
const assignee = obj.assignedTo.find(
|
||||
(item) => item.toString() == taggedUsers[0].userId,
|
||||
(item) => item.toString() == taggedUsers[0].userId
|
||||
);
|
||||
|
||||
if (!assignee) obj.assignedTo.push(taggedUsers[0].userId);
|
||||
@@ -102,6 +102,26 @@ export async function createNote(
|
||||
obj.markModified("taggedUsers", "assignedTo", "taggedOrgs");
|
||||
await obj.save();
|
||||
|
||||
const metaFields: any = {};
|
||||
if (obj.client) metaFields.client = obj.client.toString();
|
||||
if (obj.county) {
|
||||
if (resourceType == "rts") metaFields.county = obj.county.toString();
|
||||
else metaFields.county = obj.county.id.toString();
|
||||
}
|
||||
if (obj.changes) metaFields.changes = obj.changes;
|
||||
if (obj.permitNumber) metaFields.permitNumber = obj.permitNumber;
|
||||
if (obj.cleanStatus) metaFields.standardStatus = obj.cleanStatus;
|
||||
if (obj.address) metaFields.address = obj.address;
|
||||
if (obj.lot) metaFields.lot = obj.lot;
|
||||
if (obj.block) metaFields.block = obj.block;
|
||||
if (obj.jobNumber) metaFields.jobNumber = obj.jobNumber;
|
||||
if (obj.permitType) metaFields.permitType = obj.permitType;
|
||||
if (obj.stage) metaFields.stage = obj.stage;
|
||||
if (obj.dueDate) metaFields.dueDate = obj.dueDate;
|
||||
if (obj.updatedAt) metaFields.updatedAt = obj.updatedAt;
|
||||
|
||||
metaFields.createdBy = user.userId;
|
||||
|
||||
if (taggedUsers.length > 0) {
|
||||
for (const taggedUser of taggedUsers) {
|
||||
if (taggedUser.userId == user.userId) continue;
|
||||
@@ -114,8 +134,8 @@ export async function createNote(
|
||||
resourceId,
|
||||
resourceType,
|
||||
{
|
||||
createdBy: user.userId,
|
||||
},
|
||||
...metaFields,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -130,8 +150,8 @@ export async function createNote(
|
||||
resourceId,
|
||||
resourceType,
|
||||
{
|
||||
createdBy: user.userId,
|
||||
},
|
||||
...metaFields,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -144,7 +164,7 @@ export async function updateNote(
|
||||
input: CreateNoteInput,
|
||||
resourceId: string,
|
||||
noteId: string,
|
||||
tenantId: string,
|
||||
tenantId: string
|
||||
) {
|
||||
return await noteModel
|
||||
.findOneAndUpdate(
|
||||
@@ -156,7 +176,7 @@ export async function updateNote(
|
||||
],
|
||||
},
|
||||
{ ...input },
|
||||
{ new: true },
|
||||
{ new: true }
|
||||
)
|
||||
.populate({ path: "createdBy", select: "pid name avatar" });
|
||||
}
|
||||
@@ -200,7 +220,7 @@ export async function listNotes(resourceId: string, tenantId: string) {
|
||||
export async function deleteNote(
|
||||
resourceId: string,
|
||||
noteId: string,
|
||||
tenantId: string,
|
||||
tenantId: string
|
||||
) {
|
||||
return await noteModel.deleteOne({
|
||||
$and: [{ pid: noteId }, { tenantId: tenantId }, { resourceId: resourceId }],
|
||||
|
||||
@@ -22,7 +22,7 @@ import { arrayDiff } from "../utils/diff";
|
||||
|
||||
export async function createNotification(
|
||||
input: CreateNotificationInput,
|
||||
tenantId: string,
|
||||
tenantId: string
|
||||
) {
|
||||
const notification = await notificationModel.create({
|
||||
...input,
|
||||
@@ -41,7 +41,7 @@ export async function createNotification(
|
||||
|
||||
export async function getNotification(
|
||||
notifId: string,
|
||||
user: AuthenticatedUser,
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
return await notificationModel
|
||||
.findOne({
|
||||
@@ -54,7 +54,7 @@ export async function getNotification(
|
||||
export async function updateNotification(
|
||||
notifId: string,
|
||||
input: UpdateNotificationInput,
|
||||
user: AuthenticatedUser,
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
if (input.assignedToOrg && input.assignedTo) {
|
||||
delete input.assignedTo;
|
||||
@@ -62,7 +62,7 @@ export async function updateNotification(
|
||||
|
||||
const oldNotification = await notificationModel.findOne(
|
||||
{ pid: notifId },
|
||||
{ assignedTo: 1, assignedToOrg: 1 },
|
||||
{ assignedTo: 1, assignedToOrg: 1 }
|
||||
);
|
||||
|
||||
const updateNotificationResult = await notificationModel
|
||||
@@ -72,7 +72,7 @@ export async function updateNotification(
|
||||
...input,
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
{ new: true },
|
||||
{ new: true }
|
||||
)
|
||||
.populate({ path: "assignedTo", select: "pid name avatar" });
|
||||
|
||||
@@ -93,22 +93,22 @@ export async function updateNotification(
|
||||
},
|
||||
notifId,
|
||||
"notifications",
|
||||
user,
|
||||
user
|
||||
);
|
||||
} else if (key == "assignedTo") {
|
||||
const newAssignees = arrayDiff(
|
||||
updateNotificationResult.assignedTo.map((item) => item._id),
|
||||
oldNotification.assignedTo,
|
||||
oldNotification.assignedTo
|
||||
);
|
||||
|
||||
if (newAssignees.length > 0) {
|
||||
let msg = "Assigned to:\n\n";
|
||||
|
||||
for (const assignee of newAssignees) {
|
||||
const user = await getUser(assignee);
|
||||
if (!user) continue;
|
||||
const assigneeDB = await getUser(assignee);
|
||||
if (!assigneeDB) continue;
|
||||
|
||||
msg += `${user.firstName + " " + user.lastName}\n`;
|
||||
msg += `${assigneeDB.firstName + " " + assigneeDB.lastName}\n`;
|
||||
|
||||
await createAlert(
|
||||
user.tenantId,
|
||||
@@ -118,9 +118,13 @@ export async function updateNotification(
|
||||
updateNotificationResult.pid,
|
||||
"permits",
|
||||
{
|
||||
changes: updateNotificationResult.changes,
|
||||
client: updateNotificationResult.client.toString(),
|
||||
county: updateNotificationResult.county.id.toString(),
|
||||
},
|
||||
updatedAt: updateNotificationResult.updatedAt,
|
||||
permitNumber: updateNotificationResult.permitNumber,
|
||||
createdBy: user.userId,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -130,7 +134,7 @@ export async function updateNotification(
|
||||
},
|
||||
notifId,
|
||||
"notifications",
|
||||
user,
|
||||
user
|
||||
);
|
||||
}
|
||||
} else if (key == "assignedToOrg") {
|
||||
@@ -155,9 +159,13 @@ export async function updateNotification(
|
||||
updateNotificationResult.pid,
|
||||
"permits",
|
||||
{
|
||||
changes: updateNotificationResult.changes,
|
||||
client: updateNotificationResult.client.toString(),
|
||||
county: updateNotificationResult.county.id.toString(),
|
||||
},
|
||||
updatedAt: updateNotificationResult.updatedAt,
|
||||
permitNumber: updateNotificationResult.permitNumber,
|
||||
createdBy: user.userId,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -168,7 +176,7 @@ export async function updateNotification(
|
||||
|
||||
export async function listNotifications(
|
||||
params: PageQueryParams,
|
||||
user: AuthenticatedUser,
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
const page = params.page || 1;
|
||||
const pageSize = params.pageSize || 10;
|
||||
@@ -207,12 +215,12 @@ export async function listNotifications(
|
||||
|
||||
let { taggedUsersFilter, taggedUserFilterIndex } = getTaggedUsersFilter(
|
||||
filterObj,
|
||||
sortObj,
|
||||
sortObj
|
||||
);
|
||||
|
||||
let { taggedOrgsFilter, taggedOrgsFilterIndex } = getTaggedOrgsFilter(
|
||||
filterObj,
|
||||
sortObj,
|
||||
sortObj
|
||||
);
|
||||
|
||||
if (taggedUserFilterIndex != -1) filterObj.splice(taggedUserFilterIndex, 1);
|
||||
@@ -289,7 +297,7 @@ export async function listNotifications(
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
const notifications = await notificationModel.aggregate(pipeline);
|
||||
|
||||
@@ -25,7 +25,7 @@ import { arrayDiff } from "../utils/diff";
|
||||
|
||||
export async function createPermit(
|
||||
input: CreatePermitInput,
|
||||
user: AuthenticatedUser,
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
if (!input.stage) {
|
||||
input.stage = {
|
||||
@@ -64,7 +64,7 @@ export async function createPermit(
|
||||
orgId: permit.client.toString(),
|
||||
document: permit,
|
||||
} as ChangeEvent,
|
||||
["permit:read"],
|
||||
["permit:read"]
|
||||
);
|
||||
|
||||
return await permit.populate({
|
||||
@@ -89,7 +89,7 @@ export async function createPermit(
|
||||
orgId: permit.client.toString(),
|
||||
document: permit,
|
||||
} as ChangeEvent,
|
||||
["permit:read"],
|
||||
["permit:read"]
|
||||
);
|
||||
|
||||
return await permit.populate({
|
||||
@@ -131,7 +131,7 @@ export async function getPermit(permitId: string, user: AuthenticatedUser) {
|
||||
|
||||
export async function listPermits(
|
||||
params: PageQueryParams,
|
||||
user: AuthenticatedUser,
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
const page = params.page || 1;
|
||||
const pageSize = params.pageSize || 10;
|
||||
@@ -156,12 +156,12 @@ export async function listPermits(
|
||||
|
||||
let { taggedUsersFilter, taggedUserFilterIndex } = getTaggedUsersFilter(
|
||||
filterObj,
|
||||
sortObj,
|
||||
sortObj
|
||||
);
|
||||
|
||||
let { taggedOrgsFilter, taggedOrgsFilterIndex } = getTaggedOrgsFilter(
|
||||
filterObj,
|
||||
sortObj,
|
||||
sortObj
|
||||
);
|
||||
|
||||
if (taggedUserFilterIndex != -1) filterObj.splice(taggedUserFilterIndex, 1);
|
||||
@@ -274,7 +274,7 @@ export async function listPermits(
|
||||
export async function updatePermit(
|
||||
input: CreatePermitInput,
|
||||
permitId: string,
|
||||
user: AuthenticatedUser,
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
if (input.assignedToOrg && input.assignedTo) {
|
||||
delete input.assignedTo;
|
||||
@@ -282,7 +282,7 @@ export async function updatePermit(
|
||||
|
||||
const oldPermitResult = await permitModel.findOne(
|
||||
{ pid: permitId },
|
||||
{ assignedTo: 1, assignedToOrg: 1 },
|
||||
{ assignedTo: 1, assignedToOrg: 1 }
|
||||
);
|
||||
const updatePermitResult = await permitModel
|
||||
.findOneAndUpdate(
|
||||
@@ -290,7 +290,7 @@ export async function updatePermit(
|
||||
$and: [{ tenantId: user.tenantId }, { pid: permitId }],
|
||||
},
|
||||
{ ...input, lastUpdateDate: new Date() },
|
||||
{ new: true },
|
||||
{ new: true }
|
||||
)
|
||||
.populate({ path: "assignedTo", select: "pid name avatar" })
|
||||
.populate({ path: "createdBy", select: "pid name avatar" });
|
||||
@@ -314,7 +314,7 @@ export async function updatePermit(
|
||||
},
|
||||
permitId,
|
||||
"permits",
|
||||
user,
|
||||
user
|
||||
);
|
||||
|
||||
if (key == "requests" && input[key] != null) {
|
||||
@@ -337,7 +337,13 @@ export async function updatePermit(
|
||||
client: updatePermitResult.client.toString(),
|
||||
county: updatePermitResult.county.id.toString(),
|
||||
address: updatePermitResult.address,
|
||||
},
|
||||
permitNumber: updatePermitResult.permitNumber,
|
||||
standardStatus: updatePermitResult.cleanStatus,
|
||||
lot: updatePermitResult.lot,
|
||||
block: updatePermitResult.block,
|
||||
jobNumber: updatePermitResult.jobNumber,
|
||||
createdBy: user.userId,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -360,13 +366,13 @@ export async function updatePermit(
|
||||
},
|
||||
permitId,
|
||||
"permits",
|
||||
user,
|
||||
user
|
||||
);
|
||||
}
|
||||
} else if (key == "assignedTo") {
|
||||
const newAssignees = arrayDiff(
|
||||
updatePermitResult.assignedTo.map((item) => item._id),
|
||||
oldPermitResult.assignedTo,
|
||||
oldPermitResult.assignedTo
|
||||
);
|
||||
|
||||
if (newAssignees.length == 0) continue;
|
||||
@@ -374,10 +380,10 @@ export async function updatePermit(
|
||||
let msg = "Assigned to:\n\n";
|
||||
|
||||
for (const assignee of newAssignees) {
|
||||
const user = await getUser(assignee);
|
||||
if (!user) continue;
|
||||
const assigneeDB = await getUser(assignee);
|
||||
if (!assigneeDB) continue;
|
||||
|
||||
msg += `${user.firstName + " " + user.lastName}\n`;
|
||||
msg += `${assigneeDB.firstName + " " + assigneeDB.lastName}\n`;
|
||||
|
||||
await createAlert(
|
||||
user.tenantId,
|
||||
@@ -389,8 +395,14 @@ export async function updatePermit(
|
||||
{
|
||||
client: updatePermitResult.client.toString(),
|
||||
county: updatePermitResult.county.id.toString(),
|
||||
address: updatePermitResult.address.full_address,
|
||||
},
|
||||
address: updatePermitResult.address,
|
||||
permitNumber: updatePermitResult.permitNumber,
|
||||
standardStatus: updatePermitResult.cleanStatus,
|
||||
lot: updatePermitResult.lot,
|
||||
block: updatePermitResult.block,
|
||||
jobNumber: updatePermitResult.jobNumber,
|
||||
createdBy: user.userId,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -400,7 +412,7 @@ export async function updatePermit(
|
||||
},
|
||||
permitId,
|
||||
"permits",
|
||||
user,
|
||||
user
|
||||
);
|
||||
} else if (key == "assignedToOrg") {
|
||||
if (oldPermitResult.assignedToOrg == updatePermitResult.assignedToOrg)
|
||||
@@ -426,8 +438,14 @@ export async function updatePermit(
|
||||
{
|
||||
client: updatePermitResult.client.toString(),
|
||||
county: updatePermitResult.county.id.toString(),
|
||||
address: updatePermitResult.address.full_address,
|
||||
},
|
||||
address: updatePermitResult.address,
|
||||
permitNumber: updatePermitResult.permitNumber,
|
||||
standardStatus: updatePermitResult.cleanStatus,
|
||||
lot: updatePermitResult.lot,
|
||||
block: updatePermitResult.block,
|
||||
jobNumber: updatePermitResult.jobNumber,
|
||||
createdBy: user.userId,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -442,7 +460,7 @@ export async function updatePermit(
|
||||
orgId: updatePermitResult.client._id.toString(),
|
||||
document: updatePermitResult,
|
||||
} as ChangeEvent,
|
||||
["permit:read"],
|
||||
["permit:read"]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -464,7 +482,7 @@ export async function deletePermit(permitId: string, tenantId: string) {
|
||||
pid: permitId,
|
||||
},
|
||||
} as ChangeEvent,
|
||||
["permit:read"],
|
||||
["permit:read"]
|
||||
);
|
||||
|
||||
return res;
|
||||
@@ -472,7 +490,7 @@ export async function deletePermit(permitId: string, tenantId: string) {
|
||||
|
||||
export async function searchPermit(
|
||||
params: PageQueryParams,
|
||||
user: AuthenticatedUser,
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
const page = params.page || 1;
|
||||
const pageSize = params.pageSize || 10;
|
||||
@@ -671,7 +689,7 @@ export async function bulkImport(csvData: any[], user: AuthenticatedUser) {
|
||||
clientCache[clientName] = clientData;
|
||||
} else {
|
||||
errors.push(
|
||||
"Client not found. The value in Client column must exactly match the client name in Quicker Permits",
|
||||
"Client not found. The value in Client column must exactly match the client name in Quicker Permits"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -692,7 +710,7 @@ export async function bulkImport(csvData: any[], user: AuthenticatedUser) {
|
||||
countyCache[countyName] = countyData;
|
||||
} else {
|
||||
errors.push(
|
||||
"County not found. The value in County column must exactly match the county name in Quicker Permits",
|
||||
"County not found. The value in County column must exactly match the county name in Quicker Permits"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import { arrayDiff } from "../utils/diff";
|
||||
|
||||
export async function getProcessedPermit(
|
||||
permitId: String,
|
||||
user: AuthenticatedUser,
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
const permit = await processedModel
|
||||
.findOne({
|
||||
@@ -42,7 +42,7 @@ export async function getProcessedPermit(
|
||||
export async function updateProcessed(
|
||||
input: UpdateProcessedInput,
|
||||
permitId: string,
|
||||
user: AuthenticatedUser,
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
if (input.assignedToOrg && input.assignedTo) {
|
||||
delete input.assignedTo;
|
||||
@@ -50,7 +50,7 @@ export async function updateProcessed(
|
||||
|
||||
const oldPermitResult = await processedModel.findOne(
|
||||
{ pid: permitId },
|
||||
{ assignedTo: 1, assignedToOrg: 1 },
|
||||
{ assignedTo: 1, assignedToOrg: 1 }
|
||||
);
|
||||
const updateProcessedResult = await processedModel
|
||||
.findOneAndUpdate(
|
||||
@@ -58,7 +58,7 @@ export async function updateProcessed(
|
||||
$and: [{ tenantId: user.tenantId }, { pid: permitId }],
|
||||
},
|
||||
{ ...input, lastUpdateDate: new Date() },
|
||||
{ new: true },
|
||||
{ new: true }
|
||||
)
|
||||
.populate({ path: "county", select: "pid name avatar" })
|
||||
.populate({ path: "assignedTo", select: "pid name avatar" })
|
||||
@@ -81,7 +81,7 @@ export async function updateProcessed(
|
||||
},
|
||||
permitId,
|
||||
"processed",
|
||||
user,
|
||||
user
|
||||
);
|
||||
} else if (key == "client") {
|
||||
const orgInDb = await orgModel.findById(input.client);
|
||||
@@ -102,13 +102,13 @@ export async function updateProcessed(
|
||||
},
|
||||
permitId,
|
||||
"permits",
|
||||
user,
|
||||
user
|
||||
);
|
||||
}
|
||||
} else if (key == "assignedTo") {
|
||||
const newAssignees = arrayDiff(
|
||||
updateProcessedResult.assignedTo.map((item) => item._id),
|
||||
oldPermitResult.assignedTo,
|
||||
oldPermitResult.assignedTo
|
||||
);
|
||||
|
||||
if (newAssignees.length == 0) continue;
|
||||
@@ -116,10 +116,10 @@ export async function updateProcessed(
|
||||
let msg = "Assigned to:\n\n";
|
||||
|
||||
for (const assignee of newAssignees) {
|
||||
const user = await getUser(assignee);
|
||||
if (!user) continue;
|
||||
const assigneeDB = await getUser(assignee);
|
||||
if (!assigneeDB) continue;
|
||||
|
||||
msg += `${user.firstName + " " + user.lastName}\n`;
|
||||
msg += `${assigneeDB.firstName + " " + assigneeDB.lastName}\n`;
|
||||
|
||||
await createAlert(
|
||||
user.tenantId,
|
||||
@@ -131,8 +131,14 @@ export async function updateProcessed(
|
||||
{
|
||||
client: updateProcessedResult.client.toString(),
|
||||
county: updateProcessedResult.county.id.toString(),
|
||||
address: updateProcessedResult.address.full_address,
|
||||
},
|
||||
address: updateProcessedResult.address,
|
||||
permitNumber: updateProcessedResult.permitNumber,
|
||||
standardStatus: updateProcessedResult.cleanStatus,
|
||||
lot: updateProcessedResult.lot,
|
||||
block: updateProcessedResult.block,
|
||||
jobNumber: updateProcessedResult.jobNumber,
|
||||
createdBy: user.userId,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -142,7 +148,7 @@ export async function updateProcessed(
|
||||
},
|
||||
permitId,
|
||||
"processed",
|
||||
user,
|
||||
user
|
||||
);
|
||||
} else if (key == "assignedToOrg") {
|
||||
if (
|
||||
@@ -167,8 +173,14 @@ export async function updateProcessed(
|
||||
{
|
||||
client: updateProcessedResult.client.toString(),
|
||||
county: updateProcessedResult.county.id.toString(),
|
||||
address: updateProcessedResult.address.full_address,
|
||||
},
|
||||
address: updateProcessedResult.address,
|
||||
permitNumber: updateProcessedResult.permitNumber,
|
||||
standardStatus: updateProcessedResult.cleanStatus,
|
||||
lot: updateProcessedResult.lot,
|
||||
block: updateProcessedResult.block,
|
||||
jobNumber: updateProcessedResult.jobNumber,
|
||||
createdBy: user.userId,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -179,7 +191,7 @@ export async function updateProcessed(
|
||||
|
||||
export async function listProcessedPermits(
|
||||
params: PageQueryParams,
|
||||
user: AuthenticatedUser,
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
const page = params.page || 1;
|
||||
const pageSize = params.pageSize || 10;
|
||||
@@ -204,12 +216,12 @@ export async function listProcessedPermits(
|
||||
|
||||
let { taggedUsersFilter, taggedUserFilterIndex } = getTaggedUsersFilter(
|
||||
filterObj,
|
||||
sortObj,
|
||||
sortObj
|
||||
);
|
||||
|
||||
let { taggedOrgsFilter, taggedOrgsFilterIndex } = getTaggedOrgsFilter(
|
||||
filterObj,
|
||||
sortObj,
|
||||
sortObj
|
||||
);
|
||||
|
||||
if (taggedUserFilterIndex != -1) filterObj.splice(taggedUserFilterIndex, 1);
|
||||
@@ -321,7 +333,7 @@ export async function listProcessedPermits(
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
const permitsList = await processedModel.aggregate(pipeline);
|
||||
|
||||
@@ -24,7 +24,7 @@ import { getOrg } from "../organization/organization.service";
|
||||
|
||||
export async function createRts(
|
||||
input: CreateRtsInput,
|
||||
user: AuthenticatedUser,
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
let defaultClient = input.client;
|
||||
|
||||
@@ -80,7 +80,7 @@ export async function getRts(id: string, tenantId: string) {
|
||||
|
||||
export async function listRts(
|
||||
params: PageQueryParams,
|
||||
user: AuthenticatedUser,
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
const page = params.page || 1;
|
||||
const pageSize = params.pageSize || 10;
|
||||
@@ -105,12 +105,12 @@ export async function listRts(
|
||||
|
||||
let { taggedUsersFilter, taggedUserFilterIndex } = getTaggedUsersFilter(
|
||||
filterObj,
|
||||
sortObj,
|
||||
sortObj
|
||||
);
|
||||
|
||||
let { taggedOrgsFilter, taggedOrgsFilterIndex } = getTaggedOrgsFilter(
|
||||
filterObj,
|
||||
sortObj,
|
||||
sortObj
|
||||
);
|
||||
|
||||
if (taggedUserFilterIndex != -1) filterObj.splice(taggedUserFilterIndex, 1);
|
||||
@@ -249,7 +249,7 @@ export async function listRts(
|
||||
export async function updateRts(
|
||||
id: string,
|
||||
input: UpdateRtsInput,
|
||||
user: AuthenticatedUser,
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
if (input.assignedToOrg && input.assignedTo) {
|
||||
delete input.assignedTo;
|
||||
@@ -257,7 +257,7 @@ export async function updateRts(
|
||||
|
||||
const oldRts = await rtsModel.findOne(
|
||||
{ pid: id },
|
||||
{ assignedTo: 1, assignedToOrg: 1 },
|
||||
{ assignedTo: 1, assignedToOrg: 1 }
|
||||
);
|
||||
|
||||
const updatedRts = await rtsModel
|
||||
@@ -274,24 +274,24 @@ export async function updateRts(
|
||||
{ content: `Updated type to '${input.permitType}'` },
|
||||
id,
|
||||
"rts",
|
||||
user,
|
||||
user
|
||||
);
|
||||
}
|
||||
|
||||
if (updatedRts && input.assignedTo) {
|
||||
const newAssignees = arrayDiff(
|
||||
updatedRts.assignedTo.map((item) => item._id),
|
||||
oldRts.assignedTo,
|
||||
oldRts.assignedTo
|
||||
);
|
||||
|
||||
if (newAssignees.length > 0) {
|
||||
let msg = "Assigned to:\n\n";
|
||||
|
||||
for (const assignee of newAssignees) {
|
||||
const user = await getUser(assignee);
|
||||
if (!user) continue;
|
||||
const assigneeDB = await getUser(assignee);
|
||||
if (!assigneeDB) continue;
|
||||
|
||||
msg += `${user.firstName + " " + user.lastName}\n`;
|
||||
msg += `${assigneeDB.firstName + " " + assigneeDB.lastName}\n`;
|
||||
|
||||
await createAlert(
|
||||
user.tenantId,
|
||||
@@ -306,7 +306,10 @@ export async function updateRts(
|
||||
//@ts-ignore
|
||||
county: updatedRts.county._id.toString(),
|
||||
permitType: updatedRts.permitType,
|
||||
},
|
||||
stage: updatedRts.stage,
|
||||
dueDate: updatedRts.dueDate,
|
||||
createdBy: user.userId,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -316,7 +319,7 @@ export async function updateRts(
|
||||
},
|
||||
id,
|
||||
"rts",
|
||||
user,
|
||||
user
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -346,7 +349,10 @@ export async function updateRts(
|
||||
//@ts-ignore
|
||||
county: updatedRts.county._id.toString(),
|
||||
permitType: updatedRts.permitType,
|
||||
},
|
||||
stage: updatedRts.stage,
|
||||
dueDate: updatedRts.dueDate,
|
||||
createdBy: user.userId,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -360,7 +366,7 @@ export async function deleteRts(id: string, tenantId: string) {
|
||||
export async function newUpload(
|
||||
id: string,
|
||||
newUpload: UploadRtsInput,
|
||||
user: AuthenticatedUser,
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
return await rtsModel.findOneAndUpdate(
|
||||
{ pid: id, tenantId: user.tenantId },
|
||||
@@ -372,6 +378,6 @@ export async function newUpload(
|
||||
createdBy: user.userId,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user