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) {