Skip to content

Commit

Permalink
fix: define default value, and enhance the validation of limit and of…
Browse files Browse the repository at this point in the history
…fset
  • Loading branch information
WeiyuSun committed Jul 20, 2023
1 parent 49bac90 commit 6d719d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion server/handlers/walletHandler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const walletGet = async (req, res) => {
await walletGetQuerySchema.validateAsync(req.query, { abortEarly: false });
const walletService = new WalletService();

const { limit, offset } = req.query;
const { limit, offset } = (req.query.limit) ? req.query : {limit: 1000, offset: 0};
const wallets = await walletService.getAllWallets(req.wallet_id, {
limit,
offset,
Expand Down
10 changes: 8 additions & 2 deletions server/handlers/walletHandler/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ const Joi = require('joi');
const TrustRelationshipEnums = require('../../utils/trust-enums');

const walletGetQuerySchema = Joi.object({
limit: Joi.number().required(),
offset: Joi.number().integer(),
limit: Joi.number()
.integer().message('limit can only be non-negative integer')
.min(0).message('limit can only be non-negative integer')
.max(Number.MAX_SAFE_INTEGER).message('limit value overflow'),
offset: Joi.number()
.integer().message('offset can only be non-negative integer')
.min(0).message('offset can only be non-negative integer')
.max(Number.MAX_SAFE_INTEGER).message('offset value overflow'),
});

const walletIdParamSchema = Joi.object({
Expand Down

0 comments on commit 6d719d0

Please sign in to comment.