Skip to content

Commit

Permalink
fix: migrate command config to decorator (#2767)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanfallon authored Jan 23, 2025
1 parent 77ad631 commit ea1eff1
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions api/src/pdc/services/export/commands/DataGouvCommand.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 <start>",
description: "Start date (YYYY-MM-DD)",
coerce: coerceDate,
default: DataGouvCommand.defaultDate(-1),
default: defaultDate(-1),
},
{
signature: "-e, --end <end>",
description: "End date (YYYY-MM-DD)",
coerce: coerceDate,
default: DataGouvCommand.defaultDate(0),
default: defaultDate(0),
},
{
signature: "--tz <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,
Expand Down Expand Up @@ -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,
})];
}
Expand Down

0 comments on commit ea1eff1

Please sign in to comment.