diff --git a/code/api/app/lib/controllers/user.js b/code/api/app/lib/controllers/user.js new file mode 100644 index 0000000..3ddb594 --- /dev/null +++ b/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 +}; \ No newline at end of file diff --git a/code/api/app/lib/routes/user/index.js b/code/api/app/lib/routes/user/index.js new file mode 100644 index 0000000..d494c84 --- /dev/null +++ b/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); +};