Added get user by id route

This commit is contained in:
Sagi Dayan 2018-04-28 17:52:36 +03:00
parent bae570232c
commit ac65f4372c
2 changed files with 41 additions and 2 deletions

View file

@ -6,6 +6,7 @@ const bodyParser = require('body-parser');
const UpdateRouter = require('./Routers/UpdateRouter');
const AccountRouter = require('./Routers/AccountRouter');
const FrameRouter = require('./Routers/FrameRouter');
const UserRouter = require('./Routers/UserRouter');
// parse application/x-www-form-urlencoded
@ -20,6 +21,7 @@ router.use(bodyParser.json())
// }
router.use('/update', UpdateRouter);
router.use('/account', AccountRouter)
router.use('/frame', FrameRouter)
router.use('/account', AccountRouter);
router.use('/frame', FrameRouter);
router.use('/user', UserRouter);
module.exports = router;

View file

@ -0,0 +1,37 @@
const express = require("express");
const DBUtils = require('../../Utils/DBUtil');
const AuthUtil = require('../../Utils/AuthUtil');
const router = express.Router();
router.get('/:accountId', (req, res) => {
const token = req.get('token');
const accountId = req.params.accountId;
if(!accountId){
res.status(400).json({
message: 'Invalid account id'
});
return;
}
AuthUtil.getAccountByToken(token)
.then(account => {
AuthUtil.getUserByAccountId(accountId)
.then(user => {
res.json(user);
})
.catch(reason => {
res.status(400).json({
message: reason
});
})
})
.catch(reason => {
res.status(401).json({
message: reason
});
})
});
module.exports = router;