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

feat: verificationBody is now not required for issuances #1148

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/models/governance/governance.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class Governance extends Model {

if (!governanceBodyId) {
throw new Error(
'There is no Goverance Body that you own that can be edited',
'There is no Governance Body that you own that can be edited',
);
}

Expand Down
6 changes: 6 additions & 0 deletions src/models/staging/staging.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
createXlsFromSequelizeResults,
transformFullXslsToChangeList,
} from '../../utils/xls';
import { updateNilVerificationBodyAsEmptyString } from '../../utils/helpers.js';

class Staging extends Model {
static changes = new rxjs.Subject();
Expand Down Expand Up @@ -488,6 +489,11 @@ class Staging extends Model {
throw new Error('No records to send to DataLayer');
}

// replace nil issuance validationBody values with empty strings
stagedRecords.forEach((record) =>
updateNilVerificationBodyAsEmptyString(record),
);

const [unitsChangeList, projectsChangeList] = await Promise.all([
Unit.generateChangeListFromStagedData(stagedRecords, comment, author),
Project.generateChangeListFromStagedData(stagedRecords, comment, author),
Expand Down
29 changes: 29 additions & 0 deletions src/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,32 @@ export const getDataModelVersion = () => {
const majorVersion = version.split('.')[0];
return `v${majorVersion}`;
};

/**
* the issuance table does not allow the verificationBody to be null. by requirement this field is nullable.
* this function defines null or undefined verificationBody for all issuances that exist in a staged record
* @param stagedItem from the staging table
*/
export const updateNilVerificationBodyAsEmptyString = (stagedItem) => {
try {
if (stagedItem?.data) {
const data = JSON.parse(stagedItem.data);
data?.forEach((changeRecord) => {
if (stagedItem?.table === 'Projects') {
changeRecord?.issuances?.forEach((issuance) => {
if (!issuance?.verificationBody) {
issuance.verificationBody = '';
}
});
} else if (stagedItem?.table === 'Units') {
if (data?.issuance && !data.issuance?.verificationBody) {
data.issuance.verificationBody = '';
}
}
});
stagedItem.data = JSON.stringify(data);
}
} catch {
return;
}
};
2 changes: 1 addition & 1 deletion src/validations/governance.validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const governancePickListSchema = Joi.object().keys({
ratingType: Joi.array().items(Joi.string()).min(1).required(),
unitType: Joi.array().items(Joi.string()).min(1).required(),
unitStatus: Joi.array().items(Joi.string()).min(1).required(),
verificationBody: Joi.array().items(Joi.string()).min(1).required(),
verificationBody: Joi.array().items(Joi.string()).min(1).optional(),
projectTags: Joi.array().items(Joi.string()).min(1).required(),
unitTags: Joi.array().items(Joi.string()).min(1).required(),
coBenefits: Joi.array().items(Joi.string()).min(1).required(),
Expand Down
2 changes: 1 addition & 1 deletion src/validations/issuances.validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const issuanceSchema = Joi.object({
startDate: Joi.date().required(),
endDate: Joi.date().min(Joi.ref('startDate')).required(),
verificationApproach: Joi.string().required(),
verificationBody: Joi.string().required(),
verificationBody: Joi.string().allow('').optional(),
verificationReportDate: Joi.date().required(),
timeStaged: Joi.date().timestamp().allow(null).optional(),
updatedAt: Joi.date().allow(null).optional(),
Expand Down
Loading