Skip to content

Commit

Permalink
Improvements get assigned programs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben committed Jun 12, 2024
1 parent 8b66641 commit 31c7f02
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ export class ProgramsListComponent implements OnInit {
private async refresh() {
this.loading = true;
const programIds = await this.programsService.getAllProgramIds();
this.programStats = await this.programsService.getAllProgramsStats(
programIds.map((id) => id),
this.programStats =
await this.programsService.getAllProgramsStats(programIds);
const programs = await Promise.all(
programIds.map((programId) =>
this.programsService.getProgramById(programId),
),
);
const programs = [];
for (const programId of programIds) {
const program = await this.programsService.getProgramById(programId);
programs.push(program);
}
this.items = this.translateProperties(programs).sort((a, b) =>
a.created <= b.created ? -1 : 1,
);
Expand Down
11 changes: 4 additions & 7 deletions services/121-service/src/programs/programs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { DefaultUserRole } from '@121-service/src/user/user-role.enum';
import { UserService } from '@121-service/src/user/user.service';
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { DataSource, In, QueryFailedError, Repository } from 'typeorm';
import { DataSource, QueryFailedError, Repository } from 'typeorm';

interface FoundProgram
extends Omit<
Expand Down Expand Up @@ -153,14 +153,11 @@ export class ProgramService {
const user =
await this.userService.findUserProgramAssignmentsOrThrow(userId);
const programIds = user.programAssignments.map((p) => p.program.id);
const programs = await this.programRepository.find({
where: { id: In(programIds) },
select: ['id'],
});
const programsCount = programs.length;

const programsCount = programIds.length;
return {
programsCount,
programIds: programs.map((p) => p.id),
programIds: programIds,
};
}

Expand Down

0 comments on commit 31c7f02

Please sign in to comment.