1239 describes a bug where Administrative Penalty records were being improperly redacted. The check to see if the issuing agency was one that was allowed to publish non-redacted records was faulty. It was often comparing the actual agency name to a list of agency codes. A function to get the agencyCode from the name was created. As it needed to look up values from the db, it was created as an async function. This created its own complications as it required many of the upstream functions to also be converted to async. Ultimately, the original refactoring effort was unsuccessful. While the records were no longer being improperly redacted, an error was being generated that made it so the record could not be saved. This error was not able to be addressed in a timely manner, so a bandaid fix was implemented. A synchronous version of the function was created that used hardcoded values instead of db lookup.
Purpose
The entire reason for agencyCodes is that sometimes agency names change or new agencies can be added. The bandaid function will eventually become out of date and some records will be improperly redacted.
Acceptance Criteria
[ ] In the business-logic-manager, the check for if the issuingAgency is one with authority to publish names needs to be able to get also check the associated agencyCode.
[ ] this must involve a call to the database as this is where up-to-date values are stored.
Additional context
Below is the original async version of the getAgencyCodeFromName function. This can be used as a reference or implemented in its entirety if the upstream async/await issues can be resolved
/**
* Provides the agencyCode (an intermediate value) that is mapped to the given agency name
* Eg: 'Agricultural Land Commission' should return 'AGENCY_ALC'
* @param {string} agencyName - the name of an agency that provides records to NRPTI.
* @returns {string} agencyCode - the intermediate code that maps to the agencyName
*/
exports.getAgencyCodeFromName = async function(agencyName) {
const db = mongodb.connection.db(process.env.MONGODB_DATABASE || 'nrpti-dev');
const collectionDB = db.collection('nrpti');
try {
let agencyList;
// Obtain documents with Application Agency Schema
let agencyDocuments = await collectionDB.find({ _schemaName: RECORD_TYPE.ApplicationAgency._schemaName }).toArray();
// Using map function to iterate through the original array and creates
// a new array with objects containing only the _id, agencyCode, and agencyName properties.
agencyList = await agencyDocuments.map(item => ({
agencyCode: item.agencyCode,
agencyName: item.agencyName
}));
for (const agency of agencyList) {
if (agency.agencyName == agencyName) {
return agency.agencyCode;
}
}
throw new Error(`no agency code found for ${agencyName}`);
} catch (error) {
defaultLog.info(`getAgencyCodeFromName - agencies controller - error getting agencyCode for ${agencyName}`);
defaultLog.debug(error);
return agencyName;
}
};
Describe the task
1239 describes a bug where Administrative Penalty records were being improperly redacted. The check to see if the issuing agency was one that was allowed to publish non-redacted records was faulty. It was often comparing the actual agency name to a list of agency codes. A function to get the agencyCode from the name was created. As it needed to look up values from the db, it was created as an async function. This created its own complications as it required many of the upstream functions to also be converted to async. Ultimately, the original refactoring effort was unsuccessful. While the records were no longer being improperly redacted, an error was being generated that made it so the record could not be saved. This error was not able to be addressed in a timely manner, so a bandaid fix was implemented. A synchronous version of the function was created that used hardcoded values instead of db lookup.
Purpose The entire reason for agencyCodes is that sometimes agency names change or new agencies can be added. The bandaid function will eventually become out of date and some records will be improperly redacted.
Acceptance Criteria
Additional context
Below is the original async version of the getAgencyCodeFromName function. This can be used as a reference or implemented in its entirety if the upstream async/await issues can be resolved