Skip to content

Commit a3652b4

Browse files
feat(api): removed yargs deprecated methods
1 parent 32f61ac commit a3652b4

File tree

2 files changed

+8
-53
lines changed

2 files changed

+8
-53
lines changed

Diff for: api/scripts/prod/clean-ke-snapshots.js

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ function getKnowlegdeElementSnapshotCount() {
2929
return getKnowlegdeElementSnapshotsQuery().count({ count: 1 }).first();
3030
}
3131

32+
UPDATE products
33+
SET details = jsonb_set(details, '{specs,storage}', '"1TB SSD"')
34+
WHERE name = 'Laptop';
35+
3236
// Définition du script
3337
export class CleanKeSnapshotScript extends Script {
3438
constructor() {

Diff for: api/scripts/prod/generate-knowledge-element-snapshots-for-campaigns.js

+4-53
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import * as url from 'node:url';
22

3-
import yargs from 'yargs';
4-
53
import { disconnect, knex } from '../../db/knex-database-connection.js';
64
import * as knowledgeElementSnapshotRepository from '../../src/prescription/campaign/infrastructure/repositories/knowledge-element-snapshot-repository.js';
75
import { KnowledgeElementCollection } from '../../src/prescription/shared/domain/models/KnowledgeElementCollection.js';
@@ -12,39 +10,7 @@ import { PromiseUtils } from '../../src/shared/infrastructure/utils/promise-util
1210
const DEFAULT_MAX_SNAPSHOT_COUNT = 5000;
1311
const DEFAULT_CONCURRENCY = 3;
1412

15-
function _validateAndNormalizeMaxSnapshotCount(maxSnapshotCount) {
16-
if (isNaN(maxSnapshotCount)) {
17-
maxSnapshotCount = DEFAULT_MAX_SNAPSHOT_COUNT;
18-
}
19-
if (maxSnapshotCount <= 0 || maxSnapshotCount > 50000) {
20-
throw new Error(`Nombre max de snapshots ${maxSnapshotCount} ne peut pas être inférieur à 1 ni supérieur à 50000.`);
21-
}
22-
23-
return maxSnapshotCount;
24-
}
25-
26-
function _validateAndNormalizeConcurrency(concurrency) {
27-
if (isNaN(concurrency)) {
28-
concurrency = DEFAULT_CONCURRENCY;
29-
}
30-
if (concurrency <= 0 || concurrency > 10) {
31-
throw new Error(`Concurrent ${concurrency} ne peut pas être inférieur à 1 ni supérieur à 10.`);
32-
}
33-
34-
return concurrency;
35-
}
36-
37-
function _validateAndNormalizeArgs({ concurrency, maxSnapshotCount }) {
38-
const finalMaxSnapshotCount = _validateAndNormalizeMaxSnapshotCount(maxSnapshotCount);
39-
const finalConcurrency = _validateAndNormalizeConcurrency(concurrency);
40-
41-
return {
42-
maxSnapshotCount: finalMaxSnapshotCount,
43-
concurrency: finalConcurrency,
44-
};
45-
}
46-
47-
async function getEligibleCampaignParticipations(maxSnapshotCount) {
13+
async function getEligibleCampaignParticipations(maxSnapshotCount = DEFAULT_MAX_SNAPSHOT_COUNT) {
4814
return knex('campaign-participations')
4915
.select('campaign-participations.id', 'campaign-participations.userId', 'campaign-participations.sharedAt')
5016
.leftJoin(
@@ -60,7 +26,7 @@ async function getEligibleCampaignParticipations(maxSnapshotCount) {
6026

6127
async function generateKnowledgeElementSnapshots(
6228
campaignParticipationData,
63-
concurrency,
29+
concurrency = DEFAULT_CONCURRENCY,
6430
dependencies = { knowledgeElementRepository, knowledgeElementSnapshotRepository },
6531
) {
6632
return PromiseUtils.map(
@@ -90,23 +56,9 @@ const modulePath = url.fileURLToPath(import.meta.url);
9056
const isLaunchedFromCommandLine = process.argv[1] === modulePath;
9157

9258
async function main() {
93-
const commandLineArgs = yargs
94-
.option('maxSnapshotCount', {
95-
description: 'Nombre de snapshots max. à générer.',
96-
type: 'number',
97-
default: DEFAULT_MAX_SNAPSHOT_COUNT,
98-
})
99-
.option('concurrency', {
100-
description: 'Concurrence',
101-
type: 'number',
102-
default: DEFAULT_CONCURRENCY,
103-
})
104-
.help().argv;
105-
const { maxSnapshotCount, concurrency } = _validateAndNormalizeArgs(commandLineArgs);
106-
107-
const campaignParticipationData = await getEligibleCampaignParticipations(maxSnapshotCount);
59+
const campaignParticipationData = await getEligibleCampaignParticipations();
10860

109-
await generateKnowledgeElementSnapshots(campaignParticipationData, concurrency);
61+
await generateKnowledgeElementSnapshots(campaignParticipationData);
11062
}
11163

11264
(async () => {
@@ -115,7 +67,6 @@ async function main() {
11567
await main();
11668
} catch (error) {
11769
console.error('\x1b[31mErreur : %s\x1b[0m', error.message);
118-
yargs.showHelp();
11970
process.exitCode = 1;
12071
} finally {
12172
await disconnect();

0 commit comments

Comments
 (0)