From 5dc9d9f8fddb2c0be046e60b6471dd72716d9488 Mon Sep 17 00:00:00 2001 From: chaosBreaking Date: Tue, 8 Oct 2019 14:53:06 +0800 Subject: [PATCH] =?UTF-8?q?feat=20admin=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/admin/admin.controller.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/modules/admin/admin.controller.js b/src/modules/admin/admin.controller.js index 82829dc..53d0e5f 100644 --- a/src/modules/admin/admin.controller.js +++ b/src/modules/admin/admin.controller.js @@ -58,7 +58,8 @@ module.exports = { async getUserActions (req, res) { const { adminId } = res.locals.user; if (!adminId) return res.json({ code: 1, msg: '非法访问' }); - await Action.find({ ...req.body }).then(data => { + const { pageSize = 10, pageIndex = 1 } = req.body; + await Action.find({ ...req.body }).limit(pageSize).skip((pageIndex - 1) * pageSize).then(data => { return res.json({ code: 0, data @@ -73,7 +74,8 @@ module.exports = { async getDepositTicket (req, res) { const { adminId } = res.locals.user; if (!adminId) return res.json({ code: 1, msg: '非法访问' }); - await Ticket.find({ ...req.body }).then(data => { + const { pageSize = 10, pageIndex = 1} = req.body; + await Ticket.find({ ...req.body }).limit(pageSize).skip((pageIndex - 1) * pageSize).then(data => { return res.json({ code: 0, data @@ -88,7 +90,9 @@ module.exports = { async getUsers (req, res) { const { adminId } = res.locals.user; if (!adminId) return res.json({ code: 1, msg: '非法访问' }); - const [sum, data] = await Promise.all([User.count({}), User.find({ ...req.body })]).catch(err => { + const { pageSize = 10, pageIndex = 1} = req.body; + const [sum, data] = await Promise.all([User.count({}), User.find({ ...req.body }).limit(pageSize).skip((pageIndex - 1) * pageSize)]) + .catch(err => { return [err.msg, '']; }); if (!Array.isArray(data)) return res.json({