Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #315 from kmcwebdev/development
Browse files Browse the repository at this point in the history
Create new propelauth user if user does not exist
  • Loading branch information
csulit authored Oct 9, 2023
2 parents 8f51e8f + f41e86c commit 4e270ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,27 @@ export class ReimbursementMemphisNewRequestService implements OnModuleInit {
}
}

let propelauth_user_id = '';

const propelauthUser =
await this.usersApiService.fetchUserInPropelauthByEmail(
email,
);

propelauth_user_id = propelauthUser.userId;

if (!propelauthUser) {
await this.usersApiService.createUserInPropelauth(
email,
'External Reimbursement Approver Manager',
);
const newPropelauthUser =
await this.usersApiService.createUserInPropelauth(
email,
'External Reimbursement Approver Manager',
);

propelauth_user_id = newPropelauthUser.userId;
}

if (!propelauth_user_id) {
throw new Error('Propelauth user id not populated with data');
}

let approverManager = await trx
Expand Down Expand Up @@ -239,6 +250,7 @@ export class ReimbursementMemphisNewRequestService implements OnModuleInit {
const dbUser =
await this.usersApiService.createOrGetUserInDatabase({
email,
propelauth_user_id,
});

const newApprover = await trx
Expand All @@ -254,7 +266,7 @@ export class ReimbursementMemphisNewRequestService implements OnModuleInit {
approverManager = {
approver_id: newApprover.approver_id,
user_id: dbUser.user_id,
propelauth_user_id: dbUser.propelauth_user_id,
propelauth_user_id,
email: dbUser.email,
full_name: dbUser.full_name,
};
Expand Down Expand Up @@ -305,7 +317,7 @@ export class ReimbursementMemphisNewRequestService implements OnModuleInit {

const actionToken =
await this.generatePropelauthLongliveAcessToken({
user_id: approverManager.propelauth_user_id,
user_id: propelauth_user_id,
})
.then((data) => data.access_token)
.catch(() => {
Expand Down
7 changes: 2 additions & 5 deletions src/users/services/users.api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,10 @@ export class UsersApiService {

const newPropelauthUser = await propelauth.createUser({
email: email,
firstName: 'Juan',
lastName: 'Dela Cruz',
username: email.match(/([^@]+)/)[0],
password: temporaryPassword,
askUserToUpdatePasswordOnLogin: true,
sendEmailToConfirmEmailAddress: false,
emailConfirmed: true,
sendEmailToConfirmEmailAddress: true,
emailConfirmed: false,
});

this.eventEmitter.emit('reimbursement-request-send-email-new-user', {
Expand Down

0 comments on commit 4e270ea

Please sign in to comment.