framez-server/Server/API/Routers/UserRouter.js

38 lines
801 B
JavaScript
Raw Normal View History

2018-04-28 14:52:36 +00:00
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;