Skip to content

Commit

Permalink
Merge pull request #16 from CS3219-AY2223S1/FR1.2
Browse files Browse the repository at this point in the history
Fr1.2
  • Loading branch information
tanyutao544 authored Sep 4, 2022
2 parents 11e12b4 + ea9065f commit ca9594c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
frontend/node_modules/
user-service/.env
4 changes: 4 additions & 0 deletions user-service/model/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
16 changes: 11 additions & 5 deletions user-service/model/user-orm.js
Original file line number Diff line number Diff line change
@@ -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 };
}
}

0 comments on commit ca9594c

Please sign in to comment.