Skip to content

Commit ad7f9c6

Browse files
committed
merge
1 parent 935c77f commit ad7f9c6

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

server/controllers/userController.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ const randomPassword = () => {
2525
};
2626

2727
const userController: UserController = {
28+
getUsername: async (req, res, next) => {
29+
try {
30+
const { username } = req.body;
31+
const user = await Users.findOne({ username });
32+
return next();
33+
} catch (err) {
34+
return next({
35+
log: 'error cuaght in getUsername middleware',
36+
status: 400,
37+
message: { err: 'cannot get username' }
38+
});
39+
}
40+
},
2841
createUser: (req, res, next) => {
2942
let email, username, password;
3043
// use this condition for Oauth login

server/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export interface newUserError extends NativeError {
4646
}
4747

4848
export interface UserController {
49+
getUsername: RequestHandler;
4950
createUser: RequestHandler;
5051
verifyUser: RequestHandler;
5152
}

server/server.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ io.on('connection', (socket) => {
111111
});
112112
});
113113

114+
const usersInRoom = [];
115+
app.get('/', userController.getUsername, (req, res) => {
116+
const username = req.body.username;
117+
console.log('username: ', username);
118+
usersInRoom.push({ username: username });
119+
console.log(usersInRoom);
120+
return res.status(200).json({ username: username });
121+
});
122+
114123
/*
115124
GraphQl Router
116125
*/

0 commit comments

Comments
 (0)