Skip to content

Commit

Permalink
[wip] add tz
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanfallon committed Feb 6, 2024
1 parent d9bd88d commit e1ae74a
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CREATE TABLE IF NOT EXISTS export.exports
(
_id serial PRIMARY KEY,
uuid uuid NOT NULL DEFAULT uuid_generate_v4(),
type varchar(255) NOT NULL DEFAULT 'opendata',
status varchar(255) NOT NULL DEFAULT 'pending',
progress integer NOT NULL DEFAULT 0,
created_by integer NOT NULL,
Expand Down
1 change: 0 additions & 1 deletion api/services/export/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ Les actions sur les exports sont enregistrées dans la table `logs` pour garder
_id
created_at
updated_at
deleted_at
created_by
uuid
status (pending|processing|uploading|sending|error|expired)
Expand Down
71 changes: 71 additions & 0 deletions api/services/export/src/commands/CreateCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { coerceDate } from '@ilos/cli';
import { CommandInterface, CommandOptionType, command } from '@ilos/common';
import { Timezone } from '@pdc/provider-validator';
import { ExportRepository, ExportType } from '../repositories/ExportRepository';

export type Options = {
creator: number;
type: ExportType;
operator_id?: number | null;
territory_id?: number | null;
start?: Date;
end?: Date;
tz: Timezone;
};

@command()
export class CreateCommand implements CommandInterface {
static readonly signature: string = 'export:create';
static readonly description: string = 'Create an export request';
static readonly options: CommandOptionType[] = [
{
signature: '-c, --creator <creator>',
description: 'User id',
},
{
signature: '-t, --type <type>',
description: 'Export type',
default: ExportType.OPENDATA,
},
{
signature: '-o, --operator_id <operator_id>',
description: 'Operator id',
default: null,
},
{
signature: '-tt, --territory_id <territory_id>',
description: 'Territory id',
default: null,
},
{
signature: '-s, --start <start>',
description: 'Start date (YYYY-MM-DD)',
default: null,
coerce: coerceDate,
},
{
signature: '-e, --end <end>',
description: 'End date (YYYY-MM-DD)',
default: null,
coerce: coerceDate,
},
{
signature: '--tz <tz>',
description: 'Output timezone',
default: 'Europe/Paris',
},
];

constructor(protected exportRepository: ExportRepository) {}

public async call(options: Options): Promise<void> {
// TODO
const { creator, type, operator_id, territory_id, start, end, tz } = options;
// TODO create ExportParams entity and pass it to the repository
await this.exportRepository.create({
created_by: creator,
type,
params,
});
}
}
13 changes: 4 additions & 9 deletions api/services/export/src/models/ExportParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TerritorySelectorsInterface } from '../shared/territory/common/interfaces/TerritoryCodeInterface';
import { Timezone } from '@pdc/provider-validator';
import { subMonthsTz, today } from '../helpers/shared/dates.helper';
import { TerritorySelectorsInterface } from '../shared/territory/common/interfaces/TerritoryCodeInterface';

export type Config = Partial<Params>;

Expand All @@ -8,10 +9,7 @@ export type Params = {
end_at: Date;
operator_id: number[];
geo_selector: TerritorySelectorsInterface;
user_id: number | null;
recipient_email?: string | null;
recipient_fullname?: string | null;
recipient_message?: string | null;
tz?: Timezone;
};

export class ExportParams {
Expand All @@ -24,10 +22,7 @@ export class ExportParams {
end_at: today(),
operator_id: [],
geo_selector: { country: ['XXXXX'] }, // FRANCE
user_id: null,
recipient_email: null,
recipient_fullname: null,
recipient_message: null,
tz: 'Europe/Paris',
};

constructor(protected config: Config) {
Expand Down
7 changes: 3 additions & 4 deletions api/services/export/src/repositories/ExportRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import { ExportParams } from '../models/ExportParams';

export type Export = {
_id: number;
created_at: Date;
updated_at: Date;
created_by: number;
uuid: string;
type: ExportType;
status: ExportStatus;
progress: number;
type: ExportType;
created_by: number;
download_url_expire_at: Date;
download_url: string;
params: ExportParams;
error: any;
Expand Down

0 comments on commit e1ae74a

Please sign in to comment.