Skip to content

Commit

Permalink
Update permits if permissions don't match collection
Browse files Browse the repository at this point in the history
  • Loading branch information
sggerard committed Jul 10, 2024
1 parent 561d90a commit 470cf0a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class MinesCollectionsListResolver implements Resolve<Observable<object>>
}

if (params.bcmiTabType.includes('Authorizations')) {
or['type'] += 'Permit,Permit Amendment,Certificate,Certificate Amendment';
or['type'] += 'Amalgamated Permit,Permit,Permit Amendment,Certificate,Certificate Amendment';
}

if (params.bcmiTabType.includes('Compliance Oversight')) {
Expand Down
2 changes: 1 addition & 1 deletion api/src/controllers/metric.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ exports.protectedGetData = async function (args, res, next) {
// Future: Set read/write roles on metric, guard against execution at this point.
const metric = await Metric.findOne(query);

if (!metric.operation) {
if (!metric || !metric.operation) {
return QueryActions.sendResponse(res, 400, {});
}

Expand Down
31 changes: 18 additions & 13 deletions api/src/integrations/core/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,16 @@ class CoreDataSource {
throw Error('processRecord - permitInfo is null.');
}

// Create a new collections if possible.
if (savedRecord._schemaName === 'MineBCMI') {
await this.createorUpdateCollections(collectionUtils, permitUtils, permitInfo.validPermit, savedRecord);
} else {
if (!savedRecord.length > 0 || savedRecord[0].status !== 'success') {
throw Error('processRecord - savedRecord is null.');
for (let permit of permitInfo.permits){
// Create a new collections if possible.
if (savedRecord._schemaName === 'MineBCMI') {
await this.createorUpdateCollections(collectionUtils, permitUtils, permit, savedRecord);
} else {
if (!savedRecord.length > 0 || savedRecord[0].status !== 'success') {
throw Error('processRecord - savedRecord is null.');
}
await this.createorUpdateCollections(collectionUtils, permitUtils, permit, savedRecord[0].object[0]);
}
await this.createorUpdateCollections(collectionUtils, permitUtils, permitInfo.validPermit, savedRecord[0].object[0]);
}

this.status.itemsProcessed++;
Expand Down Expand Up @@ -374,7 +376,8 @@ class CoreDataSource {
return {
permitNumber: validPermit.permit_no,
permittee: validPermit.current_permittee,
validPermit
validPermit,
permits
};
}

Expand Down Expand Up @@ -446,7 +449,8 @@ class CoreDataSource {
return {
permitNumber: validPermit.permit_no,
permittee: validPermit.current_permittee,
validPermit
validPermit,
permits
};
}

Expand Down Expand Up @@ -580,12 +584,13 @@ class CoreDataSource {

await collectionUtils.createItem(collection);
} else {
// NRPT-549 Update the collection if name, date and number of permits have changed
// NRPT-549 Update the collection if name, date, number of permits have changed or permissions don't match
if (
existingCollection.name !== amendment.description ||
Date.parse(existingCollection.date) !== Date.parse(amendment.issue_date) ||
(amendment.description != null && existingCollection.name !== amendment.description) ||
(amendment.issue_date != null && Date.parse(existingCollection.date) !== Date.parse(amendment.issue_date)) ||
existingCollection.records.length != existingPermits.length ||
existingCollection.type != permitUtils.getPermitType(amendment.permit_amendment_type_code)
existingCollection.type != permitUtils.getPermitType(amendment.permit_amendment_type_code) ||
existingPermits.some( p => p.read.includes('public') !== existingCollection.read.includes('public'))
) {
const updateCollection = {
_sourceRefCoreCollectionId: amendment.permit_amendment_guid,
Expand Down

0 comments on commit 470cf0a

Please sign in to comment.