Skip to content

Commit

Permalink
Replace date with env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
sggerard committed Jun 14, 2024
1 parent 8145d13 commit 83d9762
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
4 changes: 4 additions & 0 deletions api/src/integrations/integration-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ exports.getRecords = async function(url, options = undefined) {
}
};

try{
const res = await axios.post(CORE_TOKEN_ENDPOINT, QS.stringify(requestBody), config);
} catch (excception ){
console.log(excception);
}

const payload = res.data ? res.data : null;

Expand Down
11 changes: 6 additions & 5 deletions api/src/integrations/nris-emli/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const NRIS_EMLI_API_ENDPOINT =
process.env.NRIS_EMLI_API_ENDPOINT || 'https://api.nrs.gov.bc.ca/nrisws-api/v1/emprInspections';
const NRIS_username = process.env.NRIS_username || null;
const NRIS_password = process.env.NRIS_password || null;
const NRIS_ATTACHMENT_DATE = process.env.NRIS_ATTACHMENT_DATE || '2024-06-01';
const RETRY_LIMIT = 10;

class NrisDataSource {
Expand Down Expand Up @@ -163,7 +164,7 @@ class NrisDataSource {
const existingRecord = await this.findExistingRecord(newRecord);

if (existingRecord) {
if (newRecord.documents.length === 0) { //TODO is this wrong?? Should be 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 (NRIS_EMLI_DOCUMENT_BINARIES_ENABLED === 'true') {
await this.createRecordAttachments(records[i], newRecord);
Expand Down Expand Up @@ -311,13 +312,13 @@ class NrisDataSource {

isAttachmentAllowed(attachment){
//Allow final reports
if(attachment.fileType === 'Final Report'){
if (attachment.fileType === 'Final Report') {
return true;
}
//Allow inspection reports if they were created after June 1st
if(attachment.fileType === 'Report'){
//Allow inspection reports if they were created after a specific date (June 1st)
if (attachment.fileType === 'Report') {
return attachment.attachmentComment.toLowerCase() === "inspection report"
&& attachment.attachmentDate != null && moment(attachment.attachmentDate).isAfter("2024-06-01");
&& attachment.attachmentDate != null && moment(attachment.attachmentDate).isAfter(NRIS_ATTACHMENT_DATE);
}
return false;
}
Expand Down
1 change: 1 addition & 0 deletions api/src/integrations/nris-emli/datasource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ describe('NrisDataSource', () => {
{ attachmentId: 'attachmentId1', fileType: 'Other' },
{ attachmentId: 'attachmentId2', fileType: 'Final Report' },
{ attachmentId: 'attachmentId3', fileType: 'Report', attachmentComment: 'Inspection Report'},
{ attachmentId: 'attachmentId3', fileType: 'Report', attachmentComment: 'Inspection Report', attachmentDate: "2020-01-10 11:50"},
{ attachmentId: 'attachmentId4', fileType: 'Report', attachmentComment: 'Inspection Report', attachmentDate: "2024-06-06" },
],
};
Expand Down
1 change: 1 addition & 0 deletions api/test/setEnvVars.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
process.env.NRIS_EMLI_DOCUMENT_BINARIES_ENABLED = 'true';
process.env.NRIS_username = 'test';
process.env.NRIS_password = 'test';
process.env.NRIS_ATTACHMENT_DATE = '2024-06-01';

0 comments on commit 83d9762

Please sign in to comment.