Skip to content

Commit

Permalink
fix: avoid race condition by using parallelism
Browse files Browse the repository at this point in the history
  • Loading branch information
karimdaghari committed Jan 20, 2020
1 parent 883a8ae commit f8cfa4b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/modules/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ export class UserService {
}

async addUser(newUser: UserInput): Promise<User> {
// eslint-disable-next-line require-atomic-updates
newUser.password = await this.sharedService.hashPassword(newUser.password);
// eslint-disable-next-line require-atomic-updates
newUser.profile = await this.profileService.addUserProfile(newUser.profile);
const [password, profile] = await Promise.all([
await this.sharedService.hashPassword(newUser.password),
await this.profileService.addUserProfile(newUser.profile)
]);
newUser.password = password;
newUser.profile = profile;
const addedUser = await this.userRepository.save(newUser);
return await this.userRepository.findOneOrFail(
{ id: addedUser.id },
Expand Down

0 comments on commit f8cfa4b

Please sign in to comment.