-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add custom validation for the serialnumberblock
- Loading branch information
1 parent
169fcc4
commit 88d47c0
Showing
15 changed files
with
187 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,39 @@ | ||
'use strict'; | ||
|
||
import express from 'express'; | ||
import Joi from 'joi'; | ||
import { UnitController } from '../../../controllers'; | ||
import joiExpress from 'express-joi-validation'; | ||
|
||
import { | ||
unitsGetQuerySchema, | ||
unitsPostSchema, | ||
unitsUpdateSchema, | ||
unitsDeleteSchema, | ||
unitsSplitSchema, | ||
} from '../../../validations'; | ||
|
||
const validator = joiExpress.createValidator({}); | ||
const UnitRouter = express.Router(); | ||
|
||
const querySchema = Joi.object() | ||
.keys({ | ||
page: Joi.number(), | ||
limit: Joi.number(), | ||
search: Joi.string(), | ||
warehouseUnitId: Joi.string(), | ||
columns: Joi.array().items(Joi.string()).single(), | ||
orgUid: Joi.string(), | ||
}) | ||
.with('page', 'limit'); | ||
|
||
UnitRouter.get('/', validator.query(querySchema), (req, res) => { | ||
UnitRouter.get('/', validator.query(unitsGetQuerySchema), (req, res) => { | ||
return req.query.warehouseUnitId | ||
? UnitController.findOne(req, res) | ||
: UnitController.findAll(req, res); | ||
}); | ||
|
||
const baseSchema = { | ||
countryJuridictionOfOwner: Joi.string().required(), | ||
inCountryJuridictionOfOwner: Joi.string().required(), | ||
// must be in the form ABC123-XYZ456 | ||
serialNumberBlock: Joi.string() | ||
.regex(/[.*\D]+[0-9]+[-][.*\D]+[0-9]+$/) | ||
.required(), | ||
unitIdentifier: Joi.string().required(), | ||
unitType: Joi.string().valid('heard reduction', 'removal').required(), | ||
intendedBuyerOrgUid: Joi.string().optional(), | ||
marketplace: Joi.string().optional(), | ||
tags: Joi.string().allow('').optional(), | ||
unitStatus: Joi.string().valid('Held', 'For Sale', 'Retired').required(), | ||
unitTransactionType: Joi.string().optional(), | ||
unitStatusReason: Joi.string().optional(), | ||
tokenIssuanceHash: Joi.string().required(), | ||
marketplaceIdentifier: Joi.string().optional(), | ||
unitsIssuanceLocation: Joi.string().optional(), | ||
unitRegistryLink: Joi.string().optional(), | ||
unitMarketplaceLink: Joi.string().optional(), | ||
cooresponingAdjustmentDeclaration: Joi.string() | ||
.valid('Commited', 'Not Required', 'Unknown') | ||
.required(), | ||
correspondingAdjustmentStatus: Joi.string() | ||
.valid('Not Started', 'Pending') | ||
.required(), | ||
}; | ||
|
||
const postSchema = Joi.object({ | ||
...baseSchema, | ||
}); | ||
|
||
UnitRouter.post('/', validator.body(postSchema), UnitController.create); | ||
|
||
const updateSchema = Joi.object({ | ||
warehouseUnitId: Joi.string().required(), | ||
...baseSchema, | ||
}); | ||
|
||
UnitRouter.put('/', validator.body(updateSchema), UnitController.update); | ||
|
||
const deleteSchema = Joi.object({ | ||
warehouseUnitId: Joi.string().required(), | ||
}); | ||
|
||
UnitRouter.delete('/', validator.body(deleteSchema), UnitController.destroy); | ||
UnitRouter.post('/', validator.body(unitsPostSchema), UnitController.create); | ||
UnitRouter.put('/', validator.body(unitsUpdateSchema), UnitController.update); | ||
|
||
const splitSchema = Joi.object({ | ||
warehouseUnitId: Joi.string().required(), | ||
records: Joi.array() | ||
.items( | ||
Joi.object().keys({ | ||
unitCount: Joi.number().required(), | ||
unitOwnerOrgUid: Joi.string().optional(), | ||
}), | ||
) | ||
.min(2) | ||
.max(2), | ||
}); | ||
UnitRouter.delete( | ||
'/', | ||
validator.body(unitsDeleteSchema), | ||
UnitController.destroy, | ||
); | ||
|
||
UnitRouter.post('/split', validator.body(splitSchema), UnitController.split); | ||
UnitRouter.post( | ||
'/split', | ||
validator.body(unitsSplitSchema), | ||
UnitController.split, | ||
); | ||
|
||
export { UnitRouter }; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './units.validations'; | ||
export * from './staging.validations'; | ||
export * from './projects.validations'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Joi from 'joi'; | ||
|
||
export const baseSchema = { | ||
originProjectId: Joi.string().required(), | ||
projectId: Joi.string().required(), | ||
program: Joi.string().required(), | ||
projectName: Joi.string().required(), | ||
projectLink: Joi.string().required(), | ||
projectDeveloper: Joi.string().required(), | ||
sector: Joi.string().required(), | ||
projectType: Joi.string().required(), | ||
coveredByNDC: Joi.number().required(), | ||
NDCLinkage: Joi.string().required(), | ||
projectStatus: Joi.string().required(), | ||
projectStatusDate: Joi.string().required(), | ||
unitMetric: Joi.string().required(), | ||
methodology: Joi.string().required(), | ||
methodologyVersion: Joi.number().required(), | ||
validationApproach: Joi.string().required(), | ||
validationDate: Joi.string().required(), | ||
projectTag: Joi.string().required(), | ||
estimatedAnnualAverageEmissionReduction: Joi.number().required(), | ||
projectLocations: Joi.array().min(1).optional(), | ||
qualifications: Joi.array().min(1).optional(), | ||
vintages: Joi.array().min(1).optional(), | ||
coBenefits: Joi.array().min(1).optional(), | ||
relatedProjects: Joi.array().min(1).optional(), | ||
}; | ||
|
||
export const projectsGetQuerySchema = Joi.object() | ||
.keys({ | ||
page: Joi.number(), | ||
limit: Joi.number(), | ||
search: Joi.string(), | ||
columns: Joi.array().items(Joi.string()).single(), | ||
orgUid: Joi.string(), | ||
}) | ||
.with('page', 'limit'); | ||
|
||
export const projectsPostSchema = Joi.object({ | ||
...baseSchema, | ||
}); | ||
|
||
export const projectsUpdateSchema = Joi.object({ | ||
warehouseProjectId: Joi.string().required(), | ||
...baseSchema, | ||
}); | ||
|
||
export const projectsDeleteSchema = Joi.object({ | ||
warehouseProjectId: Joi.string().required(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Joi from 'joi'; | ||
|
||
export const stagingDeleteSchema = Joi.object({ | ||
uuid: Joi.string().required(), | ||
}); |
Oops, something went wrong.