refactoring

deepsource-autofix-76c6eb20
Dan Gowans 2022-12-30 10:22:53 -05:00
parent f641e01f7f
commit b60ebf78cc
2 changed files with 109 additions and 112 deletions

View File

@ -24,7 +24,6 @@ function buildEventSummary(milestone) {
(milestone.workOrderMilestoneTypeId (milestone.workOrderMilestoneTypeId
? milestone.workOrderMilestoneType ? milestone.workOrderMilestoneType
: milestone.workOrderMilestoneDescription).trim(); : milestone.workOrderMilestoneDescription).trim();
if (milestone.workOrderLotOccupancies.length > 0) {
let occupantCount = 0; let occupantCount = 0;
for (const lotOccupancy of milestone.workOrderLotOccupancies) { for (const lotOccupancy of milestone.workOrderLotOccupancies) {
for (const occupant of lotOccupancy.lotOccupancyOccupants) { for (const occupant of lotOccupancy.lotOccupancyOccupants) {
@ -40,40 +39,38 @@ function buildEventSummary(milestone) {
if (occupantCount > 1) { if (occupantCount > 1) {
summary += " plus " + (occupantCount - 1); summary += " plus " + (occupantCount - 1);
} }
}
return summary; return summary;
} }
function buildEventDescriptionHTML_occupancies(request, milestone) { function buildEventDescriptionHTML_occupancies(request, milestone) {
let descriptionHTML = ""; let descriptionHTML = "";
if (milestone.workOrderLotOccupancies.length > 0) { if (milestone.workOrderLotOccupancies.length > 0) {
const urlRoot = getUrlRoot(request); const urlRoot = getUrlRoot(request);
descriptionHTML = descriptionHTML = `<h2>
"<h2>Related " + Related ${escapeHTML(configFunctions.getProperty("aliases.occupancies"))}
escapeHTML(configFunctions.getProperty("aliases.occupancies")) + </h2>
"</h2>" + <table border="1">
'<table border="1"><thead><tr>' + <thead><tr>
("<th>" + escapeHTML(configFunctions.getProperty("aliases.occupancy")) + " Type</th>") + <th>${escapeHTML(configFunctions.getProperty("aliases.occupancy"))} Type</th>
("<th>" + escapeHTML(configFunctions.getProperty("aliases.lot")) + "</th>") + <th>${escapeHTML(configFunctions.getProperty("aliases.lot"))}</th>
"<th>Start Date</th>" + <th>Start Date</th>
"<th>End Date</th>" + <th>End Date</th>
("<th>" + escapeHTML(configFunctions.getProperty("aliases.occupants")) + "</th>") + <th>${escapeHTML(configFunctions.getProperty("aliases.occupants"))}</th>
"</tr></thead>" + </tr></thead>
"<tbody>"; <tbody>`;
for (const occupancy of milestone.workOrderLotOccupancies) { for (const occupancy of milestone.workOrderLotOccupancies) {
descriptionHTML += descriptionHTML +=
"<tr>" + `<tr>
("<td>" + <td>
'<a href="' + <a href="${urlRoot}/lotOccupancies/${occupancy.lotOccupancyId}">
urlRoot + ${escapeHTML(occupancy.occupancyType)}
"/lotOccupancies/" + </a>
occupancy.lotOccupancyId + </td>
'">' + <td>
escapeHTML(occupancy.occupancyType) + ${occupancy.lotName ? escapeHTML(occupancy.lotName) : "(Not Set)"}
"</a></td>") + </td>
("<td>" + <td>
(occupancy.lotName ? escapeHTML(occupancy.lotName) : "(Not Set)") + ${occupancy.occupancyStartDateString}
"</td>") + </td>` +
("<td>" + occupancy.occupancyStartDateString + "</td>") +
"<td>" + "<td>" +
(occupancy.occupancyEndDate ? occupancy.occupancyEndDateString : "(No End Date)") + (occupancy.occupancyEndDate ? occupancy.occupancyEndDateString : "(No End Date)") +
"</td>" + "</td>" +
@ -85,7 +82,7 @@ function buildEventDescriptionHTML_occupancies(request, milestone) {
escapeHTML(occupant.occupantName) + escapeHTML(occupant.occupantName) +
"<br />"; "<br />";
} }
descriptionHTML += "</td>" + "</tr>"; descriptionHTML += "</td></tr>";
} }
descriptionHTML += "</tbody></table>"; descriptionHTML += "</tbody></table>";
} }
@ -100,9 +97,15 @@ function buildEventDescriptionHTML_lots(request, milestone) {
escapeHTML(configFunctions.getProperty("aliases.lots")) + escapeHTML(configFunctions.getProperty("aliases.lots")) +
"</h2>" + "</h2>" +
'<table border="1"><thead><tr>' + '<table border="1"><thead><tr>' +
("<th>" + escapeHTML(configFunctions.getProperty("aliases.lot")) + " Type</th>") + `<th>
("<th>" + escapeHTML(configFunctions.getProperty("aliases.map")) + "</th>") + ${escapeHTML(configFunctions.getProperty("aliases.lot"))} Type
("<th>" + escapeHTML(configFunctions.getProperty("aliases.lot")) + " Type" + "</th>") + </th>
<th>
${escapeHTML(configFunctions.getProperty("aliases.map"))}
</th>
<th>
${escapeHTML(configFunctions.getProperty("aliases.lot"))} Type
</th>` +
"<th>Status</th>" + "<th>Status</th>" +
"</tr></thead>" + "</tr></thead>" +
"<tbody>"; "<tbody>";
@ -117,9 +120,9 @@ function buildEventDescriptionHTML_lots(request, milestone) {
'">' + '">' +
escapeHTML(lot.lotName) + escapeHTML(lot.lotName) +
"</a></td>") + "</a></td>") +
("<td>" + escapeHTML(lot.mapName) + "</td>") + `<td>${escapeHTML(lot.mapName)}</td>` +
("<td>" + escapeHTML(lot.lotType) + "</td>") + `<td>${escapeHTML(lot.lotType)}</td>` +
("<td>" + escapeHTML(lot.lotStatus) + "</td>") + `<td>${escapeHTML(lot.lotStatus)}</td>` +
"</tr>"; "</tr>";
} }
descriptionHTML += "</tbody></table>"; descriptionHTML += "</tbody></table>";
@ -148,15 +151,11 @@ function buildEventDescriptionHTML_prints(request, milestone) {
} }
function buildEventDescriptionHTML(request, milestone) { function buildEventDescriptionHTML(request, milestone) {
const workOrderUrl = getWorkOrderUrl(request, milestone); const workOrderUrl = getWorkOrderUrl(request, milestone);
let descriptionHTML = "<h1>Milestone Description</h1>" + let descriptionHTML = `<h1>Milestone Description</h1>
"<p>" + <p>${escapeHTML(milestone.workOrderMilestoneDescription)}</p>
escapeHTML(milestone.workOrderMilestoneDescription) + <h2>Work Order #${milestone.workOrderNumber}</h2>
"</p>" + <p>${escapeHTML(milestone.workOrderDescription)}</p>
"<h2>Work Order #" + <p>${workOrderUrl}</p>`;
milestone.workOrderNumber +
"</h2>" +
("<p>" + escapeHTML(milestone.workOrderDescription) + "</p>") +
("<p>" + workOrderUrl + "</p>");
descriptionHTML += buildEventDescriptionHTML_occupancies(request, milestone); descriptionHTML += buildEventDescriptionHTML_occupancies(request, milestone);
descriptionHTML += buildEventDescriptionHTML_lots(request, milestone); descriptionHTML += buildEventDescriptionHTML_lots(request, milestone);
descriptionHTML += buildEventDescriptionHTML_prints(request, milestone); descriptionHTML += buildEventDescriptionHTML_prints(request, milestone);
@ -202,7 +201,7 @@ export const handler = (request, response) => {
url: urlRoot + "/workOrders" url: urlRoot + "/workOrders"
}); });
if (request.query.workOrderId && workOrderMilestones.length > 0) { if (request.query.workOrderId && workOrderMilestones.length > 0) {
calendar.name("Work Order #" + workOrderMilestones[0].workOrderNumber); calendar.name(`Work Order #${workOrderMilestones[0].workOrderNumber}`);
calendar.url(urlRoot + "/workOrders/" + workOrderMilestones[0].workOrderId); calendar.url(urlRoot + "/workOrders/" + workOrderMilestones[0].workOrderId);
} }
calendar.prodId({ calendar.prodId({

View File

@ -46,7 +46,6 @@ function buildEventSummary(milestone: recordTypes.WorkOrderMilestone): string {
: milestone.workOrderMilestoneDescription : milestone.workOrderMilestoneDescription
).trim(); ).trim();
if (milestone.workOrderLotOccupancies.length > 0) {
let occupantCount = 0; let occupantCount = 0;
for (const lotOccupancy of milestone.workOrderLotOccupancies) { for (const lotOccupancy of milestone.workOrderLotOccupancies) {
@ -66,7 +65,6 @@ function buildEventSummary(milestone: recordTypes.WorkOrderMilestone): string {
if (occupantCount > 1) { if (occupantCount > 1) {
summary += " plus " + (occupantCount - 1); summary += " plus " + (occupantCount - 1);
} }
}
return summary; return summary;
} }
@ -80,34 +78,33 @@ function buildEventDescriptionHTML_occupancies(
if (milestone.workOrderLotOccupancies.length > 0) { if (milestone.workOrderLotOccupancies.length > 0) {
const urlRoot = getUrlRoot(request); const urlRoot = getUrlRoot(request);
descriptionHTML = descriptionHTML = `<h2>
"<h2>Related " + Related ${escapeHTML(configFunctions.getProperty("aliases.occupancies"))}
escapeHTML(configFunctions.getProperty("aliases.occupancies")) + </h2>
"</h2>" + <table border="1">
'<table border="1"><thead><tr>' + <thead><tr>
("<th>" + escapeHTML(configFunctions.getProperty("aliases.occupancy")) + " Type</th>") + <th>${escapeHTML(configFunctions.getProperty("aliases.occupancy"))} Type</th>
("<th>" + escapeHTML(configFunctions.getProperty("aliases.lot")) + "</th>") + <th>${escapeHTML(configFunctions.getProperty("aliases.lot"))}</th>
"<th>Start Date</th>" + <th>Start Date</th>
"<th>End Date</th>" + <th>End Date</th>
("<th>" + escapeHTML(configFunctions.getProperty("aliases.occupants")) + "</th>") + <th>${escapeHTML(configFunctions.getProperty("aliases.occupants"))}</th>
"</tr></thead>" + </tr></thead>
"<tbody>"; <tbody>`;
for (const occupancy of milestone.workOrderLotOccupancies) { for (const occupancy of milestone.workOrderLotOccupancies) {
descriptionHTML += descriptionHTML +=
"<tr>" + `<tr>
("<td>" + <td>
'<a href="' + <a href="${urlRoot}/lotOccupancies/${occupancy.lotOccupancyId}">
urlRoot + ${escapeHTML(occupancy.occupancyType)}
"/lotOccupancies/" + </a>
occupancy.lotOccupancyId + </td>
'">' + <td>
escapeHTML(occupancy.occupancyType) + ${occupancy.lotName ? escapeHTML(occupancy.lotName) : "(Not Set)"}
"</a></td>") + </td>
("<td>" + <td>
(occupancy.lotName ? escapeHTML(occupancy.lotName) : "(Not Set)") + ${occupancy.occupancyStartDateString}
"</td>") + </td>` +
("<td>" + occupancy.occupancyStartDateString + "</td>") +
"<td>" + "<td>" +
(occupancy.occupancyEndDate ? occupancy.occupancyEndDateString : "(No End Date)") + (occupancy.occupancyEndDate ? occupancy.occupancyEndDateString : "(No End Date)") +
"</td>" + "</td>" +
@ -121,7 +118,7 @@ function buildEventDescriptionHTML_occupancies(
"<br />"; "<br />";
} }
descriptionHTML += "</td>" + "</tr>"; descriptionHTML += "</td></tr>";
} }
descriptionHTML += "</tbody></table>"; descriptionHTML += "</tbody></table>";
@ -144,9 +141,15 @@ function buildEventDescriptionHTML_lots(
escapeHTML(configFunctions.getProperty("aliases.lots")) + escapeHTML(configFunctions.getProperty("aliases.lots")) +
"</h2>" + "</h2>" +
'<table border="1"><thead><tr>' + '<table border="1"><thead><tr>' +
("<th>" + escapeHTML(configFunctions.getProperty("aliases.lot")) + " Type</th>") + `<th>
("<th>" + escapeHTML(configFunctions.getProperty("aliases.map")) + "</th>") + ${escapeHTML(configFunctions.getProperty("aliases.lot"))} Type
("<th>" + escapeHTML(configFunctions.getProperty("aliases.lot")) + " Type" + "</th>") + </th>
<th>
${escapeHTML(configFunctions.getProperty("aliases.map"))}
</th>
<th>
${escapeHTML(configFunctions.getProperty("aliases.lot"))} Type
</th>` +
"<th>Status</th>" + "<th>Status</th>" +
"</tr></thead>" + "</tr></thead>" +
"<tbody>"; "<tbody>";
@ -162,9 +165,9 @@ function buildEventDescriptionHTML_lots(
'">' + '">' +
escapeHTML(lot.lotName) + escapeHTML(lot.lotName) +
"</a></td>") + "</a></td>") +
("<td>" + escapeHTML(lot.mapName) + "</td>") + `<td>${escapeHTML(lot.mapName)}</td>` +
("<td>" + escapeHTML(lot.lotType) + "</td>") + `<td>${escapeHTML(lot.lotType)}</td>` +
("<td>" + escapeHTML(lot.lotStatus) + "</td>") + `<td>${escapeHTML(lot.lotStatus)}</td>` +
"</tr>"; "</tr>";
} }
@ -210,16 +213,11 @@ function buildEventDescriptionHTML(
): string { ): string {
const workOrderUrl = getWorkOrderUrl(request, milestone); const workOrderUrl = getWorkOrderUrl(request, milestone);
let descriptionHTML = let descriptionHTML = `<h1>Milestone Description</h1>
"<h1>Milestone Description</h1>" + <p>${escapeHTML(milestone.workOrderMilestoneDescription)}</p>
"<p>" + <h2>Work Order #${milestone.workOrderNumber}</h2>
escapeHTML(milestone.workOrderMilestoneDescription) + <p>${escapeHTML(milestone.workOrderDescription)}</p>
"</p>" + <p>${workOrderUrl}</p>`;
"<h2>Work Order #" +
milestone.workOrderNumber +
"</h2>" +
("<p>" + escapeHTML(milestone.workOrderDescription) + "</p>") +
("<p>" + workOrderUrl + "</p>");
descriptionHTML += buildEventDescriptionHTML_occupancies(request, milestone); descriptionHTML += buildEventDescriptionHTML_occupancies(request, milestone);
descriptionHTML += buildEventDescriptionHTML_lots(request, milestone); descriptionHTML += buildEventDescriptionHTML_lots(request, milestone);
@ -286,7 +284,7 @@ export const handler: RequestHandler = (request, response) => {
}); });
if (request.query.workOrderId && workOrderMilestones.length > 0) { if (request.query.workOrderId && workOrderMilestones.length > 0) {
calendar.name("Work Order #" + workOrderMilestones[0].workOrderNumber); calendar.name(`Work Order #${workOrderMilestones[0].workOrderNumber}`);
calendar.url(urlRoot + "/workOrders/" + workOrderMilestones[0].workOrderId); calendar.url(urlRoot + "/workOrders/" + workOrderMilestones[0].workOrderId);
} }