Skip to content

Commit

Permalink
10007: WIP unify user record creation
Browse files Browse the repository at this point in the history
  • Loading branch information
rachelschneiderman committed Mar 12, 2024
1 parent 3d9a147 commit 33dfca5
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 615 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,28 @@ export const createUserForContact = async ({

const userRaw = userEntity.validate().toRawObject();

await applicationContext.getPersistenceGateway().createNewPetitionerUser({
applicationContext,
user: userRaw,
});
const createUserPromise = applicationContext
.getUserGateway()
.createUser(applicationContext, {
attributesToUpdate: {
email: userRaw.pendingEmail,
name: userRaw.name,
role: ROLES.petitioner,
userId: userRaw.userId,
},
email: userRaw.pendingEmail!,
resendInvitationEmail: false,
});

const createUserRecordsPromise = applicationContext
.getPersistenceGateway()
.createUserRecords({
applicationContext,
user: userRaw,
userId: userRaw.userId,
});

await Promise.all([createUserPromise, createUserRecordsPromise]);

const rawCase = caseEntity.toRawObject();
const userCaseEntity = new UserCase(rawCase);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ROLES, Role } from '@shared/business/entities/EntityConstants';
import {
ROLE_PERMISSIONS,
isAuthorized,
Expand All @@ -17,19 +18,69 @@ export const createPractitionerUserInteractor = async (
throw new UnauthorizedError('Unauthorized for creating practitioner user');
}

const practitionerRoleTypes: Role[] = [
ROLES.privatePractitioner,
ROLES.irsPractitioner,
ROLES.inactivePractitioner,
];
if (!practitionerRoleTypes.includes(user.role)) {
throw new Error(
`Role must be ${ROLES.privatePractitioner}, ${ROLES.irsPractitioner}, or ${ROLES.inactivePractitioner}`,
);
}

user.pendingEmail = user.email;
user.email = undefined;

const practitioner = await createPractitionerUser(applicationContext, {
user,
});

const createdUser = await applicationContext
.getPersistenceGateway()
.createOrUpdatePractitionerUser({
if (!practitioner.pendingEmail) {
return await applicationContext.getPersistenceGateway().createUserRecords({
applicationContext,
user: practitioner,
user,
userId: practitioner.userId,
});
}

const existingUser = await applicationContext
.getUserGateway()
.getUserByEmail(applicationContext, {
email: practitioner.pendingEmail,
});

if (!existingUser) {
await applicationContext.getUserGateway().createUser(applicationContext, {
attributesToUpdate: {
email: practitioner.pendingEmail,
name: practitioner.name,
role: practitioner.role,
userId: practitioner.userId,
},
email: practitioner.pendingEmail,
resendInvitationEmail: false,
});

return { barNumber: createdUser.barNumber };
await applicationContext.getPersistenceGateway().createUserRecords({
applicationContext,
user,
userId: practitioner.userId,
});
} else {
await applicationContext.getUserGateway().updateUser(applicationContext, {
attributesToUpdate: {
role: practitioner.role,
},
email: practitioner.pendingEmail,
});

await applicationContext.getPersistenceGateway().createUserRecords({
applicationContext,
user,
userId: existingUser.userId,
});
}

return { barNumber: practitioner.barNumber };
};
10 changes: 5 additions & 5 deletions web-api/src/getPersistenceGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import {
removeLock,
} from './persistence/dynamo/locks/acquireLock';
import { createMessage } from './persistence/dynamo/messages/createMessage';
import { createNewPetitionerUser } from './persistence/dynamo/users/createNewPetitionerUser';
import { createNewPractitionerUser } from './persistence/dynamo/users/createNewPractitionerUser';
import { createOrUpdatePractitionerUser } from './persistence/dynamo/users/createOrUpdatePractitionerUser';
import { createOrUpdateUser } from './persistence/dynamo/users/createOrUpdateUser';
import {
createOrUpdateUser,
createUserRecords,
} from './persistence/dynamo/users/createOrUpdateUser';
import { createPractitionerDocument } from './persistence/dynamo/practitioners/createPractitionerDocument';
import { createTrialSession } from './persistence/dynamo/trialSessions/createTrialSession';
import { createTrialSessionWorkingCopy } from './persistence/dynamo/trialSessions/createTrialSessionWorkingCopy';
Expand Down Expand Up @@ -229,13 +230,12 @@ const gatewayMethods = {
createCaseTrialSortMappingRecords,
createJobStatus,
createMessage,
createNewPetitionerUser,
createNewPractitionerUser,
createOrUpdatePractitionerUser,
createOrUpdateUser,
createPractitionerDocument,
createTrialSession,
createTrialSessionWorkingCopy,
createUserRecords,
deleteKeyCount,
editPractitionerDocument,
fetchPendingItems,
Expand Down

This file was deleted.

58 changes: 0 additions & 58 deletions web-api/src/persistence/dynamo/users/createNewPetitionerUser.ts

This file was deleted.

Loading

0 comments on commit 33dfca5

Please sign in to comment.