Move updateBuilding out of try-catch around authentication
This commit is contained in:
parent
6ec8820333
commit
c18dc837db
@ -49,12 +49,14 @@ const getBuildingById = asyncController(async (req: express.Request, res: expres
|
||||
});
|
||||
|
||||
const updateBuildingById = asyncController(async (req: express.Request, res: express.Response) => {
|
||||
let user_id;
|
||||
|
||||
if (req.session.user_id) {
|
||||
await updateBuilding(req, res, req.session.user_id);
|
||||
user_id = req.session.user_id;
|
||||
} else if (req.query.api_key) {
|
||||
try {
|
||||
const user = await userService.authAPIUser(String(req.query.api_key));
|
||||
await updateBuilding(req, res, user.user_id);
|
||||
user_id = user.user_id;
|
||||
} catch(err) {
|
||||
console.error(err);
|
||||
res.send({ error: 'Must be logged in' });
|
||||
@ -62,6 +64,10 @@ const updateBuildingById = asyncController(async (req: express.Request, res: exp
|
||||
} else {
|
||||
res.send({ error: 'Must be logged in' });
|
||||
}
|
||||
|
||||
if (user_id) {
|
||||
await updateBuilding(req, res, user_id);
|
||||
}
|
||||
});
|
||||
|
||||
async function updateBuilding(req: express.Request, res: express.Response, userId: string) {
|
||||
|
Loading…
Reference in New Issue
Block a user