Skip to content

Commit

Permalink
EW-1019 Fix Linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
SimoneRadtke-Cap committed Dec 11, 2024
1 parent a9669a5 commit 3633cc0
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,29 @@ export class AccountServiceDb extends AbstractAccountService {
super();
}

async findById(id: EntityId): Promise<Account> {
public async findById(id: EntityId): Promise<Account> {
const internalId = await this.getInternalId(id);

return this.accountRepo.findById(internalId);
}

async findMultipleByUserId(userIds: EntityId[]): Promise<Account[]> {
public findMultipleByUserId(userIds: EntityId[]): Promise<Account[]> {
return this.accountRepo.findMultipleByUserId(userIds);
}

async findByUserId(userId: EntityId): Promise<Account | null> {
public findByUserId(userId: EntityId): Promise<Account | null> {
return this.accountRepo.findByUserId(userId);
}

async findByUserIdOrFail(userId: EntityId): Promise<Account> {
public findByUserIdOrFail(userId: EntityId): Promise<Account> {
return this.accountRepo.findByUserIdOrFail(userId);
}

async findByUsernameAndSystemId(username: string, systemId: EntityId | ObjectId): Promise<Account | null> {
public findByUsernameAndSystemId(username: string, systemId: EntityId | ObjectId): Promise<Account | null> {
return this.accountRepo.findByUsernameAndSystemId(username, systemId);
}

async save(accountSave: AccountSave): Promise<Account> {
public async save(accountSave: AccountSave): Promise<Account> {
let account: Account;
if (accountSave.id) {
const internalId = await this.getInternalId(accountSave.id);
Expand All @@ -56,31 +56,31 @@ export class AccountServiceDb extends AbstractAccountService {
return this.accountRepo.save(account);
}

async updateUsername(accountId: EntityId, username: string): Promise<Account> {
public async updateUsername(accountId: EntityId, username: string): Promise<Account> {
const internalId = await this.getInternalId(accountId);
const account = await this.accountRepo.findById(internalId);
account.username = username;
await this.accountRepo.save(account);
return account;
}

async updateLastLogin(accountId: EntityId, lastLogin: Date): Promise<Account> {
public async updateLastLogin(accountId: EntityId, lastLogin: Date): Promise<Account> {
const internalId = await this.getInternalId(accountId);
const account = await this.accountRepo.findById(internalId);
account.lastLogin = lastLogin;
await this.accountRepo.save(account);
return account;
}

async updateLastTriedFailedLogin(accountId: EntityId, lastTriedFailedLogin: Date): Promise<Account> {
public async updateLastTriedFailedLogin(accountId: EntityId, lastTriedFailedLogin: Date): Promise<Account> {
const internalId = await this.getInternalId(accountId);
const account = await this.accountRepo.findById(internalId);
account.lasttriedFailedLogin = lastTriedFailedLogin;
await this.accountRepo.save(account);
return account;
}

async updatePassword(accountId: EntityId, password: string): Promise<Account> {
public async updatePassword(accountId: EntityId, password: string): Promise<Account> {
const internalId = await this.getInternalId(accountId);
const account = await this.accountRepo.findById(internalId);
account.password = await this.encryptPassword(password);
Expand All @@ -89,24 +89,24 @@ export class AccountServiceDb extends AbstractAccountService {
return account;
}

async delete(id: EntityId): Promise<void> {
public async delete(id: EntityId): Promise<void> {
const internalId = await this.getInternalId(id);
return this.accountRepo.deleteById(internalId);
}

async deleteByUserId(userId: EntityId): Promise<EntityId[]> {
public deleteByUserId(userId: EntityId): Promise<EntityId[]> {
return this.accountRepo.deleteByUserId(userId);
}

async searchByUsernamePartialMatch(userName: string, skip: number, limit: number): Promise<Counted<Account[]>> {
public searchByUsernamePartialMatch(userName: string, skip: number, limit: number): Promise<Counted<Account[]>> {
return this.accountRepo.searchByUsernamePartialMatch(userName, skip, limit);
}

async searchByUsernameExactMatch(userName: string): Promise<Counted<Account[]>> {
public searchByUsernameExactMatch(userName: string): Promise<Counted<Account[]>> {
return this.accountRepo.searchByUsernameExactMatch(userName);
}

validatePassword(account: Account, comparePassword: string): Promise<boolean> {
public validatePassword(account: Account, comparePassword: string): Promise<boolean> {
if (!account.password) {
return Promise.resolve(false);
}
Expand Down Expand Up @@ -137,7 +137,7 @@ export class AccountServiceDb extends AbstractAccountService {
return bcrypt.hash(password, 10);
}

async findMany(offset = 0, limit = 100): Promise<Account[]> {
public findMany(offset = 0, limit = 100): Promise<Account[]> {
return this.accountRepo.findMany(offset, limit);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export class AccountServiceIdm extends AbstractAccountService {
super();
}

async findById(id: EntityId): Promise<Account> {
public async findById(id: EntityId): Promise<Account> {
const result = await this.identityManager.findAccountById(id);
const account = this.accountIdmToDoMapper.mapToDo(result);
return account;
}

async findMultipleByUserId(userIds: EntityId[]): Promise<Account[]> {
public async findMultipleByUserId(userIds: EntityId[]): Promise<Account[]> {
const resultAccounts = new Array<Account>();

const promises = userIds.map((userId) => this.identityManager.findAccountByDbcUserId(userId).catch(() => null));
Expand All @@ -48,7 +48,7 @@ export class AccountServiceIdm extends AbstractAccountService {
return resultAccounts;
}

async findByUserId(userId: EntityId): Promise<Account | null> {
public async findByUserId(userId: EntityId): Promise<Account | null> {
try {
const result = await this.identityManager.findAccountByDbcUserId(userId);
return this.accountIdmToDoMapper.mapToDo(result);
Expand All @@ -58,7 +58,7 @@ export class AccountServiceIdm extends AbstractAccountService {
}
}

async findByUserIdOrFail(userId: EntityId): Promise<Account> {
public async findByUserIdOrFail(userId: EntityId): Promise<Account> {
try {
const result = await this.identityManager.findAccountByDbcUserId(userId);
return this.accountIdmToDoMapper.mapToDo(result);
Expand All @@ -67,33 +67,37 @@ export class AccountServiceIdm extends AbstractAccountService {
}
}

async findByUsernameAndSystemId(username: string, systemId: EntityId | ObjectId): Promise<Account | null> {
public async findByUsernameAndSystemId(username: string, systemId: EntityId | ObjectId): Promise<Account | null> {
const [accounts] = await this.searchByUsernameExactMatch(username);
const account = accounts.find((tempAccount) => tempAccount.systemId === systemId) || null;
return account;
}

async searchByUsernamePartialMatch(userName: string, skip: number, limit: number): Promise<Counted<Account[]>> {
public async searchByUsernamePartialMatch(
userName: string,
skip: number,
limit: number
): Promise<Counted<Account[]>> {
const [results, total] = await this.identityManager.findAccountsByUsername(userName, { skip, limit, exact: false });
const accounts = results.map((result) => this.accountIdmToDoMapper.mapToDo(result));
return [accounts, total];
}

async searchByUsernameExactMatch(userName: string): Promise<Counted<Account[]>> {
public async searchByUsernameExactMatch(userName: string): Promise<Counted<Account[]>> {
const [results, total] = await this.identityManager.findAccountsByUsername(userName, { exact: true });
const accounts = results.map((result) => this.accountIdmToDoMapper.mapToDo(result));
return [accounts, total];
}

async updateLastTriedFailedLogin(accountId: EntityId, lastTriedFailedLogin: Date): Promise<Account> {
public async updateLastTriedFailedLogin(accountId: EntityId, lastTriedFailedLogin: Date): Promise<Account> {
const attributeName = 'lastTriedFailedLogin';
const id = await this.getIdmAccountId(accountId);
await this.identityManager.setUserAttribute(id, attributeName, lastTriedFailedLogin.toISOString());
const updatedAccount = await this.identityManager.findAccountById(id);
return this.accountIdmToDoMapper.mapToDo(updatedAccount);
}

async save(accountSave: AccountSave): Promise<Account> {
public async save(accountSave: AccountSave): Promise<Account> {
let accountId: string;
const idmAccount: IdmAccountUpdate = {
username: accountSave.username,
Expand Down Expand Up @@ -130,39 +134,39 @@ export class AccountServiceIdm extends AbstractAccountService {
return accountId;
}

async updateUsername(accountRefId: EntityId, username: string): Promise<Account> {
public async updateUsername(accountRefId: EntityId, username: string): Promise<Account> {
const id = await this.getIdmAccountId(accountRefId);
await this.identityManager.updateAccount(id, { username });
const updatedAccount = await this.identityManager.findAccountById(id);
return this.accountIdmToDoMapper.mapToDo(updatedAccount);
}

async updatePassword(accountRefId: EntityId, password: string): Promise<Account> {
public async updatePassword(accountRefId: EntityId, password: string): Promise<Account> {
const id = await this.getIdmAccountId(accountRefId);
await this.identityManager.updateAccountPassword(id, password);
const updatedAccount = await this.identityManager.findAccountById(id);
return this.accountIdmToDoMapper.mapToDo(updatedAccount);
}

async validatePassword(account: Account, comparePassword: string): Promise<boolean> {
public async validatePassword(account: Account, comparePassword: string): Promise<boolean> {
const jwt = await this.idmOauthService.resourceOwnerPasswordGrant(account.username, comparePassword);
return jwt !== undefined;
}

async delete(accountRefId: EntityId): Promise<void> {
public async delete(accountRefId: EntityId): Promise<void> {
const id = await this.getIdmAccountId(accountRefId);
await this.identityManager.deleteAccountById(id);
}

async deleteByUserId(userId: EntityId): Promise<EntityId[]> {
public async deleteByUserId(userId: EntityId): Promise<EntityId[]> {
const idmAccount = await this.identityManager.findAccountByDbcUserId(userId);
const deletedAccountId = await this.identityManager.deleteAccountById(idmAccount.id);

return [deletedAccountId];
}

// eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars
async findMany(_offset: number, _limit: number): Promise<Account[]> {
public findMany(_offset: number, _limit: number): Promise<Account[]> {
throw new NotImplementedException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,49 @@ export abstract class AbstractAccountService {
* The following methods are only needed by nest
*/

abstract searchByUsernamePartialMatch(userName: string, skip: number, limit: number): Promise<Counted<Account[]>>;
public abstract searchByUsernamePartialMatch(
userName: string,
skip: number,
limit: number
): Promise<Counted<Account[]>>;

abstract validatePassword(account: Account, comparePassword: string): Promise<boolean>;
public abstract validatePassword(account: Account, comparePassword: string): Promise<boolean>;
/**
* @deprecated For migration purpose only
*/
abstract findMany(offset?: number, limit?: number): Promise<Account[]>;
public abstract findMany(offset?: number, limit?: number): Promise<Account[]>;

/*
* The following methods are also needed by feathers
*/

abstract findById(id: EntityId): Promise<Account>;
public abstract findById(id: EntityId): Promise<Account>;

abstract findMultipleByUserId(userIds: EntityId[]): Promise<Account[]>;
public abstract findMultipleByUserId(userIds: EntityId[]): Promise<Account[]>;

abstract findByUserId(userId: EntityId): Promise<Account | null>;
public abstract findByUserId(userId: EntityId): Promise<Account | null>;

abstract findByUserIdOrFail(userId: EntityId): Promise<Account>;
public abstract findByUserIdOrFail(userId: EntityId): Promise<Account>;

// HINT: it would be preferable to use entityId here. Needs to be checked if this is blocked by lecacy code
abstract findByUsernameAndSystemId(username: string, systemId: EntityId | ObjectId): Promise<Account | null>;
public abstract findByUsernameAndSystemId(username: string, systemId: EntityId | ObjectId): Promise<Account | null>;

abstract save(accountSave: AccountSave): Promise<Account>;
public abstract save(accountSave: AccountSave): Promise<Account>;

abstract updateUsername(accountId: EntityId, username: string): Promise<Account>;
public abstract updateUsername(accountId: EntityId, username: string): Promise<Account>;

/**
* @deprecated Used for brute force detection, but will become subject to IDM thus be removed.
*/
abstract updateLastTriedFailedLogin(accountId: EntityId, lastTriedFailedLogin: Date): Promise<Account>;
public abstract updateLastTriedFailedLogin(accountId: EntityId, lastTriedFailedLogin: Date): Promise<Account>;

abstract updatePassword(accountId: EntityId, password: string): Promise<Account>;
public abstract updatePassword(accountId: EntityId, password: string): Promise<Account>;

abstract delete(id: EntityId): Promise<void>;
public abstract delete(id: EntityId): Promise<void>;

abstract deleteByUserId(userId: EntityId): Promise<EntityId[]>;
public abstract deleteByUserId(userId: EntityId): Promise<EntityId[]>;

abstract searchByUsernameExactMatch(userName: string): Promise<Counted<Account[]>>;
public abstract searchByUsernameExactMatch(userName: string): Promise<Counted<Account[]>>;

abstract isUniqueEmail(email: string): Promise<boolean>;
public abstract isUniqueEmail(email: string): Promise<boolean>;
}
Loading

0 comments on commit 3633cc0

Please sign in to comment.