|
@ -44,10 +44,10 @@ async function editUser (ctx) { |
|
|
// 存在且传递id 或者 不传id也存在
|
|
|
// 存在且传递id 或者 不传id也存在
|
|
|
// 修改 update
|
|
|
// 修改 update
|
|
|
storageData.deleted = false |
|
|
storageData.deleted = false |
|
|
|
|
|
storageData.role = [...new Set([...existUserRes.role, ...role])] |
|
|
if ( |
|
|
if ( |
|
|
role.includes('admin') |
|
|
storageData.role.includes('admin') |
|
|
) { |
|
|
) { |
|
|
storageData.role = [...new Set([...existUserRes.role, ...role])] |
|
|
|
|
|
storageData.disabled = false |
|
|
storageData.disabled = false |
|
|
} |
|
|
} |
|
|
await models.User.update(storageData, { |
|
|
await models.User.update(storageData, { |
|
@ -75,6 +75,16 @@ async function putUser (ctx) { |
|
|
const models = ctx.fs.dc.models; |
|
|
const models = ctx.fs.dc.models; |
|
|
const { pomsUserId } = ctx.params |
|
|
const { pomsUserId } = ctx.params |
|
|
const { disabled = undefined, deleted = undefined } = ctx.request.body |
|
|
const { disabled = undefined, deleted = undefined } = ctx.request.body |
|
|
|
|
|
const existUserRes = await models.User.findOne({ |
|
|
|
|
|
where: { |
|
|
|
|
|
id: pomsUserId |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
if (existUserRes && existUserRes.role.includes('admin')) { |
|
|
|
|
|
throw '已是管理员,请先解除管理员权限' |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const updateData = { |
|
|
const updateData = { |
|
|
disabled, |
|
|
disabled, |
|
|
deleted, |
|
|
deleted, |
|
@ -84,6 +94,7 @@ async function putUser (ctx) { |
|
|
delete updateData[k] |
|
|
delete updateData[k] |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
await models.User.update(updateData, { |
|
|
await models.User.update(updateData, { |
|
|
where: { |
|
|
where: { |
|
|
id: pomsUserId |
|
|
id: pomsUserId |
|
@ -94,7 +105,7 @@ async function putUser (ctx) { |
|
|
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 = { |
|
|
|
|
|
message: typeof error == 'string' ? error : undefined |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|