Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NRPTI-1045] - WIP - Update agency name in NRPTI #1114

Merged
merged 55 commits into from
Oct 3, 2023

Conversation

davidclaveau
Copy link
Contributor

@davidclaveau davidclaveau commented Sep 25, 2023

Pull Request Standards

  • The title of the PR is accurate
  • The title includes the type of change [HOTFIX, FEATURE, etc]
  • The PR title includes the ticket number in format of [NRPTI-###]
  • Documentation is updated to reflect change

Description

This PR includes the following proposed change(s):

  • Allow the user to update an agency's name from the NRPTI admin
  • Add a migration to add several documents with "_schemaName": "applicationAgency" in the database
    • e.g.
    {
     "_id": {
       "$oid": "1234a1234abc1234cd44d4c04c5c"
    },
     "_schemaName": "ApplicationAgency",
     "agencyCode": "AGENCY_ALC",
     "agencyName": "Agricultural Land Commission",
     "read": [
       "sysadmin"
     ],
     "write": [
       "sysadmin"
     ],
     "dateAdded": {
       "$date": "2023-09-12T19:10:05.233Z"
     },
     "dateUpdated": "",
     "addedBy": "",
     "updatedBy": "" 
    }
    
  • Add migrations to update existing issuingAgencies in the database to their newly added agencyCode
  • Add functionality to retrieve and show the correct agencyName corresponding to the agencyCode for a document that's pulled from the database
    • Use a Factory service to retrieve the agencies from the database and reference a cache of the codes and names
  • Create a UI for users to rename agency codes in the database

davidclaveau and others added 30 commits September 11, 2023 13:53
…update values from that list with value from a text box.
…e the object which will be sent to the api for updating the agencyList. Also worth noting the alerts are being used here for console debugging. My local settings are preventing logging, when I find the reason I will update readme to document process
@sanjaytkbabu sanjaytkbabu marked this pull request as ready for review October 3, 2023 15:16
Copy link
Contributor

@LocalNewsTV LocalNewsTV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can reduce crlf issues by enabling this setting in VSC

image

api/src/models/master/applicationAgency.js Outdated Show resolved Hide resolved
api/src/swagger/swagger.yaml Outdated Show resolved Hide resolved
Comment on lines +5 to +47

@Injectable()
export class ApplicationAgencyService {
private api: string;
private agencies: { [key: string]: string } = {};

constructor(private configService: ConfigService, public http: HttpClient) {}

async init() {
this.api = `${this.configService.config['API_LOCATION']}${this.configService.config['API_PATH']}`;
await this.refreshAgencies().toPromise();
}

refreshAgencies(): Observable<void> {
return new Observable<void>(observer => {
const apiEndpoint = `${this.api}/list-agencies`;
const getAgencies = this.http.get<{ [key: string]: string }>(apiEndpoint);

getAgencies.subscribe(
response => {
// Data transformation to make the data easier to work with
const agencyList = {};
for (const record in response) {
if (response.hasOwnProperty(record)) {
agencyList[response[record]['agencyCode']] = response[record]['agencyName'];
}
}
this.agencies = agencyList;
observer.next();
observer.complete();
},
error => {
console.error('HTTP Request Error: ', error);
observer.error(error);
}
);
});
}

getAgencies(): { [key: string]: string } {
return this.agencies;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be some documentation to help with future maintenance of the repo

Comment on lines 6 to 48
@Injectable({ providedIn: 'root' })
export class IssuingAgencyService {
constructor(public apiService: ApiService, public http: HttpClient) {}

public getIssuingAgencies(): Promise<any> {
return this.http
.get<any>(`${this.apiService.pathAPI}/list-agencies`)
.toPromise()
.catch(error => {
console.error('API call error:', error);
throw error; // Rethrow the error to propagate it further
});
}

public updateAgency(agencyCode: string, agencyName: any): Promise<any> {
const apiUrl = `${this.apiService.pathAPI}/update-agencies`;
const updatedAgency = { agencies: [{ agencyCode: agencyCode, agencyName: agencyName }] }; // Wrap the array in an object
console.log(JSON.stringify(updatedAgency));
return this.http
.put<any>(apiUrl, updatedAgency)
.toPromise()
.catch(error => {
console.error('API call error:', error);
throw error; // Rethrow the error to propagate it further
});
}

public async getIssuingAgencyMap() {
try {
const response = await this.getIssuingAgencies();
const issuingAgencyMap: { [key: string]: string } = {};
if (response && Array.isArray(response)) {
response.forEach(agency => {
issuingAgencyMap[agency.agencyCode] = agency.agencyName;
});
}
return issuingAgencyMap;
} catch (error) {
console.error('getIssuingAgencyMap() API call error:', error);
throw error;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be some documentation to help with future maintenance of the repo

Comment on lines 2 to 83
const ApplicationAgency = require('../src/models/master/applicationAgency');
const mongoose = require('mongoose');

var dbm;
var type;
var seed;

exports.setup = function(options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
};

exports.up = async function (db) {
console.log('**** Adding ApplicationAgencies constants to nrpti collection ****');

// Connect to the database
const mClient = await db.connection.connect(db.connectionString, {
native_parser: true,
});

const agencies = [
{ agencyCode: "AGENCY_ALC", agencyName: 'Agricultural Land Commission' },
{ agencyCode: "AGENCY_WF", agencyName: 'BC Wildfire Service' },
{ agencyCode: "AGENCY_ENV_COS", agencyName: 'Conservation Officer Service' },
{ agencyCode: "AGENCY_EAO", agencyName: 'Environmental Assessment Office' },
{ agencyCode: "AGENCY_EMLI", agencyName: 'Ministry of Energy Mines and Low Carbon Innovation' },
{ agencyCode: "AGENCY_ENV", agencyName: 'Ministry of Environment and Climate Change Strategy' },
{ agencyCode: "AGENCY_ENV_BCPARKS", agencyName: 'BC Parks' },
{ agencyCode: "AGENCY_OGC", agencyName: 'BC Energy Regulator' },
{ agencyCode: "AGENCY_ENV_EPD", agencyName: 'Ministry of Environment and Climate Change Strategy' },
{ agencyCode: "AGENCY_LNG", agencyName: 'LNG Secretariat' },
{ agencyCode: "AGENCY_AGRI", agencyName: 'Ministry of Agriculture and Food' },
{ agencyCode: "AGENCY_FLNRO", agencyName: 'Ministry of Forests' },
{ agencyCode: "AGENCY_FLNR_NRO", agencyName: 'Natural Resource Officers' },
{ agencyCode: "AGENCY_WLRS", agencyName: 'Ministry of Water, Land and Resource Stewardship' },
{ agencyCode: "AGENCY_CAS", agencyName: 'Climate Action Secretariat' },
]

try {
let currentCollection = await mClient.collection('nrpti');

for (const agency of agencies) {
const existingAgency = await currentCollection.findOne({ _schemaName: 'ApplicationAgency', agencyCode: agency['agencyCode'] });

if (!existingAgency) {
await currentCollection.insertOne(
{
_schemaName: 'ApplicationAgency',
agencyCode: agency['agencyCode'],
agencyName: agency['agencyName'],
read: ['sysadmin'],
write: ['sysadmin'],
dateAdded: new Date(),
dateUpdated: null,
addedBy: '',
updatedBy: '',
}
);
console.log(` **** Add the ApplicationAgency code ${agency['agencyCode']} into nrpti collection ****`);
} else {
console.log(' **** ApplicationAgency code already exists in nrpti collection ****')
}
}
} catch (err) {
console.log(` **** Error updating nrpti collection for agency: ${agency['agencyName']} ****`, err);
} finally {
if (mClient) {
console.log(' **** Closing connection to nrpti collection ****')
await mClient.close();
}
}

return null;
};

exports.down = function(db) {
return null;
};

exports._meta = {
"version": 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be some documentation to help with future maintenance of the repo

Comment on lines 1 to 24
'use strict';

var dbm;
var seed;

/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function (options, seedLink) {
dbm = options.dbmigrate;
seed = seedLink;
};

exports.up = async function (db) {
const mClient = await db.connection.connect(db.connectionString, {
native_parser: true,
});

const LegislationActs = {
ACT_Env_Management: 'Environmental Management Act',
ACT_Int_Pest_Management: 'Integrated Pest Management Act',
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be some documentation to help with future maintenance of the repo

Comment on lines 1 to 15
const queryActions = require('../utils/query-actions');
const mongodb = require('../utils/mongodb');
const RECORD_TYPE = require('../utils/constants/record-type-enum');
const defaultLog = require('../utils/logger')('record');

exports.publicGet = async function(args, res, next) {
const db = mongodb.connection.db(process.env.MONGODB_DATABASE || 'nrpti-dev');
const collectionDB = db.collection('nrpti');

let agencyList;

try {
//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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be some documentation to help with future maintenance of the repo

sanjaytkbabu and others added 3 commits October 3, 2023 10:35
Co-authored-by: Matthew Logan <62873746+LocalNewsTV@users.noreply.github.com>
crlf

Co-authored-by: Matthew Logan <62873746+LocalNewsTV@users.noreply.github.com>
crlf

Co-authored-by: Matthew Logan <62873746+LocalNewsTV@users.noreply.github.com>
@sonarcloud
Copy link

sonarcloud bot commented Oct 3, 2023

Please retry analysis of this Pull-Request directly on SonarCloud.

@LocalNewsTV LocalNewsTV self-requested a review October 3, 2023 17:53
@sonarcloud
Copy link

sonarcloud bot commented Oct 3, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 18 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@sanjaytkbabu sanjaytkbabu merged commit 9bd2658 into master Oct 3, 2023
5 checks passed
@sanjaytkbabu sanjaytkbabu deleted the feature/1045-issuing-agency-update branch October 3, 2023 21:33
@sanjaytkbabu sanjaytkbabu restored the feature/1045-issuing-agency-update branch October 3, 2023 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants