IOT线 鉴权系统
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.
 
 
 
 
 

55 lines
1.3 KiB

'use strict';
async function message (ctx) {
try {
const { models } = ctx.fs.dc;
const { userId } = ctx.params
let userRes = await models.User.findAll({
attributes: { exclude: ['password'] },
where: {
id: { $in: userId.split(',') },
}
})
ctx.status = 200;
ctx.body = userRes
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {}
}
}
async function accord (ctx) {
try {
const { models } = ctx.fs.dc;
const { userId } = ctx.params
const data = ctx.request.body
const { action, data: params } = data
if (action == 'create') {
let params_ = JSON.parse(JSON.stringify(params))
params_.delete = false
await models.User.create(params_)
} else {
await models.User.update(params, {
where: {
id: { $in: String(params.id).split(',') }
}
})
}
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {}
}
}
module.exports = {
message,
accord
};