739 lines
26 KiB
JavaScript
739 lines
26 KiB
JavaScript
import { JSONPath as jsonpath } from "jsonpath-plus";
|
|
import { consoleLogger } from "../../../actions/core/logger";
|
|
import { getToken } from "../../../actions/core/token";
|
|
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
|
import { relayGetData } from "../middleware/relayForwarding";
|
|
|
|
const escapeODataString = (value = "") =>
|
|
String(value).replace(/'/g, "''").trim();
|
|
|
|
const normaliseSearchValue = (value = "") => escapeODataString(value);
|
|
|
|
const buildContainsClause = (fieldName, value) => {
|
|
const safeValue = normaliseSearchValue(value);
|
|
if (!safeValue) return null;
|
|
|
|
return `contains(${fieldName}, '${safeValue}')`;
|
|
};
|
|
|
|
const joinFilterClauses = (clauses = []) =>
|
|
clauses.filter(Boolean).join(" and ");
|
|
|
|
const getAddressFields = (logicalCollectionName) => {
|
|
if (
|
|
logicalCollectionName === "pinswg_sipses" ||
|
|
logicalCollectionName === "pinswg_dnses"
|
|
) {
|
|
return {
|
|
line1: "pinswg_projectlocation",
|
|
town: "pinswg_projectlocation",
|
|
county: "pinswg_projectlocation",
|
|
postcode: "pinswg_projectlocation"
|
|
};
|
|
}
|
|
|
|
if (
|
|
logicalCollectionName === "pinswg_ldps" ||
|
|
logicalCollectionName === "pinswg_harbourrevisionorders"
|
|
) {
|
|
return {
|
|
line1: "pinswg_addressline1",
|
|
town: "pinswg_town",
|
|
county: "pinswg_county",
|
|
postcode: "pinswg_postcode"
|
|
};
|
|
}
|
|
|
|
if (
|
|
logicalCollectionName === "pinswg_transportandworkacts" ||
|
|
logicalCollectionName === "pinswg_electricityacts"
|
|
) {
|
|
return {
|
|
line1: "pinswg_addressline1",
|
|
town: "pinswg_addresstown",
|
|
county: "pinswg_addresscounty",
|
|
postcode: "pinswg_postcode"
|
|
};
|
|
}
|
|
|
|
if (logicalCollectionName === "pinswg_rows") {
|
|
return {
|
|
line1: "pinswg_siteaddressline1",
|
|
town: "pinswg_siteaddresstown",
|
|
county: "pinswg_sitecounty",
|
|
postcode: "pinswg_siteaddresspostcode"
|
|
};
|
|
}
|
|
|
|
return {
|
|
line1: "pinswg_siteaddressline1",
|
|
town: "pinswg_siteaddresstown",
|
|
county: "pinswg_siteaddresscounty",
|
|
postcode: "pinswg_siteaddresspostcode"
|
|
};
|
|
};
|
|
|
|
const buildAddressFilter = ({
|
|
logicalCollectionName,
|
|
addressline1,
|
|
town,
|
|
county,
|
|
postcode
|
|
}) => {
|
|
const fields = getAddressFields(logicalCollectionName);
|
|
|
|
return joinFilterClauses([
|
|
buildContainsClause(fields.line1, addressline1),
|
|
buildContainsClause(fields.town, town),
|
|
buildContainsClause(fields.county, county),
|
|
buildContainsClause(fields.postcode, postcode)
|
|
]);
|
|
};
|
|
|
|
const getLocationSelectFields = (logicalCollectionName) => {
|
|
if (
|
|
logicalCollectionName === "pinswg_sipses" ||
|
|
logicalCollectionName === "pinswg_dnses"
|
|
) {
|
|
return ["pinswg_projectlocation"];
|
|
}
|
|
|
|
if (
|
|
logicalCollectionName === "pinswg_ldps" ||
|
|
logicalCollectionName === "pinswg_harbourrevisionorders"
|
|
) {
|
|
return [
|
|
"pinswg_addresstown",
|
|
"pinswg_addressline1",
|
|
"pinswg_addresscounty",
|
|
"pinswg_addressline2",
|
|
"pinswg_addresspostcode"
|
|
];
|
|
}
|
|
|
|
if (
|
|
logicalCollectionName === "pinswg_electricityacts" ||
|
|
logicalCollectionName === "pinswg_transportandworkacts"
|
|
) {
|
|
return [
|
|
"pinswg_addresstown",
|
|
"pinswg_addressline1",
|
|
"pinswg_addresscounty",
|
|
"pinswg_addressline2",
|
|
"pinswg_postcode"
|
|
];
|
|
}
|
|
|
|
if (logicalCollectionName === "pinswg_rows") {
|
|
return [
|
|
"pinswg_siteaddresstown",
|
|
"pinswg_siteaddressline1",
|
|
"pinswg_sitecounty",
|
|
"pinswg_siteaddressline2",
|
|
"pinswg_siteaddresspostcode"
|
|
];
|
|
}
|
|
|
|
return [
|
|
"pinswg_siteaddresstown",
|
|
"pinswg_siteaddressline1",
|
|
"pinswg_siteaddresscounty",
|
|
"pinswg_siteaddressline2",
|
|
"pinswg_siteaddresspostcode"
|
|
];
|
|
};
|
|
|
|
const collectionsWithStartDate = new Set([
|
|
"pinswg_planningappeals78s",
|
|
"pinswg_lawfuldevelopmentcertificates",
|
|
"pinswg_householderappealhases",
|
|
"pinswg_advertses",
|
|
"pinswg_callinss77s",
|
|
"pinswg_commonlands",
|
|
"pinswg_communityinfrastructurelevys117118119s",
|
|
"pinswg_compulsorypurchaseorderses",
|
|
"pinswg_enforcementnoticeappeals174s",
|
|
"pinswg_environmentalpermittings",
|
|
"pinswg_hedgeshedgerowstreepreservationreplacems",
|
|
"pinswg_miscellaneouscaseworks",
|
|
"pinswg_planningconditionss73s79s",
|
|
"pinswg_planningobligationappeals106s",
|
|
"pinswg_rows",
|
|
"pinswg_wayleaves"
|
|
]);
|
|
|
|
const collectionsWithStartDatesPlural = new Set([
|
|
"pinswg_enforcementlistedbuildingconservationaps",
|
|
"pinswg_maintenanceoflands217s"
|
|
]);
|
|
|
|
const collectionsWithValidDate = new Set(["pinswg_nonvalidations"]);
|
|
|
|
const collectionsWithAcceptedAsValid = new Set([
|
|
"pinswg_electricityacts",
|
|
"pinswg_dnses",
|
|
"pinswg_transportandworkacts"
|
|
]);
|
|
|
|
const collectionsWithAssociatedLpa = new Set([
|
|
"pinswg_compulsorypurchaseorderses",
|
|
"pinswg_enforcementnoticeappeals174s",
|
|
"pinswg_planningconditionss73s79s",
|
|
"pinswg_planningobligationappeals106s",
|
|
"pinswg_hedgeshedgerowstreepreservationreplacems",
|
|
"pinswg_householderappealhases",
|
|
"pinswg_lawfuldevelopmentcertificates",
|
|
"pinswg_advertses",
|
|
"pinswg_communityinfrastructurelevys117118119s",
|
|
"pinswg_callinss77s",
|
|
"pinswg_wayleaves",
|
|
"pinswg_environmentalpermittings",
|
|
"pinswg_miscellaneouscaseworks",
|
|
"pinswg_commonlands",
|
|
"pinswg_rows",
|
|
"pinswg_maintenanceoflands217s",
|
|
"pinswg_enforcementlistedbuildingconservationaps",
|
|
"pinswg_dnses",
|
|
"pinswg_sipses"
|
|
]);
|
|
|
|
const getDecisionDateField = (logicalCollectionName) => {
|
|
if (
|
|
logicalCollectionName === "pinswg_dnses" ||
|
|
logicalCollectionName === "pinswg_transportandworkacts"
|
|
) {
|
|
return "pinswg_dateofdecision";
|
|
}
|
|
|
|
if (logicalCollectionName === "pinswg_nonvalidations") {
|
|
return "pinswg_decisionissueddate";
|
|
}
|
|
|
|
if (logicalCollectionName === "pinswg_electricityacts") {
|
|
return "pinswg_datedecision";
|
|
}
|
|
|
|
if (logicalCollectionName === "pinswg_sipses") {
|
|
return null;
|
|
}
|
|
|
|
return "pinswg_casedecisiondate";
|
|
};
|
|
|
|
const getDecisionField = (logicalCollectionName) => {
|
|
if (logicalCollectionName === "pinswg_planningappeals78s") {
|
|
return "pinswg_dicision";
|
|
}
|
|
|
|
if (logicalCollectionName === "pinswg_transportandworkacts") {
|
|
return "pinswg_decsision";
|
|
}
|
|
|
|
if (logicalCollectionName === "pinswg_nonvalidations") {
|
|
return "pinswg_decisionissued";
|
|
}
|
|
|
|
return "pinswg_decision";
|
|
};
|
|
|
|
const getSelectFields = (item) => {
|
|
const fields = ["modifiedon", "_pinswg_appellant_value", "pinswg_name"];
|
|
|
|
if (collectionsWithStartDate.has(item.LogicalCollectionName)) {
|
|
fields.push("pinswg_startdate", "pinswg_finalcommentsduedate");
|
|
}
|
|
|
|
if (collectionsWithStartDatesPlural.has(item.LogicalCollectionName)) {
|
|
fields.push("pinswg_startdates", "pinswg_finalcommentsduedate");
|
|
}
|
|
|
|
if (collectionsWithValidDate.has(item.LogicalCollectionName)) {
|
|
fields.push("pinswg_validdate");
|
|
}
|
|
|
|
if (collectionsWithAcceptedAsValid.has(item.LogicalCollectionName)) {
|
|
fields.push(
|
|
"pinswg_applicationacceptedasvalid",
|
|
"pinswg_endofrepresentationperiod"
|
|
);
|
|
}
|
|
|
|
fields.push(...getLocationSelectFields(item.LogicalCollectionName));
|
|
|
|
const decisionDateField = getDecisionDateField(item.LogicalCollectionName);
|
|
if (decisionDateField) {
|
|
fields.push(decisionDateField);
|
|
}
|
|
|
|
fields.push(getDecisionField(item.LogicalCollectionName));
|
|
|
|
if (
|
|
item.LogicalCollectionName !== "pinswg_nonvalidations" &&
|
|
item.LogicalCollectionName !== "pinswg_sipses"
|
|
) {
|
|
fields.push("pinswg_dateeventrequested");
|
|
}
|
|
|
|
fields.push("statuscode");
|
|
|
|
if (item.LogicalCollectionName !== "pinswg_sipses") {
|
|
fields.push(`_${item.NavigationProperty.toLowerCase()}_value`);
|
|
}
|
|
|
|
if (item.LogicalCollectionName === "pinswg_planningappeals78s") {
|
|
fields.push("_pinswg_localplanningauthority_value");
|
|
}
|
|
|
|
if (collectionsWithAssociatedLpa.has(item.LogicalCollectionName)) {
|
|
fields.push("_pinswg_associatedlpa_value");
|
|
}
|
|
|
|
if (item.LogicalCollectionName === "pinswg_sipses") {
|
|
fields.push("_pinswg_sipscase_value");
|
|
} else {
|
|
fields.push(`_${item.PrimaryIdAttribute}s_value`);
|
|
}
|
|
|
|
return [...new Set(fields)].join(",");
|
|
};
|
|
|
|
const getIncidentIdFromRecord = (item, record) => {
|
|
if (item.value === "SIP") {
|
|
return record._pinswg_sipscase_value || null;
|
|
}
|
|
|
|
return record[`_${item.NavigationProperty.toLowerCase()}_value`] || null;
|
|
};
|
|
|
|
const buildSearchQueryUrl = (item, params) => {
|
|
const addressFilter = buildAddressFilter({
|
|
logicalCollectionName: item.LogicalCollectionName,
|
|
addressline1: params.addressline1,
|
|
town: params.town,
|
|
county: params.county,
|
|
postcode: params.postcode
|
|
});
|
|
|
|
const selectFields = getSelectFields(item);
|
|
|
|
return (
|
|
`${item.LogicalCollectionName}?$count=true` +
|
|
(addressFilter ? `&$filter=${addressFilter}` : "") +
|
|
`&$orderby=createdon desc&$select=${selectFields}`
|
|
);
|
|
};
|
|
|
|
const buildIncidentQueryUrl = (incidentId) =>
|
|
"incidents?" +
|
|
"$select=" +
|
|
[
|
|
"pinswg_environmentalstatementlocation",
|
|
"ticketnumber",
|
|
"pinswg_publishtoweb",
|
|
"modifiedon",
|
|
"description",
|
|
"numberofchildincidents",
|
|
"_accountid_value",
|
|
"_customerid_value",
|
|
"_pinswg_associatedlpa_value",
|
|
"_ownerid_value",
|
|
"pinswg_appealcasetype",
|
|
"statuscode",
|
|
"ticketnumber",
|
|
"title",
|
|
"_primarycontactid_value",
|
|
"pinswg_lpareference",
|
|
"pinswg_appellantagent",
|
|
"pinswg_appellantfirstname",
|
|
"pinswg_appellantlastname"
|
|
].join(",") +
|
|
"&$expand=primarycontactid($select=fullname)" +
|
|
`&$filter=incidentid eq ${incidentId} and pinswg_appealcasetype ne null ` +
|
|
"&$orderby=createdon desc&$count=true";
|
|
|
|
const fetchSearchResultsForAppealType = async (item, token, params) => {
|
|
const queryUrl = buildSearchQueryUrl(item, params);
|
|
|
|
console.log(
|
|
"\n==========================================\n",
|
|
"basic search: " + queryUrl,
|
|
"\n\n",
|
|
item.LogicalCollectionName,
|
|
"\n\n",
|
|
queryUrl,
|
|
"\n==========================================\n"
|
|
);
|
|
|
|
try {
|
|
const { data } = await relayGetData({
|
|
queryUrl,
|
|
accessToken: token.access_token
|
|
});
|
|
|
|
return (data.value || []).map((record) => ({
|
|
...record,
|
|
pinswg_appealType: item.value,
|
|
incidentid: getIncidentIdFromRecord(item, record)
|
|
}));
|
|
} catch (error) {
|
|
consoleLogger(error);
|
|
return [];
|
|
}
|
|
};
|
|
|
|
const fetchIncident = async (incidentId, token) => {
|
|
const queryUrl = buildIncidentQueryUrl(incidentId);
|
|
|
|
try {
|
|
const { data } = await relayGetData({
|
|
queryUrl,
|
|
accessToken: token.access_token
|
|
});
|
|
|
|
return data?.value?.[0] || null;
|
|
} catch (error) {
|
|
consoleLogger(error);
|
|
return null;
|
|
}
|
|
};
|
|
|
|
export default async function ApiProxy(req, res) {
|
|
try {
|
|
const appellantname = req.query.appellantname || "";
|
|
const addressline1 = req.query.addressline1 || "";
|
|
const town = req.query.town || "";
|
|
const county = req.query.county || "";
|
|
const postcode = req.query.postcode || "";
|
|
|
|
const token = await getToken();
|
|
|
|
console.log("whats my params:", req.query);
|
|
|
|
const appealTypeArray = [
|
|
{
|
|
LogicalCollectionName: "pinswg_advertses",
|
|
LogicalName: "pinswg_adverts",
|
|
PrimaryIdAttribute: "pinswg_advertsid",
|
|
UrlName: "adverts",
|
|
MetadataId: "0735866b-5482-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040018",
|
|
NavigationProperty: "pinswg_AdvertsIds",
|
|
value: "Adverts"
|
|
},
|
|
{
|
|
LogicalCollectionName: "pinswg_callinss77s",
|
|
LogicalName: "pinswg_callinss77",
|
|
PrimaryIdAttribute: "pinswg_callinss77id",
|
|
UrlName: "callinss77",
|
|
MetadataId: "dd309e51-4982-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040010",
|
|
NavigationProperty: "pinswg_CallInsS77Ids",
|
|
value: "Called In Applications - S77"
|
|
},
|
|
{
|
|
LogicalCollectionName: "pinswg_commonlands",
|
|
LogicalName: "pinswg_commonland",
|
|
PrimaryIdAttribute: "pinswg_commonlandid",
|
|
UrlName: "commonland",
|
|
MetadataId: "4161a618-5082-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040016",
|
|
NavigationProperty: "pinswg_CommonLandIds",
|
|
value: "Common Land"
|
|
},
|
|
{
|
|
LogicalCollectionName:
|
|
"pinswg_communityinfrastructurelevys117118119s",
|
|
LogicalName: "pinswg_communityinfrastructurelevys117118119",
|
|
PrimaryIdAttribute: "pinswg_communityinfrastructurelevyid",
|
|
UrlName: "communityinfrastructurelevys117118119",
|
|
MetadataId: "0c309f3c-4882-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040009",
|
|
NavigationProperty: "pinswg_CommunityInfrastructureLevyIds",
|
|
value: "Community Infrastructure Levy - S117, 118, & 119"
|
|
},
|
|
{
|
|
LogicalCollectionName: "pinswg_compulsorypurchaseorderses",
|
|
LogicalName: "pinswg_compulsorypurchaseorders",
|
|
PrimaryIdAttribute: "pinswg_compulsorypurchaseordersid",
|
|
UrlName: "compulsorypurchaseorders",
|
|
MetadataId: "054da4c7-5582-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040019",
|
|
NavigationProperty: "pinswg_CompulsoryPurchaseOrdersIds",
|
|
value: "Compulsory Purchase Orders"
|
|
},
|
|
{
|
|
LogicalCollectionName: "pinswg_dnses",
|
|
LogicalName: "pinswg_dns",
|
|
PrimaryIdAttribute: "pinswg_dnsid",
|
|
UrlName: "dns",
|
|
MetadataId: "36f07225-4a82-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040011",
|
|
NavigationProperty: "pinswg_DNSIds",
|
|
value: "Developments of National Significance"
|
|
},
|
|
{
|
|
LogicalCollectionName: "pinswg_electricityacts",
|
|
LogicalName: "pinswg_electricityact",
|
|
PrimaryIdAttribute: "pinswg_electricityactid",
|
|
UrlName: "electricityact",
|
|
MetadataId: "6aedaab1-4a82-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040012",
|
|
NavigationProperty: "pinswg_ElectricityActIds",
|
|
value: "Electricity Act"
|
|
},
|
|
{
|
|
LogicalCollectionName:
|
|
"pinswg_enforcementlistedbuildingconservationaps",
|
|
LogicalName:
|
|
"pinswg_enforcementlistedbuildingandconservationappeals39",
|
|
PrimaryIdAttribute: "pinswg_enforcementlistedbuildingconseid",
|
|
UrlName: "enforcementlistedbuildingconservationap",
|
|
MetadataId: "c697be96-9481-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040006",
|
|
NavigationProperty: "pinswg_EnforcementListedBuildingConseIds",
|
|
value: "Enforcement Listed Building and Conservation Appeal - S39"
|
|
},
|
|
{
|
|
LogicalCollectionName: "pinswg_enforcementnoticeappeals174s",
|
|
LogicalName: "pinswg_enforcementnoticeappeals174",
|
|
PrimaryIdAttribute: "pinswg_enforcementnoticeappeals174id",
|
|
UrlName: "enforcementnoticeappeals174",
|
|
MetadataId: "930a3cc4-9181-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040005",
|
|
NavigationProperty: "pinswg_EnforcementNoticeAppealS174Ids",
|
|
value: "Enforcement Notice Appeal - S174"
|
|
},
|
|
{
|
|
LogicalCollectionName: "pinswg_environmentalpermittings",
|
|
LogicalName: "pinswg_environmentalpermitting",
|
|
PrimaryIdAttribute: "pinswg_enforcementpermittingid",
|
|
UrlName: "environmentalpermitting",
|
|
MetadataId: "62d4aa9a-5682-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040020",
|
|
NavigationProperty: "pinswg_EnforcementPermittingIds",
|
|
value: "Environmental Permitting"
|
|
},
|
|
{
|
|
LogicalCollectionName:
|
|
"pinswg_hedgeshedgerowstreepreservationreplacems",
|
|
LogicalName: "pinswg_hedgeshedgerowstreepreservationreplacem",
|
|
PrimaryIdAttribute: "pinswg_hedgeshedgerowstreepreservatioid",
|
|
UrlName: "hedgeshedgerowstreepreservationreplacem",
|
|
MetadataId: "60f38fed-5382-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040017",
|
|
NavigationProperty: "pinswg_HedgesHedgerowsTreePreservatioIds",
|
|
value: "High Hedges, Tree Preservation orders, Hedgerows, Tree Replacement Notice."
|
|
},
|
|
{
|
|
LogicalCollectionName: "pinswg_householderappealhases",
|
|
LogicalName: "pinswg_householderappealhas",
|
|
PrimaryIdAttribute: "pinswg_householderappealhasid",
|
|
UrlName: "householderappealhas",
|
|
MetadataId: "a6c728b0-9081-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040004",
|
|
NavigationProperty: "pinswg_HouseholderAppealHASIds",
|
|
value: "Householder and Minor Commercial Appeals - HAS/CAS"
|
|
},
|
|
{
|
|
LogicalCollectionName: "pinswg_lawfuldevelopmentcertificates",
|
|
LogicalName: "pinswg_lawfuldevelopmentcertificateappeals194195",
|
|
PrimaryIdAttribute: "pinswg_lawfuldevelopmentcertificatappid",
|
|
UrlName: "lawfuldevelopmentcertificateappeals1941",
|
|
MetadataId: "184e4861-9681-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040008",
|
|
NavigationProperty: "pinswg_LawfulDevelopmentCertificatAppIds",
|
|
value: "Lawful Development Certificate Appeal - S194 + 195"
|
|
},
|
|
{
|
|
LogicalCollectionName: "pinswg_maintenanceoflands217s",
|
|
LogicalName: "pinswg_maintenanceoflands217",
|
|
PrimaryIdAttribute: "pinswg_maintenanceoflands217id",
|
|
UrlName: "maintenanceoflands217",
|
|
MetadataId: "bb302784-9581-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040007",
|
|
NavigationProperty: "pinswg_MaintenanceofLandS217Ids",
|
|
value: "Maintenance of Land - S217"
|
|
},
|
|
{
|
|
LogicalCollectionName: "pinswg_miscellaneouscaseworks",
|
|
LogicalName: "pinswg_misccasework",
|
|
PrimaryIdAttribute: "pinswg_miscellaneouscasewordid",
|
|
UrlName: "miscellaneouscasework",
|
|
MetadataId: "f519aa8e-5782-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040022",
|
|
NavigationProperty: "pinswg_MiscellaneousCasewordIds",
|
|
value: "Miscellaneous Casework"
|
|
},
|
|
{
|
|
LogicalCollectionName: "pinswg_nonvalidations",
|
|
LogicalName: "pinswg_nonvalidation",
|
|
PrimaryIdAttribute: "pinswg_nonvalidationid",
|
|
UrlName: "nonvalidation",
|
|
MetadataId: "37f31a93-5882-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040024",
|
|
NavigationProperty: "pinswg_NonValidationIds",
|
|
value: "Non-Validation"
|
|
},
|
|
{
|
|
LogicalCollectionName: "pinswg_planningappeals78s",
|
|
LogicalName: "pinswg_planningappeals78",
|
|
PrimaryIdAttribute: "pinswg_planningappeals78id",
|
|
UrlName: "planningappeals78",
|
|
MetadataId: "8d7f813a-4183-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040000",
|
|
NavigationProperty: "pinswg_PlanningAppealS78Ids",
|
|
value: "Planning Appeal - S78"
|
|
},
|
|
{
|
|
LogicalCollectionName: "pinswg_planningconditionss73s79s",
|
|
LogicalName: "pinswg_planningconditionss73s79",
|
|
PrimaryIdAttribute: "pinswg_planningconditionss73s79id",
|
|
UrlName: "planningconditionss73s79",
|
|
MetadataId: "093bf9ff-8d81-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040001",
|
|
NavigationProperty: "pinswg_PlanningConditionsS73S79Ids",
|
|
value: "Planning Conditions - S73 + S79"
|
|
},
|
|
{
|
|
LogicalCollectionName: "pinswg_planningobligationappeals106s",
|
|
LogicalName: "pinswg_planningobligationappeals106",
|
|
PrimaryIdAttribute: "pinswg_planningobligationappeals106id",
|
|
UrlName: "planningobligationappeals106",
|
|
MetadataId: "cb8beeae-8f81-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040003",
|
|
NavigationProperty: "pinswg_PlanningObligationAppealS106Ids",
|
|
value: "Planning Obligation Appeal - S106"
|
|
},
|
|
{
|
|
LogicalCollectionName: "pinswg_sipses",
|
|
LogicalName: "pinswg_sips",
|
|
PrimaryIdAttribute: "pinswg_sipscase",
|
|
UrlName: "sips",
|
|
MetadataId: "8d31911b-b8ea-ef11-ab08-00224800be9c",
|
|
appealTypeID: "846040002",
|
|
tmpNav: "pinswg_sipsid",
|
|
NavigationProperty: "pinswg_sipscase",
|
|
value: "SIP"
|
|
},
|
|
{
|
|
LogicalCollectionName: "pinswg_rows",
|
|
LogicalName: "pinswg_row",
|
|
PrimaryIdAttribute: "pinswg_rowid",
|
|
UrlName: "row",
|
|
MetadataId: "4ccc6e93-4f82-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040015",
|
|
NavigationProperty: "pinswg_ROWIds",
|
|
value: "Rights of Way"
|
|
},
|
|
{
|
|
LogicalCollectionName: "pinswg_transportandworkacts",
|
|
LogicalName: "pinswg_transportandworksact",
|
|
PrimaryIdAttribute: "pinswg_transportandworkactid",
|
|
UrlName: "transportandworksact",
|
|
MetadataId: "bc3edc4b-7d82-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040013",
|
|
NavigationProperty: "pinswg_TransportandWorkActIds",
|
|
value: "Transport and Works Act"
|
|
},
|
|
{
|
|
LogicalCollectionName: "pinswg_wayleaves",
|
|
LogicalName: "pinswg_wayleave",
|
|
PrimaryIdAttribute: "pinswg_wayleaveid",
|
|
UrlName: "wayleave",
|
|
MetadataId: "a0652117-5782-eb11-aac0-00224800be9c",
|
|
appealTypeID: "846040021",
|
|
NavigationProperty: "pinswg_WayleaveIds",
|
|
value: "Wayleave"
|
|
}
|
|
];
|
|
|
|
const searchResultsNested = await Promise.all(
|
|
appealTypeArray.map((item) =>
|
|
fetchSearchResultsForAppealType(item, token, {
|
|
addressline1,
|
|
town,
|
|
county,
|
|
postcode
|
|
})
|
|
)
|
|
);
|
|
|
|
let searchResultsObj = searchResultsNested.flat();
|
|
|
|
searchResultsObj = jsonpath({
|
|
path: "$..[?(@ && @.pinswg_name)]",
|
|
json: searchResultsObj,
|
|
eval: true
|
|
});
|
|
|
|
searchResultsObj = searchResultsObj.filter(
|
|
(record) => record.incidentid != null
|
|
);
|
|
|
|
const incidentResults = await Promise.all(
|
|
searchResultsObj.map(async (record) => {
|
|
const incidentObj = await fetchIncident(
|
|
record.incidentid,
|
|
token
|
|
);
|
|
|
|
if (!incidentObj) {
|
|
return {
|
|
...record,
|
|
pinswg_publishtoweb: false,
|
|
ticketnumber: null,
|
|
pinswg_lpareference: null
|
|
};
|
|
}
|
|
|
|
console.log(
|
|
"pinswg_publishtoweb: " + incidentObj.pinswg_publishtoweb,
|
|
"ticketnumber: " + incidentObj.ticketnumber
|
|
);
|
|
|
|
return {
|
|
...record,
|
|
pinswg_publishtoweb: incidentObj.pinswg_publishtoweb,
|
|
ticketnumber: incidentObj.ticketnumber,
|
|
pinswg_lpareference: incidentObj.pinswg_lpareference
|
|
};
|
|
})
|
|
);
|
|
|
|
searchResultsObj = incidentResults;
|
|
|
|
if (Object.prototype.hasOwnProperty.call(req.query, "appellantname")) {
|
|
searchResultsObj = searchResultsObj.filter(
|
|
(record) =>
|
|
record[
|
|
"_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue"
|
|
] !== undefined
|
|
);
|
|
|
|
searchResultsObj = searchResultsObj.filter((record) =>
|
|
record[
|
|
"_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue"
|
|
]
|
|
.toLowerCase()
|
|
.includes(String(appellantname).toLowerCase())
|
|
);
|
|
}
|
|
|
|
searchResultsObj = searchResultsObj.filter(
|
|
(record) => record.pinswg_publishtoweb
|
|
);
|
|
|
|
return respondSuccess(res, {
|
|
"@odata.count": searchResultsObj.length,
|
|
value: searchResultsObj
|
|
});
|
|
} catch (error) {
|
|
consoleLogger(error);
|
|
return respondError(res, {
|
|
status: 500,
|
|
code: "BASIC_SEARCH_BY_ADDRESS_FETCH_FAILED",
|
|
message: "Failed to retrieve search results"
|
|
});
|
|
}
|
|
}
|