From 31f7cf96892187a3ab2d3b1618a626785f0b5ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mark=20Lis=C3=A9?= Date: Tue, 11 May 2021 16:52:42 -0700 Subject: [PATCH] NRPT-707: Disable document handling for NRIS-EMLI (#852) --- api/src/integrations/nris-emli/datasource.js | 32 +++++++------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/api/src/integrations/nris-emli/datasource.js b/api/src/integrations/nris-emli/datasource.js index c790a89b8..eb8104c23 100644 --- a/api/src/integrations/nris-emli/datasource.js +++ b/api/src/integrations/nris-emli/datasource.js @@ -12,7 +12,7 @@ const BusinessLogicManager = require('../../utils/business-logic-manager'); const utils = require('../../utils/constants/misc'); const fs = require('fs'); - +const NRIS_EMLI_DOCUMENT_BINARIES_ENABLED = process.env.NRIS_EMLI_DOCUMENT_BINARIES_ENABLED || false; const NRIS_TOKEN_ENDPOINT = process.env.NRIS_TOKEN_ENDPOINT || 'https://api.nrs.gov.bc.ca/oauth2/v1/oauth/token?disableDeveloperFilter=true&grant_type=client_credentials&scope=NRISWS.*'; @@ -150,14 +150,14 @@ class NrisDataSource { if (existingRecord) { if (newRecord.documents.length === 0) { // create attachment if no existing document was found, if no "Final Report" is attached no document will be created - if (this.shouldRecordHaveAttachments(newRecord)) { + if (NRIS_EMLI_DOCUMENT_BINARIES_ENABLED === true) { await this.createRecordAttachments(records[i], newRecord); } } await this.updateRecord(newRecord, existingRecord); } else { - if (this.shouldRecordHaveAttachments(newRecord)) { + if (NRIS_EMLI_DOCUMENT_BINARIES_ENABLED === true) { await this.createRecordAttachments(records[i], newRecord); } await this.createItem(newRecord); @@ -214,12 +214,14 @@ class NrisDataSource { newRecord.sourceSystemRef = 'nris-emli'; - // check if document exists already in the system but is orphaned - for (let i = 0; i < record.attachment.length; i++) { - if (record.attachment[i].fileType === 'Final Report') { - const existingDocument = await this.findExistingDocument(record.attachment[i].filePath); - if (existingDocument && existingDocument._id && !newRecord.documents.includes(existingDocument._id)) { - newRecord.documents.push(existingDocument._id); + if (NRIS_EMLI_DOCUMENT_BINARIES_ENABLED === true) { + // check if document exists already in the system but is orphaned + for (let i = 0; i < record.attachment.length; i++) { + if (record.attachment[i].fileType === 'Final Report') { + const existingDocument = await this.findExistingDocument(record.attachment[i].filePath); + if (existingDocument && existingDocument._id && !newRecord.documents.includes(existingDocument._id)) { + newRecord.documents.push(existingDocument._id); + } } } } @@ -449,18 +451,6 @@ class NrisDataSource { defaultLog.error(`Failed to save ${RECORD_TYPE.Inspection._schemaName} record: ${error.message}`); } } - - shouldRecordHaveAttachments(record) { - if ( - record && - record.legislation && - record.legislation.act === 'Greenhouse Gas Industrial Reporting and Control Act' - ) { - return false; - } - - return true; - } } module.exports = NrisDataSource;