Added get user by id route
This commit is contained in:
parent
bae570232c
commit
ac65f4372c
2 changed files with 41 additions and 2 deletions
|
@ -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;
|
||||
|
|
37
Server/API/Routers/UserRouter.js
Normal file
37
Server/API/Routers/UserRouter.js
Normal 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;
|
Loading…
Reference in a new issue