From 47fae4f288f8cce9da45dc51f4ad9f100a9d82f7 Mon Sep 17 00:00:00 2001 From: ASIF ALI DAR Date: Thu, 16 Nov 2023 16:09:56 +0530 Subject: [PATCH] Update route-controller-service-structure-for-expressjs.md using destructuring in user.controllers.js: --- ...te-controller-service-structure-for-expressjs.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/nodejs/route-controller-service-structure-for-expressjs.md b/docs/nodejs/route-controller-service-structure-for-expressjs.md index daff383c..a074a654 100644 --- a/docs/nodejs/route-controller-service-structure-for-expressjs.md +++ b/docs/nodejs/route-controller-service-structure-for-expressjs.md @@ -85,17 +85,16 @@ module.exports = router; var UserService = require('../services/user.service') exports.getUsers = async function (req, res, next) { - // Validate request parameters, queries using express-validator - - var page = req.params.page ? req.params.page : 1; - var limit = req.params.limit ? req.params.limit : 10; + const { page = 1, limit = 10 } = req.params; + try { - var users = await UserService.getUsers({}, page, limit) - return res.status(200).json({ status: 200, data: users, message: "Succesfully Users Retrieved" }); + const users = await UserService.getUsers({}, page, limit); + return res.status(200).json({ status: 200, data: users, message: "Successfully Users Retrieved" }); } catch (e) { return res.status(400).json({ status: 400, message: e.message }); } -} +}; + ```