Skip to content

Commit

Permalink
fix: validation logic to support xls
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed May 30, 2023
1 parent 0ef36dd commit 595cc9b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/validations/issuances.validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import Joi from 'joi';

export const issuanceSchema = Joi.object({
// orgUid - derived upon creation
id: Joi.string().optional(),
warehouseProjectId: Joi.string().optional(),
id: Joi.string().allow(null).optional(),
warehouseProjectId: Joi.string().allow(null).optional(),
startDate: Joi.date().required(),
endDate: Joi.date().min(Joi.ref('startDate')).required(),
verificationApproach: Joi.string().required(),
verificationBody: Joi.string().required(),
verificationReportDate: Joi.date().required(),
timeStaged: Joi.date().timestamp().allow(null).optional(),
updatedAt: Joi.date().optional(),
createdAt: Joi.date().optional(),
updatedAt: Joi.date().allow(null).optional(),
createdAt: Joi.date().allow(null).optional(),
});
8 changes: 4 additions & 4 deletions src/validations/projects.validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const baseSchema = {
// warehouseProjectId - derived upon creation
// orgUid - derived upon creation
projectId: Joi.alternatives().try(Joi.string(), Joi.number()).required(),
currentRegistry: Joi.string().optional(),
currentRegistry: Joi.string().allow(null).optional(),
originProjectId: Joi.alternatives()
.try(Joi.string(), Joi.number())
.required(),
Expand All @@ -42,7 +42,7 @@ export const baseSchema = {
projectStatusDate: Joi.date().required(),
unitMetric: Joi.string().custom(pickListValidation('unitMetric')).required(),
methodology: Joi.string().required(),
methodology2: Joi.string().optional(),
methodology2: Joi.string().allow(null).optional(),
validationBody: Joi.string().allow(null).optional(),
validationDate: Joi.date().allow(null).optional(),
description: Joi.string().allow(null).optional(),
Expand All @@ -55,8 +55,8 @@ export const baseSchema = {
projectLocations: Joi.array().items(locationSchema).min(1).optional(),
projectRatings: Joi.array().items(ratingSchema).min(1).optional(),
estimations: Joi.array().items(estimationSchema).min(1).optional(),
updatedAt: Joi.date().optional(),
createdAt: Joi.date().optional(),
updatedAt: Joi.date().allow(null).optional(),
createdAt: Joi.date().allow(null).optional(),
timeStaged: Joi.date().timestamp().allow(null).optional(),
};

Expand Down
17 changes: 9 additions & 8 deletions src/validations/units.validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,27 @@ const unitsBaseSchema = {
// warehouseUnitId - derived upon unit creation
// issuanceId - derived upon unit creation
// orgUid - derived upon unit creation
projectLocationId: Joi.string().optional(),
unitOwner: Joi.string(),
projectLocationId: Joi.string().allow(null).optional(),
unitOwner: Joi.string().allow(null).optional(),
countryJurisdictionOfOwner: Joi.string()
.custom(pickListValidation('countries', 'countryJurisdictionOfOwner'))
.required(),
inCountryJurisdictionOfOwner: Joi.string().optional(),
inCountryJurisdictionOfOwner: Joi.string().allow(null).optional(),
unitBlockStart: Joi.string().required(),
unitBlockEnd: Joi.string().required(),
unitCount: Joi.number().integer().required(),
// match 4 digit year
vintageYear: Joi.number().integer().min(1900).max(3000).required(),
unitType: Joi.string().custom(pickListValidation('unitType')).required(),
marketplace: Joi.string().optional(),
marketplaceLink: Joi.string().optional(),
marketplace: Joi.string().allow(null).optional(),
marketplaceLink: Joi.string().allow(null).optional(),
marketplaceIdentifier: Joi.string().disallow('').allow(null).optional(),
unitTags: Joi.string().allow('').optional(),
unitTags: Joi.string().allow('').allow(null).optional(),
unitStatus: Joi.string().custom(pickListValidation('unitStatus')).required(),
unitStatusReason: Joi.string().when('unitStatus', {
is: Joi.exist().valid('cancelled', 'retired'),
then: Joi.required(),
otherwise: Joi.allow(null).optional(),
}),
unitRegistryLink: Joi.string().required(),
correspondingAdjustmentDeclaration: Joi.string()
Expand All @@ -43,8 +44,8 @@ const unitsBaseSchema = {
.required(),
issuance: issuanceSchema.optional(),
labels: Joi.array().items(labelSchema).optional(),
updatedAt: Joi.date().optional(),
createdAt: Joi.date().optional(),
updatedAt: Joi.date().allow(null).optional(),
createdAt: Joi.date().allow(null).optional(),
timeStaged: Joi.date().timestamp().allow(null).optional(),
};

Expand Down

0 comments on commit 595cc9b

Please sign in to comment.