|
@ -20,11 +20,19 @@ async function get(ctx) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function add(ctx) { |
|
|
async function add(ctx) { |
|
|
|
|
|
const transaction = await ctx.fs.dc.orm.transaction(); |
|
|
try { |
|
|
try { |
|
|
const { models } = ctx.fs.dc; |
|
|
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({ |
|
|
await models.RoleResource.destroy({ |
|
|
where: { roleId: roleId } |
|
|
where: { roleId: roleId }, |
|
|
|
|
|
transaction |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
let storageData = resourceId.map(e => { |
|
|
let storageData = resourceId.map(e => { |
|
@ -33,9 +41,11 @@ async function add(ctx) { |
|
|
resId: e |
|
|
resId: e |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
await models.RoleResource.bulkCreate(storageData); |
|
|
await models.RoleResource.bulkCreate(storageData, { transaction }); |
|
|
|
|
|
await transaction.commit(); |
|
|
ctx.status = 204; |
|
|
ctx.status = 204; |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
|
|
|
await transaction.rollback(); |
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
ctx.status = 400; |
|
|
ctx.status = 400; |
|
|
ctx.body = { |
|
|
ctx.body = { |
|
|