diff --git a/src/models/governance/governance.model.js b/src/models/governance/governance.model.js index e70cabd8..76dc9124 100644 --- a/src/models/governance/governance.model.js +++ b/src/models/governance/governance.model.js @@ -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', ); } diff --git a/src/models/staging/staging.model.js b/src/models/staging/staging.model.js index 5b0af3e4..bc02d041 100644 --- a/src/models/staging/staging.model.js +++ b/src/models/staging/staging.model.js @@ -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(); @@ -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), diff --git a/src/utils/helpers.js b/src/utils/helpers.js index 3d2cef5e..e5d2dd73 100644 --- a/src/utils/helpers.js +++ b/src/utils/helpers.js @@ -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; + } +}; diff --git a/src/validations/governance.validations.js b/src/validations/governance.validations.js index 1dc7d285..9600f514 100644 --- a/src/validations/governance.validations.js +++ b/src/validations/governance.validations.js @@ -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(), diff --git a/src/validations/issuances.validation.js b/src/validations/issuances.validation.js index 1c28d4c5..8c5f2d27 100644 --- a/src/validations/issuances.validation.js +++ b/src/validations/issuances.validation.js @@ -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(),