Skip to content

Commit

Permalink
Merge pull request #429 from XLPeng57/#248-hide-SQL-from-Postman-client
Browse files Browse the repository at this point in the history
fix: validated id in endpoint /token/:id
  • Loading branch information
Kpoke authored Sep 21, 2023
2 parents f51d888 + 451eaf8 commit 0c6504d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 9 additions & 3 deletions server/handlers/tokenHandler/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const TokenService = require('../../services/TokenService');
const { tokenGetSchema, tokenGetTransactionsByIdSchema } = require('./schemas');
const { tokenGetSchema, tokenIdSchema, tokenGetTransactionsByIdSchema } = require('./schemas');

const tokenGet = async (req, res) => {
const validatedQuery = await tokenGetSchema.validateAsync(req.query, { abortEarly: false });
Expand All @@ -21,7 +21,10 @@ const tokenGet = async (req, res) => {
};

const tokenGetById = async (req, res) => {
const { id } = req.params;
const validatedParams = await tokenIdSchema.validateAsync(req.params, {
abortEarly: false,
});
const {id} = validatedParams;
const {wallet_id} = req
const tokenService = new TokenService();
const token = await tokenService.getById({
Expand All @@ -38,7 +41,10 @@ const tokenGetTransactionsById = async (req, res) => {
abortEarly: false,
});
const { limit, offset } = validatedQuery;
const { id } = req.params;
const validatedParams = await tokenIdSchema.validateAsync(req.params, {
abortEarly: false,
});
const { id } = validatedParams;
const {wallet_id} = req
const tokenService = new TokenService();
const transactions = await tokenService.getTransactions({
Expand Down
5 changes: 5 additions & 0 deletions server/handlers/tokenHandler/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ const tokenGetSchema = Joi.object({
wallet: Joi.string(),
});

const tokenIdSchema = Joi.object({
id: Joi.string().uuid().required(),
});

const tokenGetTransactionsByIdSchema = Joi.object({
limit: Joi.number().integer().min(1).max(2000).default(1000),
offset: Joi.number().integer().min(0).default(0),
});

module.exports = {
tokenGetSchema,
tokenIdSchema,
tokenGetTransactionsByIdSchema,
};

0 comments on commit 0c6504d

Please sign in to comment.