feat: add opening quantity, cost and date to items.

This commit is contained in:
a.bouhuolia
2020-12-23 21:31:17 +02:00
parent b07bb2df53
commit 47b40f6940
9 changed files with 146 additions and 18 deletions

View File

@@ -25,6 +25,7 @@ export default class ItemsController extends BaseController {
router.post('/', [
...this.validateItemSchema,
...this.validateNewItemSchema,
],
this.validationResult,
asyncMiddleware(this.newItem.bind(this)),
@@ -90,6 +91,17 @@ export default class ItemsController extends BaseController {
return router;
}
/**
* New item validation schema.
*/
get validateNewItemSchema(): ValidationChain[] {
return [
check('opening_quantity').default(0).isInt({ min: 0 }).toInt(),
check('opening_cost').optional({ nullable: true }).isFloat({ min: 0 }).toFloat(),
check('opening_date').optional({ nullable: true }).isISO8601(),
];
}
/**
* Validate item schema.
*/