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

37 lines
801 B
JavaScript

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;