Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const addUser = ({ id, username, room }) => {
- // Clean the data
- username = username.trim().toLowerCase();
- room = room.trim().toLowerCase();
- // Validate the data
- if (!username || !room) {
- return {
- error: "Username and room required!"
- };
- }
- // Check for existing user
- const existingUser = users.find(user => {
- return user.room === room && user.username === username;
- });
- // Validate username
- if (existingUser) {
- return {
- error: "Username is taken!"
- };
- }
- // Store user
- const user = { id, username, room };
- users.push(user);
- console.log(users);
- return { user };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement