aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/FileRouter.ts18
-rw-r--r--test/integration/protocol.routes.test.ts2
2 files changed, 11 insertions, 9 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();
}
);
diff --git a/test/integration/protocol.routes.test.ts b/test/integration/protocol.routes.test.ts
index 2a7cf54..866ac2a 100644
--- a/test/integration/protocol.routes.test.ts
+++ b/test/integration/protocol.routes.test.ts
@@ -184,7 +184,7 @@ describe('routes : protocol', () => {
public_admin_metadata: types.anything,
private_admin_metadata: types.anything
}, 200],
- ['post', '/users/mock_user', null, 200],
+ ['post', '/users/new_user', null, 200],
['get', '/users/mock_user/properties', {
data: optional(types.anything)
}, 200],