diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..22500a310 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +frontend/node_modules/ +user-service/.env diff --git a/user-service/model/repository.js b/user-service/model/repository.js index bfbf83452..d5c4a2a2c 100644 --- a/user-service/model/repository.js +++ b/user-service/model/repository.js @@ -15,3 +15,7 @@ export async function createUser(params) { return new UserModel(params) } +export async function checkUserName(params) { + console.log(UserModel.exists({username: params})); + return UserModel.exists({username: params}) +} diff --git a/user-service/model/user-orm.js b/user-service/model/user-orm.js index a630f7704..c7b08a945 100644 --- a/user-service/model/user-orm.js +++ b/user-service/model/user-orm.js @@ -1,14 +1,20 @@ -import { createUser } from './repository.js'; +import { createUser, checkUserName } from './repository.js'; //need to separate orm functions from repository to decouple business logic from persistence export async function ormCreateUser(username, password) { try { - const newUser = await createUser({username, password}); - newUser.save(); - return true; + const exists = await checkUserName(username); + if(!exists){ + const newUser = await createUser({username, password}); + newUser.save(); + return true; + } else { + const err = new Error('ERROR: UserName already exists'); + console.log(err.message); + throw err; + } } catch (err) { console.log('ERROR: Could not create new user'); return { err }; } } -