Skip to content

Commit

Permalink
feat(api): replaced the two certification activation/deactivation bat…
Browse files Browse the repository at this point in the history
…ches by a single one
  • Loading branch information
agarbe committed Dec 13, 2024
1 parent 4998bc0 commit 27da3b2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 30 deletions.
6 changes: 2 additions & 4 deletions packages/reva-api/infra/cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import { batchPaymentRequestUnifvae } from "../modules/finance/unifvae/batches/p
import { batchPaymentRequest } from "../modules/finance/unireva/batches/paymentRequest";
import uploadSpoolerFiles from "../modules/finance/unireva/batches/paymentRequestProofJob";
import { sendReminderToCandidateWithScheduledJury } from "../modules/jury/features/sendReminderToCandidateWithScheduledJury";
import { deactivateCertificationsIfExpiresAtDateIsPast } from "../modules/referential/features/deactivateCertificationsIfExpiresAtDateIsPast";
import { makeCertificationsAvailableIfAvailableAtDateIsPast } from "../modules/referential/features/makeCertificationsAvailableIfAvailableAtDateIsPast";
import { setCertificationsVisibleOrNotUsingStatusAndAvailabilityDate } from "../modules/referential/features/setCertificationsVisibleOrNotUsingStatusAndAvailabilityDate";
import { logger } from "../modules/shared/logger";
import { prismaClient } from "../prisma/client";

Expand Down Expand Up @@ -110,8 +109,7 @@ CronJob.from({
batchKey: "batch.activate-or-deactivate-certifications",
batchCallback: async () => {
logger.info("Running activate-or-deactivate-certifications batch");
await makeCertificationsAvailableIfAvailableAtDateIsPast();
await deactivateCertificationsIfExpiresAtDateIsPast();
await setCertificationsVisibleOrNotUsingStatusAndAvailabilityDate();
},
}),
start: true,
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { startOfToday } from "date-fns";

import { prismaClient } from "../../../prisma/client";

export const setCertificationsVisibleOrNotUsingStatusAndAvailabilityDate = () =>
prismaClient.$transaction([
prismaClient.certification.updateMany({ data: { visible: false } }),
prismaClient.certification.updateMany({
where: {
status: "VALIDE_PAR_CERTIFICATEUR",
availableAt: { lte: startOfToday() },
expiresAt: { gt: startOfToday() },
},
data: { visible: true },
}),
]);

0 comments on commit 27da3b2

Please sign in to comment.