From ea1eff1e2f18888cfc02af2a3cde2f05c91a9621 Mon Sep 17 00:00:00 2001 From: Jonathan Fallon Date: Thu, 23 Jan 2025 15:37:46 +0100 Subject: [PATCH] fix: migrate command config to decorator (#2767) --- .../export/commands/DataGouvCommand.ts | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/api/src/pdc/services/export/commands/DataGouvCommand.ts b/api/src/pdc/services/export/commands/DataGouvCommand.ts index e1efe8117..0afd219e3 100644 --- a/api/src/pdc/services/export/commands/DataGouvCommand.ts +++ b/api/src/pdc/services/export/commands/DataGouvCommand.ts @@ -1,5 +1,5 @@ import { coerceDate } from "@/ilos/cli/index.ts"; -import { command, CommandInterface, CommandOptionType } from "@/ilos/common/index.ts"; +import { command, CommandInterface } from "@/ilos/common/index.ts"; import { logger } from "@/lib/logger/index.ts"; import { today, toTzString } from "@/pdc/helpers/dates.helper.ts"; import { Timezone } from "@/pdc/providers/validator/index.ts"; @@ -21,35 +21,35 @@ export type Options = { tz: Timezone; }; -@command() -export class DataGouvCommand implements CommandInterface { - static readonly signature: string = "export:datagouv"; - static readonly description: string = "Export opendata file and upload to data.gouv.fr"; - static readonly options: CommandOptionType[] = [ +function defaultDate(offset = 0): Date { + const now = today(); + return new Date(now.getFullYear(), now.getMonth() + offset, 1); +} + +@command({ + signature: "export:datagouv", + description: "Export opendata file and upload to data.gouv.fr", + options: [ { signature: "-s, --start ", description: "Start date (YYYY-MM-DD)", coerce: coerceDate, - default: DataGouvCommand.defaultDate(-1), + default: defaultDate(-1), }, { signature: "-e, --end ", description: "End date (YYYY-MM-DD)", coerce: coerceDate, - default: DataGouvCommand.defaultDate(0), + default: defaultDate(0), }, { signature: "--tz ", description: "Output timezone", default: "Europe/Paris", }, - ]; - - static defaultDate(offset = 0): Date { - const now = today(); - return new Date(now.getFullYear(), now.getMonth() + offset, 1); - } - + ], +}) +export class DataGouvCommand implements CommandInterface { constructor( protected exportRepository: ExportRepositoryInterfaceResolver, protected fileCreatorService: OpenDataFileCreatorServiceInterfaceResolver, @@ -98,8 +98,8 @@ export class DataGouvCommand implements CommandInterface { logger.error("Invalid date range. Defaults applied"); return [ExportParams.fromJSON({ - start_at: DataGouvCommand.defaultDate(-1), - end_at: DataGouvCommand.defaultDate(0), + start_at: defaultDate(-1), + end_at: defaultDate(0), tz, })]; }