Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions migrations/1775842011163-migrations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class Migrations1775842011163 implements MigrationInterface {
name = 'Migrations1775842011163';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "cohort" DROP COLUMN "endDate"`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "cohort" ADD "endDate" TIMESTAMP WITH TIME ZONE`,
);
await queryRunner.query(`
UPDATE "cohort" c
SET "endDate" = (
SELECT MAX(cw."scheduledDate")
FROM "cohort_week" cw
WHERE cw."cohortId" = c."id"
)
`);
await queryRunner.query(
`ALTER TABLE "cohort" ALTER COLUMN "endDate" SET NOT NULL`,
);
}
}
2 changes: 1 addition & 1 deletion src/certificates/certificates-generation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class CertificatesGenerationService {
certificate.name,
certificate.cohort.type,
certificate.type,
certificate.cohort.endDate,
certificate.cohort.getEndDate(),
certificate.withExercises,
certificate.rank,
);
Expand Down
9 changes: 5 additions & 4 deletions src/certificates/certificates.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ export class CertificatesService {
): Promise<{ cohort: Cohort; certificateEntities: Certificate[] }> {
const cohort = await this.cohortRepository.findOne({
where: { id: cohortId },
relations: { weeks: true },
});

if (!cohort) {
throw new ServiceError(`Cohort with id ${cohortId} not found`);
}

if (cohort.endDate > new Date()) {
if (cohort.getEndDate() > new Date()) {
throw new BadRequestException(
`Cohort with id ${cohortId} has not ended yet. Certificates can only be generated after the cohort ends.`,
);
Expand Down Expand Up @@ -212,7 +213,7 @@ export class CertificatesService {

const certificates = await this.certificateRepository.find({
where: { cohort: { id: cohortId } },
relations: { cohort: true, user: true },
relations: { cohort: { weeks: true }, user: true },
});

if (certificates.length === 0) {
Expand Down Expand Up @@ -279,7 +280,7 @@ export class CertificatesService {
const certificate = await this.certificateRepository.findOne({
where: { id },
relations: {
cohort: true,
cohort: { weeks: true },
user: true,
},
});
Expand Down Expand Up @@ -310,7 +311,7 @@ export class CertificatesService {
}> {
const certificates = await this.certificateRepository.find({
where: { cohort: { id: cohortId } },
relations: { cohort: true, user: true },
relations: { cohort: { weeks: true }, user: true },
});

if (certificates.length === 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/cohorts/cohort-reminder.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@

const cohort = await this.cohortRepository.findOne({
where: { id: cohortId },
relations: { users: true },
relations: { users: true, weeks: true },
});

if (!cohort) {
Expand Down Expand Up @@ -234,7 +234,7 @@
user.discordUserName;

await this.mailService.sendCohortFeedbackReminderEmail(
user.email!,

Check warning on line 237 in src/cohorts/cohort-reminder.service.ts

View workflow job for this annotation

GitHub Actions / check-formatting-and-lint

Forbidden non-null assertion

Check warning on line 237 in src/cohorts/cohort-reminder.service.ts

View workflow job for this annotation

GitHub Actions / check-formatting-and-lint

Forbidden non-null assertion

Check warning on line 237 in src/cohorts/cohort-reminder.service.ts

View workflow job for this annotation

GitHub Actions / check-formatting-and-lint

Forbidden non-null assertion
userName,
cohortName,
season,
Expand Down Expand Up @@ -271,7 +271,7 @@
const nextExecuteOnTime = new Date(task.executeOnTime);
nextExecuteOnTime.setUTCDate(nextExecuteOnTime.getUTCDate() + 7);

const cutoffDate = new Date(cohort.endDate);
const cutoffDate = new Date(cohort.getEndDate());
cutoffDate.setUTCDate(cutoffDate.getUTCDate() + 7);

if (nextExecuteOnTime <= cutoffDate) {
Expand Down
2 changes: 1 addition & 1 deletion src/cohorts/cohorts.response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class GetCohortResponseDto {
type: cohort.type,
season: cohort.season,
startDate: cohort.startDate.toISOString(),
endDate: cohort.endDate.toISOString(),
endDate: cohort.getEndDate().toISOString(),
registrationDeadline: cohort.registrationDeadline.toISOString(),
hasExercises: cohort.hasExercises,
classroomId: cohort.classroomId ?? null,
Expand Down
10 changes: 2 additions & 8 deletions src/cohorts/cohorts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class CohortsService {
type: cohort.type,
season: cohort.season,
startDate: cohort.startDate.toISOString(),
endDate: cohort.endDate.toISOString(),
endDate: cohort.getEndDate().toISOString(),
registrationDeadline:
cohort.registrationDeadline.toISOString(),
}),
Expand Down Expand Up @@ -189,6 +189,7 @@ export class CohortsService {
async listPublicCohorts(): Promise<ListAvailableCohortsResponseDto> {
const latestCohorts = await this.cohortRepository
.createQueryBuilder('c')
.leftJoinAndSelect('c.weeks', 'weeks')
.distinctOn(['c.type'])
.orderBy('c.type', 'ASC')
.addOrderBy('c.season', 'DESC')
Expand Down Expand Up @@ -303,7 +304,6 @@ export class CohortsService {
cohort.type = cohortData.type;
cohort.season = season;
cohort.startDate = startDate;
cohort.endDate = endDate;
cohort.registrationDeadline = registrationDeadline;
cohort.hasExercises = hasExercises;
cohort.weeks = [];
Expand Down Expand Up @@ -411,12 +411,6 @@ export class CohortsService {
const startDate = new Date(cohortData.startDate);
startDate.setUTCHours(0, 0, 0, 0);
cohort.startDate = startDate;

const config = this.cohortConfigService.getConfig(cohort.type);
const totalWeeks = config.gdSessions + 2;
const endDate = new Date(startDate);
endDate.setUTCDate(endDate.getUTCDate() + totalWeeks * 7);
cohort.endDate = endDate;
}
if (cohortData.registrationDeadline) {
const registrationDeadline = new Date(
Expand Down
11 changes: 8 additions & 3 deletions src/entities/cohort.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,20 @@ export class Cohort extends BaseEntity {
@Column('timestamptz')
startDate!: Date;

@Column('timestamptz')
endDate!: Date;

@Column('boolean')
hasExercises!: boolean;

@Column('text', { nullable: true })
classroomId!: string | null;

getEndDate(): Date {
return this.weeks.reduce(
(max, week) =>
week.scheduledDate > max ? week.scheduledDate : max,
this.weeks[0].scheduledDate,
);
}

@ManyToMany(() => User, (u) => u.cohorts)
@JoinTable()
users!: User[];
Expand Down
2 changes: 1 addition & 1 deletion src/github-classroom/github-classroom.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class GitHubClassroomService {
}

const endDatePlusBuffer = new Date(
cohort.endDate.getTime() + TWENTY_FOUR_HOURS_MS,
cohort.getEndDate().getTime() + TWENTY_FOUR_HOURS_MS,
);
const hasCohortEnded = endDatePlusBuffer < new Date();

Expand Down
Loading