Browse Source

(*)部门培训记录查询、修改、导入接口

master
zmh 2 years ago
parent
commit
205efcdaf4
  1. 50
      api/app/lib/controllers/departmentTrain/index.js
  2. 8
      api/app/lib/routes/departmentTrain/index.js

50
api/app/lib/controllers/departmentTrain/index.js

@ -1,8 +1,16 @@
'use strict'; 'use strict';
async function getDepartmentTrainRecordList(ctx) { async function get(ctx) {
try { try {
const { limit, page } = ctx.query;
const models = ctx.fs.dc.models;
let res = await models.DeptTraining.findAndCountAll({
where: {},
offset: Number(page) * Number(limit),
limit: Number(limit),
order: [['id', 'ASC']]
})
ctx.status = 200; ctx.status = 200;
ctx.body = {}; ctx.body = res;
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
@ -10,9 +18,45 @@ async function getDepartmentTrainRecordList(ctx) {
message: '查询部门培训记录列表失败' message: '查询部门培训记录列表失败'
} }
} }
}
async function importData(ctx) {
let errorMsg = { message: '导入部门培训记录信息失败' };
const transaction = await ctx.fs.dc.orm.transaction();
try {
const models = ctx.fs.dc.models;
const data = ctx.request.body;
await models.DeptTraining.bulkCreate(data, { transaction });
await transaction.commit();
ctx.status = 204;
} catch (error) {
await transaction.rollback();
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = errorMsg;
}
} }
async function modify(ctx) {
try {
const { models } = ctx.fs.dc;
const { id, ...rest } = ctx.request.body;
const existRes = await models.DeptTraining.findOne({ where: { id } });
if (!existRes) {
throw '当前部门培训记录信息不存在';
}
await models.DeptTraining.update({ ...rest }, { where: { id: id } });
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: '修改部门培训记录失败'
}
}
}
module.exports = { module.exports = {
getDepartmentTrainRecordList get,
importData,
modify
} }

8
api/app/lib/routes/departmentTrain/index.js

@ -5,5 +5,11 @@ const departmentTrain = require('../../controllers/departmentTrain');
module.exports = function (app, router, opts) { module.exports = function (app, router, opts) {
app.fs.api.logAttr['GET/department/train/record/list'] = { content: '查询部门培训记录列表', visible: true }; app.fs.api.logAttr['GET/department/train/record/list'] = { content: '查询部门培训记录列表', visible: true };
router.get('/department/train/record/list', departmentTrain.getDepartmentTrainRecordList); router.get('/department/train/record/list', departmentTrain.get);
app.fs.api.logAttr['POST/department/train/record/bulk'] = { content: '导入部门培训记录信息', visible: true };
router.post('/department/train/record/bulk', departmentTrain.importData);
app.fs.api.logAttr['PUT/department/train/record/modify'] = { content: '编辑部门培训记录信息', visible: true };
router.put('/department/train/record/modify', departmentTrain.modify);
}; };
Loading…
Cancel
Save