Skip to content

Commit

Permalink
Check usage of ?? ''.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkreuzkam-cap committed Jan 12, 2024
1 parent 4ffcc2d commit f7321fb
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class AccountResponseMapper {
id: resolvedAccount.id as string,
userId: resolvedAccount.userId,
activated: resolvedAccount.activated,
username: resolvedAccount.username ?? '',
username: resolvedAccount.username,
updatedAt: resolvedAccount.updatedAt,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ describe('account repo', () => {

it('should return account', async () => {
const accountToFind = await setup();
const account = await repo.findByUsernameAndSystemId(
accountToFind.username ?? '',
accountToFind.systemId ?? ''
);
const account = await repo.findByUsernameAndSystemId(accountToFind.username, accountToFind.systemId ?? '');
expect(account?.username).toEqual(accountToFind.username);
});
});
Expand Down
3 changes: 1 addition & 2 deletions apps/server/src/modules/account/review-comments.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Review Comments 14.7.23

- check ?? ''
- check names (fix dto naming)
- check TODOs
- Remove lookup service, move to idm and db
- Move Account Entity

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe('AccountDbService', () => {
const { mockAccountWithSystemId } = setup();
const resultAccount = await accountService.findByUsernameAndSystemId(
mockAccountWithSystemId.username,
'nonExistentSystemId' ?? ''
'nonExistentSystemId'
);
expect(resultAccount).toBeNull();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ describe('AccountService Integration', () => {
it('should create a new account', async () => {
if (!isIdmReachable) return;
const account = await accountService.save(testAccount);
await compareDbAccount(account.id ?? '', account);
await compareDbAccount(account.id, account);
await compareIdmAccount(account.idmReferenceId ?? '', account);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class AccountValidationService {
filteredAccounts.length > 1 ||
// paranoid 'toString': legacy code may call userId or accountId as ObjectID
(foundUsers.length === 1 && foundUsers[0].id.toString() !== userId?.toString()) ||
(filteredAccounts.length === 1 && (filteredAccounts[0].id ?? '').toString() !== accountId?.toString())
(filteredAccounts.length === 1 && filteredAccounts[0].id.toString() !== accountId?.toString())
);
}

Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/modules/account/uc/account.uc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export class AccountUc {
throw new ForbiddenOperationError('Current user is not authorized to delete an account.');
}
const account: Account = await this.accountService.findById(params.id);
await this.accountService.delete(account.id ?? '');
await this.accountService.delete(account.id);
return AccountUcMapper.mapToResolvedAccountDto(account);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class LdapStrategy extends PassportStrategy(Strategy, 'ldap') {

await this.checkCredentials(account, system, ldapDn, password);

const currentUser: ICurrentUser = CurrentUserMapper.userToICurrentUser(account.id ?? '', user, true, systemId);
const currentUser: ICurrentUser = CurrentUserMapper.userToICurrentUser(account.id, user, true, systemId);

return currentUser;
}
Expand Down Expand Up @@ -83,7 +83,7 @@ export class LdapStrategy extends PassportStrategy(Strategy, 'ldap') {
await this.ldapService.checkLdapCredentials(system, ldapDn, password);
} catch (error) {
if (error instanceof UnauthorizedException) {
await this.authenticationService.updateLastTriedFailedLogin(account.id ?? '');
await this.authenticationService.updateLastTriedFailedLogin(account.id);
}
throw error;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ export class LocalStrategy extends PassportStrategy(Strategy) {

const accountUserId = GuardAgainst.nullOrUndefined(
account.userId,
new Error(`login failing, because account ${account.id ?? ''} has no userId`)
new Error(`login failing, because account ${account.id} has no userId`)
);
const user = await this.userRepo.findById(accountUserId, true);
const currentUser = CurrentUserMapper.userToICurrentUser(account.id ?? '', user, false);
const currentUser = CurrentUserMapper.userToICurrentUser(account.id, user, false);
return currentUser;
}

Expand All @@ -58,7 +58,7 @@ export class LocalStrategy extends PassportStrategy(Strategy) {
): Promise<void | never> {
this.authenticationService.checkBrutForce(account);
if (!(await bcrypt.compare(enteredPassword, savedPassword))) {
await this.authenticationService.updateLastTriedFailedLogin(account.id ?? '');
await this.authenticationService.updateLastTriedFailedLogin(account.id);
throw new UnauthorizedException();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class Oauth2Strategy extends PassportStrategy(Strategy, 'oauth2') {
}

const currentUser: OauthCurrentUser = CurrentUserMapper.mapToOauthCurrentUser(
account.id ?? '',
account.id,
user,
systemId,
tokenDto.idToken
Expand Down
6 changes: 1 addition & 5 deletions apps/server/src/modules/user/service/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ export class UserService {
const user: UserDO = await this.findById(userId);
const account: Account = await this.accountService.findByUserIdOrFail(userId);

const resolvedUser: OauthCurrentUser = CurrentUserMapper.mapToOauthCurrentUser(
account.id ?? '',
user,
account.systemId
);
const resolvedUser: OauthCurrentUser = CurrentUserMapper.mapToOauthCurrentUser(account.id, user, account.systemId);

return resolvedUser;
}
Expand Down

0 comments on commit f7321fb

Please sign in to comment.