Skip to content

Commit

Permalink
feat: add validation for pagination params
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael.Taylor committed Jan 5, 2022
1 parent c9b9ceb commit a4e428d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/routes/v1/resources/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ import joiExpress from 'express-joi-validation';
const validator = joiExpress.createValidator({});
const ProjectRouter = express.Router();

ProjectRouter.get('/', (req, res) => {
const querySchema = Joi.object()
.keys({
page: Joi.number(),
limit: Joi.number(),
search: Joi.string(),
})
.with('page', 'limit');

ProjectRouter.get('/', validator.query(querySchema), (req, res) => {
return req.query.warehouseProjectId
? ProjectController.findOne(req, res)
: ProjectController.findAll(req, res);
Expand Down
10 changes: 9 additions & 1 deletion src/routes/v1/resources/units.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ import joiExpress from 'express-joi-validation';
const validator = joiExpress.createValidator({});
const UnitRouter = express.Router();

UnitRouter.get('/', (req, res) => {
const querySchema = Joi.object()
.keys({
page: Joi.number(),
limit: Joi.number(),
search: Joi.string(),
})
.with('page', 'limit');

UnitRouter.get('/', validator.query(querySchema), (req, res) => {
return req.query.id
? UnitController.findOne(req, res)
: UnitController.findAll(req, res);
Expand Down

0 comments on commit a4e428d

Please sign in to comment.