You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
2.3 KiB
99 lines
2.3 KiB
2 years ago
|
'use strict';
|
||
|
const moment = require('moment')
|
||
|
const fs = require('fs');
|
||
|
|
||
|
async function get(ctx) {
|
||
|
try {
|
||
|
const { models } = ctx.fs.dc;
|
||
|
let userRoleList = await models.UserRole.findAndCountAll({
|
||
|
order: [['id', 'desc']]
|
||
|
});
|
||
|
ctx.status = 200
|
||
|
ctx.body = userRoleList;
|
||
|
} catch (error) {
|
||
|
ctx.fs.logger.error(`path:${ctx.path},error:${error}`)
|
||
|
ctx.status = 400;
|
||
|
ctx.body = { name: 'FindError', message: '查询用户信息失败' }
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async function add(ctx) {
|
||
|
try {
|
||
|
const { models } = ctx.fs.dc;
|
||
|
const { userId, roleId } = ctx.request.body
|
||
|
await models.UserRole.destroy({
|
||
|
where: { roleId: roleId }
|
||
|
})
|
||
|
|
||
|
let storageData = userId.map(e => {
|
||
|
return {
|
||
|
roleId: roleId,
|
||
|
userId: e
|
||
|
}
|
||
|
})
|
||
|
await models.UserRole.bulkCreate(storageData);
|
||
|
ctx.status = 204;
|
||
|
} catch (error) {
|
||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
|
||
|
ctx.status = 400;
|
||
|
ctx.body = {
|
||
|
message: typeof error == 'string' ? error : undefined
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async function edit(ctx) {
|
||
|
try {
|
||
|
const { models } = ctx.fs.dc;
|
||
|
// const { pepUserId, provinces, cities, businessLines } = ctx.request.body
|
||
|
const { id, name } = ctx.request.body
|
||
|
|
||
|
const role = await models.Role.findOne({
|
||
|
where: { id }
|
||
|
})
|
||
|
|
||
|
if (!role) {
|
||
|
throw '当前角色不存在'
|
||
|
}
|
||
|
let storageData = { name }
|
||
|
await models.Role.update(storageData, {
|
||
|
where: { id }
|
||
|
})
|
||
|
ctx.status = 204;
|
||
|
} catch (error) {
|
||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
|
||
|
ctx.status = 400;
|
||
|
ctx.body = {
|
||
|
message: typeof error == 'string' ? error : undefined
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async function del(ctx) {
|
||
|
try {
|
||
|
const { models } = ctx.fs.dc;
|
||
|
const { id } = ctx.request.body
|
||
|
|
||
|
await models.SalesDistribution.update({
|
||
|
delete: false
|
||
|
},
|
||
|
{
|
||
|
where: { id }
|
||
|
})
|
||
|
ctx.status = 204;
|
||
|
} catch (error) {
|
||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
|
||
|
ctx.status = 400;
|
||
|
ctx.body = {
|
||
|
message: typeof error == 'string' ? error : undefined
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
module.exports = {
|
||
|
get,
|
||
|
add,
|
||
|
edit,
|
||
|
del,
|
||
|
}
|