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

NRPT-798 Impoort COORS Ticket as Court Conviction #898

Merged
merged 2 commits into from
Aug 12, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions api/src/importers/coors/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,33 @@ class CoorsCsvDataSource {
let batchSize = process.env.CSV_IMPORT_BATCH_SIZE || 100;

const recordTypeConfig = this.getRecordTypeConfig();
const courtConvictionTypeConfig = {
getUtil: (auth_payload, csvRow) => {
return new (require('./court-conviction-utils'))(auth_payload, RECORD_TYPE.CourtConviction, csvRow);
}
};

if (!recordTypeConfig) {
throw Error('batchProcessRecords - failed to find matching recordTypeConfig.');
}

let promises = [];
for (let i = 0; i < this.csvRows.length; i++) {
const csvRow = this.csvRows[i];

// process Convictions serially so penalties can be appended to existing records propely
if (this.recordType === 'Court Conviction') {
await this.processRecord(this.csvRows[i], recordTypeConfig)
//
// Rows with enforcemnt_outcome === 'GTYJ' should be treated as Court Conviction regardless
// of the selected import type. This is due to limitation on COORS export query.
// https://bcmines.atlassian.net/browse/NRPT-798
if (
this.recordType === 'Court Conviction' ||
(csvRow['enforcement_outcome'] && csvRow['enforcement_outcome'] === 'GTYJ')
) {
await this.processRecord(csvRow, courtConvictionTypeConfig);
} else {
// batch process
promises.push(this.processRecord(this.csvRows[i], recordTypeConfig));
promises.push(this.processRecord(csvRow, recordTypeConfig));
if (i % batchSize === 0 || i === this.csvRows.length - 1) {
await Promise.all(promises);
promises = [];
Expand Down Expand Up @@ -106,7 +120,7 @@ class CoorsCsvDataSource {

// Record will be null if row has business_reviewed = N, skip processing it
if (!nrptiRecord) {
defaultLog.debug('skipped record processing, not reviewed by business')
defaultLog.debug('skipped record processing, not reviewed by business');
return Promise.resolve();
}
// Check if this record already exists
Expand Down