Browse Source

用户信息获取

release_0.0.3
yuan_yi 2 years ago
parent
commit
188207342c
  1. 26
      code/api/app/lib/controllers/user.js
  2. 8
      code/api/app/lib/routes/user/index.js

26
code/api/app/lib/controllers/user.js

@ -0,0 +1,26 @@
'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 = {}
}
}
module.exports = {
message
};

8
code/api/app/lib/routes/user/index.js

@ -0,0 +1,8 @@
'use strict';
const user = require('../../controllers/user');
module.exports = function (app, router, opts) {
app.fs.api.logAttr['GET/user/:userId/message'] = { content: '用户信息', visible: true };
router.get('/user/:userId/message', user.message);
};
Loading…
Cancel
Save