Skip to content

Commit

Permalink
fix: ORV2-2202 Fix Account Claim for a deleted user (#1305)
Browse files Browse the repository at this point in the history
  • Loading branch information
praju-aot authored Apr 4, 2024
1 parent e5b21c7 commit b7f9132
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ export class UsersService {
await queryRunner.connect();
await queryRunner.startTransaction();
try {
const existingUser = await queryRunner.manager.findOne<User>(User, {
where: {
userGUID: currentUser.userGUID,
},
relations: {
companyUsers: true,
userContact: true,
},
});

let user = this.classMapper.map(createUserDto, CreateUserDto, User, {
extraArgs: () => ({
userAuthGroup: GenericUserAuthGroup.PUBLIC_VERIFIED,
Expand All @@ -124,7 +134,11 @@ export class UsersService {
}),
});

user.userContact.contactId = existingUser?.userContact?.contactId;

const newCompanyUser = new CompanyUser();
newCompanyUser.companyUserId =
existingUser?.companyUsers?.at(0)?.companyUserId;
newCompanyUser.company = new Company();
newCompanyUser.company.companyId = companyId;
newCompanyUser.statusCode = UserStatus.ACTIVE;
Expand Down
1 change: 1 addition & 0 deletions vehicles/test/unit/users/users.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe('UsersService', () => {
delete: jest.fn(),
update: jest.fn(),
find: jest.fn(),
findOne: jest.fn(),
save: jest.fn(),
};

Expand Down
2 changes: 2 additions & 0 deletions vehicles/test/util/mocks/factory/dataSource.factory.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type MockQueryRunnerManager = {
delete: jest.Mock;
update: jest.Mock;
find: jest.Mock;
findOne?: jest.Mock;
save: jest.Mock;
};

Expand All @@ -37,6 +38,7 @@ export const dataSourceMockFactory = () => {
manager: {
delete: jest.fn(),
update: jest.fn(),
findOne: jest.fn(),
save: jest.fn((saveObject: object) => {
if (saveObject instanceof Company) {
if (saveObject.legalName === constants.RED_COMPANY_LEGAL_NAME) {
Expand Down

0 comments on commit b7f9132

Please sign in to comment.