Skip to content

Commit

Permalink
Merge pull request #1148 from Chia-Network/verification-body-not-req
Browse files Browse the repository at this point in the history
feat: verificationBody is now not required for issuances
  • Loading branch information
TheLastCicada authored Aug 5, 2024
2 parents 173e560 + 5e614b0 commit b31242c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
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

0 comments on commit b31242c

Please sign in to comment.