|
@ -6,7 +6,7 @@ async function get(ctx) { |
|
|
try { |
|
|
try { |
|
|
const { models } = ctx.fs.dc; |
|
|
const { models } = ctx.fs.dc; |
|
|
let roleList = await models.Role.findAndCountAll({ |
|
|
let roleList = await models.Role.findAndCountAll({ |
|
|
where: { delete: true }, |
|
|
where: { delete: false }, |
|
|
order: [['id', 'desc']], |
|
|
order: [['id', 'desc']], |
|
|
}); |
|
|
}); |
|
|
ctx.status = 200 |
|
|
ctx.status = 200 |
|
@ -24,10 +24,10 @@ async function add(ctx) { |
|
|
const { name } = ctx.request.body |
|
|
const { name } = ctx.request.body |
|
|
|
|
|
|
|
|
const role = await models.Role.findOne({ |
|
|
const role = await models.Role.findOne({ |
|
|
where: { name } |
|
|
where: { name: name, delete: false } |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
if (role && !role.delete) { |
|
|
if (role) { |
|
|
throw '当前角色已存在' |
|
|
throw '当前角色已存在' |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -49,13 +49,20 @@ async function edit(ctx) { |
|
|
// const { pepUserId, provinces, cities, businessLines } = ctx.request.body
|
|
|
// const { pepUserId, provinces, cities, businessLines } = ctx.request.body
|
|
|
const { id, name } = ctx.request.body |
|
|
const { id, name } = ctx.request.body |
|
|
|
|
|
|
|
|
const role = await models.Role.findOne({ |
|
|
const oldRole = await models.Role.findOne({ |
|
|
where: { id } |
|
|
where: { id } |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
if (!role) { |
|
|
if (!oldRole) { |
|
|
throw '当前角色不存在' |
|
|
throw '当前角色不存在' |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const role = await models.Role.findOne({ |
|
|
|
|
|
where: { name: name, id: { $not: id }, delete: false } |
|
|
|
|
|
}) |
|
|
|
|
|
if (!role) { |
|
|
|
|
|
throw '当前角色已存在' |
|
|
|
|
|
} |
|
|
let storageData = { name } |
|
|
let storageData = { name } |
|
|
await models.Role.update(storageData, { |
|
|
await models.Role.update(storageData, { |
|
|
where: { id } |
|
|
where: { id } |
|
@ -71,16 +78,32 @@ async function edit(ctx) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function del(ctx) { |
|
|
async function del(ctx) { |
|
|
|
|
|
const transaction = await ctx.fs.dc.orm.transaction(); |
|
|
try { |
|
|
try { |
|
|
const { models } = ctx.fs.dc; |
|
|
const { models } = ctx.fs.dc; |
|
|
const { id } = ctx.query |
|
|
const { id } = ctx.query |
|
|
|
|
|
|
|
|
await models.Role.update({ |
|
|
await models.Role.update({ delete: true }, |
|
|
delete: false}, |
|
|
{ |
|
|
{where: {id } |
|
|
where: { id }, |
|
|
|
|
|
transaction |
|
|
|
|
|
}) |
|
|
|
|
|
await models.RoleResource.destroy({ |
|
|
|
|
|
where: { |
|
|
|
|
|
roleId: id |
|
|
|
|
|
}, |
|
|
|
|
|
transaction |
|
|
|
|
|
}) |
|
|
|
|
|
await models.UserRole.destroy({ |
|
|
|
|
|
where: { |
|
|
|
|
|
roleId: id |
|
|
|
|
|
}, |
|
|
|
|
|
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 = { |
|
|