-
Notifications
You must be signed in to change notification settings - Fork 14
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
Conversation
…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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
@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; | ||
} | ||
} |
There was a problem hiding this comment.
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
@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; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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
'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', | ||
}; | ||
|
There was a problem hiding this comment.
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
api/src/controllers/agencies.js
Outdated
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. |
There was a problem hiding this comment.
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
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>
Please retry analysis of this Pull-Request directly on SonarCloud. |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Pull Request Standards
HOTFIX
,FEATURE
,etc
][NRPTI-###]
Description
This PR includes the following proposed change(s):
"_schemaName": "applicationAgency"
in the databaseissuingAgencies
in the database to their newly addedagencyCode
agencyName
corresponding to theagencyCode
for a document that's pulled from the database