From 545f121149461c05ae855a78962a6d7075446f41 Mon Sep 17 00:00:00 2001 From: zhangminghua Date: Fri, 7 Jul 2023 14:49:34 +0800 Subject: [PATCH] =?UTF-8?q?(*)=E9=83=A8=E9=97=A8=E5=9F=B9=E8=AE=AD?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=95=B0=E6=8D=AE=E8=8C=83=E5=9B=B4=E6=8E=A7?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/controllers/departmentTrain/index.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/api/app/lib/controllers/departmentTrain/index.js b/api/app/lib/controllers/departmentTrain/index.js index f14bd62..3c7d1f2 100644 --- a/api/app/lib/controllers/departmentTrain/index.js +++ b/api/app/lib/controllers/departmentTrain/index.js @@ -1,17 +1,25 @@ 'use strict'; -const moment = require("moment/moment"); +const moment = require("moment"); +const { getDataRange } = require('../auth/index') async function get(ctx) { try { const { limit, page } = ctx.query; const models = ctx.fs.dc.models; - let res = await models.DeptTraining.findAndCountAll({ + const findObj = { where: {}, - offset: Number(page) * Number(limit), - limit: Number(limit), order: [['id', 'ASC']] - }) + }; + let dataRange = await getDataRange(ctx); + if (dataRange.departmentNames) { + findObj.where.departmentName = { $in: dataRange.departmentNames || [] } + } + if (Number(limit) > 0 && Number(page) >= 0) { + findObj.limit = Number(limit); + findObj.offset = Number(page) * Number(limit); + } + let res = await models.DeptTraining.findAndCountAll(findObj) ctx.status = 200; ctx.body = res; } catch (error) {