Skip to content

Commit ca9594c

Browse files
authored
Merge pull request #16 from CS3219-AY2223S1/FR1.2
Fr1.2
2 parents 11e12b4 + ea9065f commit ca9594c

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
frontend/node_modules/
3+
user-service/.env

user-service/model/repository.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ export async function createUser(params) {
1515
return new UserModel(params)
1616
}
1717

18+
export async function checkUserName(params) {
19+
console.log(UserModel.exists({username: params}));
20+
return UserModel.exists({username: params})
21+
}

user-service/model/user-orm.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
import { createUser } from './repository.js';
1+
import { createUser, checkUserName } from './repository.js';
22

33
//need to separate orm functions from repository to decouple business logic from persistence
44
export async function ormCreateUser(username, password) {
55
try {
6-
const newUser = await createUser({username, password});
7-
newUser.save();
8-
return true;
6+
const exists = await checkUserName(username);
7+
if(!exists){
8+
const newUser = await createUser({username, password});
9+
newUser.save();
10+
return true;
11+
} else {
12+
const err = new Error('ERROR: UserName already exists');
13+
console.log(err.message);
14+
throw err;
15+
}
916
} catch (err) {
1017
console.log('ERROR: Could not create new user');
1118
return { err };
1219
}
1320
}
14-

0 commit comments

Comments
 (0)