Skip to content

Commit e68d550

Browse files
[FEATURE] Autoriser une limite de date sur le script de récupération des décalages de live alerts (PIX-17051).
#11883
2 parents 3acc666 + ca17f1f commit e68d550

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Diff for: api/scripts/certification/fix-validated-live-alert-certification-challenge-ids.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ export class FixValidatedLiveAlertCertificationChallengeIds extends Script {
2828
demandOption: false,
2929
default: 100,
3030
},
31+
startingFromDate: {
32+
type: 'date',
33+
describe: 'allows to run the script only for certification-courses that happened after the given date',
34+
demandOption: true,
35+
default: new Date(2024, 10, 4),
36+
},
3137
},
3238
});
3339

@@ -39,7 +45,9 @@ export class FixValidatedLiveAlertCertificationChallengeIds extends Script {
3945
const dryRun = options.dryRun;
4046
const batchSize = options.batchSize;
4147
const delayInMs = options.delayBetweenBatch;
42-
this.logger.info(`dryRun=${dryRun}`);
48+
const startingFromDate = options.startingFromDate;
49+
50+
this.logger.info({ dryRun, batchSize, delayInMs, startingFromDate });
4351

4452
let hasNext = true;
4553
let cursorId = 0;
@@ -50,6 +58,7 @@ export class FixValidatedLiveAlertCertificationChallengeIds extends Script {
5058
const courseIds = await this.#getCourseIds({
5159
cursorId,
5260
batchSize,
61+
startingFromDate,
5362
transaction,
5463
});
5564

@@ -173,12 +182,14 @@ export class FixValidatedLiveAlertCertificationChallengeIds extends Script {
173182
};
174183
}
175184

176-
#getCourseIds({ cursorId, batchSize, transaction }) {
185+
#getCourseIds({ cursorId, batchSize, startingFromDate, transaction }) {
186+
this.logger.debug({ cursorId, batchSize, startingFromDate });
177187
return transaction
178188
.select('id')
179189
.from('certification-courses')
180190
.where('certification-courses.id', '>', cursorId)
181191
.andWhere('certification-courses.version', '=', AlgorithmEngineVersion.V3)
192+
.andWhere('certification-courses.createdAt', '>', startingFromDate)
182193
.orderBy('certification-courses.id')
183194
.limit(batchSize);
184195
}

Diff for: api/tests/integration/scripts/certification/fix-validated-live-alert-certification-challenge-ids_test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('Integration | Scripts | Certification | fix-validated-live-alert-certi
99
it('should fix the capacities challenges ids', async function () {
1010
// given
1111
const certificationCourseId = 321;
12-
const options = { dryRun: false, batchSize: 10 };
12+
const options = { dryRun: false, batchSize: 10, startingFromDate: new Date(2024, 10, 4) };
1313
const logger = {
1414
info: sinon.stub(),
1515
debug: sinon.stub(),
@@ -20,6 +20,7 @@ describe('Integration | Scripts | Certification | fix-validated-live-alert-certi
2020
id: certificationCourseId,
2121
userId: user.id,
2222
version: AlgorithmEngineVersion.V3,
23+
createdAt: new Date(2024, 10, 5),
2324
});
2425
const assessment = databaseBuilder.factory.buildAssessment({
2526
certificationCourseId: certificationCourse.id,

0 commit comments

Comments
 (0)