aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHafeez2018-04-13 16:46:48 +0100
committerHafeez2018-04-13 16:46:48 +0100
commitac6adaddabaefce05e88aa4ed0409aa76579b15f (patch)
treef1d3c6cd7db7af6e9a0b957d98b18f156596f4d8 /src
parentchanged something (diff)
parentfixed user not found (diff)
downloadmedicine-ac6adaddabaefce05e88aa4ed0409aa76579b15f.tar.gz
medicine-ac6adaddabaefce05e88aa4ed0409aa76579b15f.zip

Merge branch ‘trh/gets’ of gitlab.cs.st-andrews.ac.uk:cs3099group-be-4/project-code into trh/gets

Diffstat (limited to 'src')
-rw-r--r--src/FileRouter.ts18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/FileRouter.ts b/src/FileRouter.ts
index 990110a..e890241 100644
--- a/src/FileRouter.ts
+++ b/src/FileRouter.ts
@@ -257,6 +257,10 @@ const getUserProperties: Middleware = (
req: Request, res: Response, next: NextFunction
): void => {
logger.debug('Listing additional properties for a user');
+ if (res.locals.user == null) {
+ next(new RequestError(404, 'user_not_found'));
+ return;
+ }
res.locals.data = res.locals.user.properties;
next();
};
@@ -354,16 +358,18 @@ const postUsername: Middleware = async(
): Promise<void> => {
let user: User | null | undefined = res.locals.user;
if (user == null) {
- logger.debug('Adding new user');
+ console.log('Adding new user');
user = new User({
username: req.params.username,
password: req.params.password
});
} else {
- logger.debug('Editing user');
+ console.log('Editing user');
user.password = req.params.password;
}
- user.metadata = req.body;
+ if (req.body) {
+ user.metadata = req.body;
+ }
next();
};
@@ -622,11 +628,7 @@ export class FileRouter {
username: name
}
});
- if (user == null) {
- return next(new RequestError(404, 'user_not_found'));
- } else {
- res.locals.user = user;
- }
+ res.locals.user = user;
next();
}
);