Browse Source

(*)角色数据范围入库

master
zmh 2 years ago
parent
commit
b8313cb8c7
  1. 2
      api/app/lib/controllers/role/index.js
  2. 16
      api/app/lib/controllers/roleResource/index.js

2
api/app/lib/controllers/role/index.js

@ -31,7 +31,7 @@ async function add(ctx) {
throw '当前角色已存在'
}
let storageData = { name, delete: true }
let storageData = { name, delete: false }
await models.Role.create(storageData)
ctx.status = 204;
} catch (error) {

16
api/app/lib/controllers/roleResource/index.js

@ -20,11 +20,19 @@ async function get(ctx) {
}
async function add(ctx) {
const transaction = await ctx.fs.dc.orm.transaction();
try {
const { models } = ctx.fs.dc;
const { roleId, resourceId } = ctx.request.body
const { roleId, resourceId, dataRange } = ctx.request.body
await models.Role.update(
{ dataRange: dataRange },
{
where: { id: roleId },
transaction
})
await models.RoleResource.destroy({
where: { roleId: roleId }
where: { roleId: roleId },
transaction
})
let storageData = resourceId.map(e => {
@ -33,9 +41,11 @@ async function add(ctx) {
resId: e
}
})
await models.RoleResource.bulkCreate(storageData);
await models.RoleResource.bulkCreate(storageData, { 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 = {

Loading…
Cancel
Save