competemcgill / wisp-users-microservice

WISP Microservice to handle user data and interactions
https://docs.wisp.compete-mcgill.ca/microservices/users
MIT License
4 stars 1 forks source link

Make username unique in the DB #20

Closed ValerianClerc closed 4 years ago

ValerianClerc commented 4 years ago

Title

MohamedBeydoun commented 4 years ago

Username should be unique in DB, but the checks should also be performed like we do with emails (we check if a user exists with the given email and send a 400 "User already exists") e.g.

const foundUserByEmail: IUserModel = await userDBInteractions.findByEmail(req.body.email);
const foundUserByUsername: IUserModel = await userDBInteractions.findByUsername(req.body.username);
if (foundUserByEmail || foundUserByUsername) res.status(statusCodes.BAD_REQUEST).send({ status: statusCodes.BAD_REQUEST, message: "User already exists" });
else {}