Skip to content

Commit

Permalink
chore: clean up following boy scout rule
Browse files Browse the repository at this point in the history
  • Loading branch information
hoeppner-dataport committed Dec 5, 2024
1 parent f6a1c1e commit db187e8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
47 changes: 25 additions & 22 deletions apps/server/src/modules/user/service/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ export class UserService implements DeletionService, IEventHandler<UserDeletedEv
await this.eventBus.publish(new DataDeletedEvent(deletionRequestId, dataDeleted));
}

async getUserEntityWithRoles(userId: EntityId): Promise<User> {
public async getUserEntityWithRoles(userId: EntityId): Promise<User> {
// only roles required, no need for the other populates
const userWithRoles = await this.userRepo.findById(userId, true);

return userWithRoles;
}

async me(userId: EntityId): Promise<[User, string[]]> {
public async me(userId: EntityId): Promise<[User, string[]]> {
const user = await this.userRepo.findById(userId, true);
const permissions = user.resolvePermissions();

Expand All @@ -73,20 +73,20 @@ export class UserService implements DeletionService, IEventHandler<UserDeletedEv
/**
* @deprecated use {@link UserService.findById} instead
*/
async getUser(id: string): Promise<UserDto> {
public async getUser(id: string): Promise<UserDto> {
const userEntity = await this.userRepo.findById(id, true);
const userDto = UserMapper.mapFromEntityToDto(userEntity);

return userDto;
}

async findById(id: string): Promise<UserDO> {
public async findById(id: string): Promise<UserDO> {
const userDO = await this.userDORepo.findById(id, true);

return userDO;
}

async findByIds(ids: string[]): Promise<UserDO[]> {
public async findByIds(ids: string[]): Promise<UserDO[]> {
const userDOs = await this.userDORepo.findByIds(ids, true);

return userDOs;
Expand All @@ -98,25 +98,25 @@ export class UserService implements DeletionService, IEventHandler<UserDeletedEv
return userDO;
}

async save(user: UserDO): Promise<UserDO> {
const savedUser: Promise<UserDO> = this.userDORepo.save(user);
public async save(user: UserDO): Promise<UserDO> {
const savedUser = await this.userDORepo.save(user);

return savedUser;
}

async saveAll(users: UserDO[]): Promise<UserDO[]> {
const savedUsers: Promise<UserDO[]> = this.userDORepo.saveAll(users);
public async saveAll(users: UserDO[]): Promise<UserDO[]> {
const savedUsers = await this.userDORepo.saveAll(users);

return savedUsers;
}

async findUsers(query: UserQuery, options?: IFindOptions<UserDO>): Promise<Page<UserDO>> {
public async findUsers(query: UserQuery, options?: IFindOptions<UserDO>): Promise<Page<UserDO>> {
const users: Page<UserDO> = await this.userDORepo.find(query, options);

return users;
}

async findBySchoolRole(
public async findBySchoolRole(
schoolId: EntityId,
roleName: RoleName,
options?: IFindOptions<UserDO>
Expand All @@ -127,7 +127,7 @@ export class UserService implements DeletionService, IEventHandler<UserDeletedEv
return result;
}

async findPublicTeachersBySchool(schoolId: EntityId, options?: IFindOptions<UserDO>): Promise<Page<UserDO>> {
public async findPublicTeachersBySchool(schoolId: EntityId, options?: IFindOptions<UserDO>): Promise<Page<UserDO>> {
const discoverabilitySetting = this.configService.get<string>('TEACHER_VISIBILITY_FOR_EXTERNAL_TEAM_INVITATION');
if (discoverabilitySetting === 'disabled') {
return new Page<UserDO>([], 0);
Expand All @@ -147,7 +147,7 @@ export class UserService implements DeletionService, IEventHandler<UserDeletedEv
return result;
}

async addSecondarySchoolToUsers(userIds: string[], schoolId: EntityId): Promise<void> {
public async addSecondarySchoolToUsers(userIds: string[], schoolId: EntityId): Promise<void> {
const users = await this.userDORepo.findByIds(userIds, true);
const guestStudent = await this.roleService.findByName(RoleName.GUESTSTUDENT);
const guestTeacher = await this.roleService.findByName(RoleName.GUESTTEACHER);
Expand Down Expand Up @@ -185,19 +185,19 @@ export class UserService implements DeletionService, IEventHandler<UserDeletedEv
return Promise.resolve();
}

async findByExternalId(externalId: string, systemId: EntityId): Promise<UserDO | null> {
const user: Promise<UserDO | null> = this.userDORepo.findByExternalId(externalId, systemId);
public async findByExternalId(externalId: string, systemId: EntityId): Promise<UserDO | null> {
const user = await this.userDORepo.findByExternalId(externalId, systemId);

return user;
}

async findByEmail(email: string): Promise<UserDO[]> {
const user: Promise<UserDO[]> = this.userDORepo.findByEmail(email);
public async findByEmail(email: string): Promise<UserDO[]> {
const user = await this.userDORepo.findByEmail(email);

return user;
}

async getDisplayName(user: UserDO): Promise<string> {
public async getDisplayName(user: UserDO): Promise<string> {
const protectedRoles: RoleDto[] = await this.roleService.getProtectedRoles();
const isProtectedUser: boolean = user.roles.some(
(roleRef: RoleReference): boolean =>
Expand All @@ -209,7 +209,7 @@ export class UserService implements DeletionService, IEventHandler<UserDeletedEv
return displayName;
}

async patchLanguage(userId: EntityId, newLanguage: LanguageType): Promise<boolean> {
public async patchLanguage(userId: EntityId, newLanguage: LanguageType): Promise<boolean> {
this.checkAvailableLanguages(newLanguage);
const user = await this.userRepo.findById(userId);
user.language = newLanguage;
Expand Down Expand Up @@ -281,7 +281,7 @@ export class UserService implements DeletionService, IEventHandler<UserDeletedEv
}

public async getParentEmailsFromUser(userId: EntityId): Promise<string[]> {
const parentEmails = this.userRepo.getParentEmailsFromUser(userId);
const parentEmails = await this.userRepo.getParentEmailsFromUser(userId);

return parentEmails;
}
Expand All @@ -293,7 +293,9 @@ export class UserService implements DeletionService, IEventHandler<UserDeletedEv
}

public async findMultipleByExternalIds(externalIds: string[]): Promise<string[]> {
return this.userRepo.findByExternalIds(externalIds);
const userIds = await this.userRepo.findByExternalIds(externalIds);

return userIds;
}

public async updateLastSyncedAt(userIds: string[]): Promise<void> {
Expand Down Expand Up @@ -326,7 +328,8 @@ export class UserService implements DeletionService, IEventHandler<UserDeletedEv
const unsyncedForMiliseconds = unsyncedForMinutes * 60000;
const differenceBetweenCurrentDateAndUnsyncedTime = new Date().getTime() - unsyncedForMiliseconds;
const dateOfLastSyncToBeLookedFrom = new Date(differenceBetweenCurrentDateAndUnsyncedTime);
return this.userRepo.findUnsynchronizedUserIds(dateOfLastSyncToBeLookedFrom);
const userIds = await this.userRepo.findUnsynchronizedUserIds(dateOfLastSyncToBeLookedFrom);
return userIds;
}

public async removeCalendarEvents(userId: EntityId): Promise<DomainDeletionReport> {
Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/shared/repo/user/user.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,16 @@ export class UserRepo extends BaseRepo<User> {
return users;
}

public async findByExternalIds(externalIds: string[]): Promise<string[]> {
public async findByExternalIds(externalIds: EntityId[]): Promise<EntityId[]> {
const foundUsers = await this._em.find(
User,
{ externalId: { $in: externalIds } },
{ fields: ['id', 'externalId'] }
);

const users = foundUsers.map(({ id }) => id);
const userIds = foundUsers.map(({ id }) => id);

return users;
return userIds;
}

public async updateAllUserByLastSyncedAt(userIds: string[]): Promise<void> {
Expand Down

0 comments on commit db187e8

Please sign in to comment.