diff --git a/manifest.webapp b/manifest.webapp index f7fe1536b7353c7a895e7dca8125fdc4fd931606..f7a68b6ad14da3ab2ae9cefb16b6509f0976794f 100644 --- a/manifest.webapp +++ b/manifest.webapp @@ -144,6 +144,11 @@ "type": "node", "file": "services/aggregatorUsageEvents/ecolyo.js", "trigger": "@cron 0 1 * * *" + }, + "aggregatorUsageEvents": { + "type": "node", + "file": "services/fluidsPrices/ecolyo.js", + "trigger": "@cron 0 1 * * *" } }, "permissions": { diff --git a/src/db/fluidPrices.json b/src/db/fluidPrices.json index e89009c6e1cfbb2032edbf36df48b0ac37513a86..de1187d530b9b13ebc410d69730c0cbbd46d9158 100644 --- a/src/db/fluidPrices.json +++ b/src/db/fluidPrices.json @@ -88,5 +88,347 @@ "price": 0.0919, "startDate": "2017-01-01T00:00:00.000Z", "endDate": "2017-01-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0915, + "startDate": "2017-02-01T00:00:00.000Z", + "endDate": "2017-02-28T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0932, + "startDate": "2017-03-01T00:00:00.000Z", + "endDate": "2017-03-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0927, + "startDate": "2017-04-01T00:00:00.000Z", + "endDate": "2017-04-30T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0906, + "startDate": "2017-05-01T00:00:00.000Z", + "endDate": "2017-05-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0906, + "startDate": "2017-06-01T00:00:00.000Z", + "endDate": "2017-06-30T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0788, + "startDate": "2017-07-01T00:00:00.000Z", + "endDate": "2017-07-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0783, + "startDate": "2017-08-01T00:00:00.000Z", + "endDate": "2017-08-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0783, + "startDate": "2017-09-01T00:00:00.000Z", + "endDate": "2017-09-30T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0791, + "startDate": "2017-10-01T00:00:00.000Z", + "endDate": "2017-10-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0806, + "startDate": "2017-11-01T00:00:00.000Z", + "endDate": "2017-11-30T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0812, + "startDate": "2017-12-01T00:00:00.000Z", + "endDate": "2017-12-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0857, + "startDate": "2018-01-01T00:00:00.000Z", + "endDate": "2018-01-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0866, + "startDate": "2018-02-01T00:00:00.000Z", + "endDate": "2018-02-28T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0847, + "startDate": "2018-03-01T00:00:00.000Z", + "endDate": "2018-03-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0839, + "startDate": "2018-04-01T00:00:00.000Z", + "endDate": "2018-04-30T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0842, + "startDate": "2018-05-01T00:00:00.000Z", + "endDate": "2018-05-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0855, + "startDate": "2018-06-01T00:00:00.000Z", + "endDate": "2018-06-30T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0959, + "startDate": "2018-07-01T00:00:00.000Z", + "endDate": "2018-07-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0961, + "startDate": "2018-08-01T00:00:00.000Z", + "endDate": "2018-08-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0967, + "startDate": "2018-09-01T00:00:00.000Z", + "endDate": "2018-09-30T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0989, + "startDate": "2018-10-01T00:00:00.000Z", + "endDate": "2018-10-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.1031, + "startDate": "2018-11-01T00:00:00.000Z", + "endDate": "2018-11-30T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.1013, + "startDate": "2018-12-01T00:00:00.000Z", + "endDate": "2018-12-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0999, + "startDate": "2019-01-01T00:00:00.000Z", + "endDate": "2019-01-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0993, + "startDate": "2019-02-01T00:00:00.000Z", + "endDate": "2019-02-28T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0993, + "startDate": "2019-03-01T00:00:00.000Z", + "endDate": "2019-03-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0977, + "startDate": "2019-04-01T00:00:00.000Z", + "endDate": "2019-04-30T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0973, + "startDate": "2019-05-01T00:00:00.000Z", + "endDate": "2019-05-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0969, + "startDate": "2019-06-01T00:00:00.000Z", + "endDate": "2019-06-30T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0795, + "startDate": "2019-07-01T00:00:00.000Z", + "endDate": "2019-07-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0791, + "startDate": "2019-08-01T00:00:00.000Z", + "endDate": "2019-08-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0785, + "startDate": "2019-09-01T00:00:00.000Z", + "endDate": "2019-09-30T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.077, + "startDate": "2019-10-01T00:00:00.000Z", + "endDate": "2019-10-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0789, + "startDate": "2019-11-01T00:00:00.000Z", + "endDate": "2019-11-30T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0793, + "startDate": "2019-12-01T00:00:00.000Z", + "endDate": "2019-12-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0787, + "startDate": "2020-01-01T00:00:00.000Z", + "endDate": "2020-01-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0765, + "startDate": "2020-02-01T00:00:00.000Z", + "endDate": "2020-02-29T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0736, + "startDate": "2020-03-01T00:00:00.000Z", + "endDate": "2020-03-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.071, + "startDate": "2020-04-01T00:00:00.000Z", + "endDate": "2020-04-30T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0703, + "startDate": "2020-05-01T00:00:00.000Z", + "endDate": "2020-05-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0687, + "startDate": "2020-06-01T00:00:00.000Z", + "endDate": "2020-06-30T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0698, + "startDate": "2020-07-01T00:00:00.000Z", + "endDate": "2020-07-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0705, + "startDate": "2020-08-01T00:00:00.000Z", + "endDate": "2020-08-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0709, + "startDate": "2020-09-01T00:00:00.000Z", + "endDate": "2020-09-30T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0735, + "startDate": "2020-10-01T00:00:00.000Z", + "endDate": "2020-10-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0745, + "startDate": "2020-11-01T00:00:00.000Z", + "endDate": "2020-11-30T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0759, + "startDate": "2020-12-01T00:00:00.000Z", + "endDate": "2020-12-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.076, + "startDate": "2021-01-01T00:00:00.000Z", + "endDate": "2021-01-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0782, + "startDate": "2021-02-01T00:00:00.000Z", + "endDate": "2021-02-28T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0818, + "startDate": "2021-03-01T00:00:00.000Z", + "endDate": "2021-03-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.079, + "startDate": "2021-04-01T00:00:00.000Z", + "endDate": "2021-04-30T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0797, + "startDate": "2021-05-01T00:00:00.000Z", + "endDate": "2021-05-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0826, + "startDate": "2021-06-01T00:00:00.000Z", + "endDate": "2021-06-30T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0895, + "startDate": "2021-07-01T00:00:00.000Z", + "endDate": "2021-07-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.0934, + "startDate": "2021-08-01T00:00:00.000Z", + "endDate": "2021-08-31T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.1002, + "startDate": "2021-09-01T00:00:00.000Z", + "endDate": "2021-09-30T23:59:59.000Z" + }, + { + "fluidType": 2, + "price": 0.1121, + "startDate": "2021-10-01T00:00:00.000Z", + "endDate": null } ] diff --git a/src/migrations/migration.data.ts b/src/migrations/migration.data.ts index f231c6e900c605ae0aec02cb4a0c4e5d34d0538a..bac8a282b3cf19c323cd7036298c9a92676376fc 100644 --- a/src/migrations/migration.data.ts +++ b/src/migrations/migration.data.ts @@ -242,6 +242,7 @@ export const migrations: Migration[] = [ description: 'Init new doctype fluidPrices', releaseNotes: null, docTypes: FLUIDPRICES_DOCTYPE, + isCreate: true, run: async (_client: Client, docs: any[]): Promise<any> => { for (const fluidPrice of fluidsPricesData) { await _client.create(FLUIDPRICES_DOCTYPE, fluidPrice) diff --git a/src/migrations/migration.ts b/src/migrations/migration.ts index 0e690905a0810202adce11cfb205e1d342680039..4faab391c864d590567c9854fffbc712bd783e48 100644 --- a/src/migrations/migration.ts +++ b/src/migrations/migration.ts @@ -152,6 +152,11 @@ export async function migrate( result = migrationNoop() } + // Handle new doctype creation + if (migration.isCreate) { + await migration.run(_client, docToUpdate) + } + switch (result.type) { case MIGRATION_RESULT_NOOP: await updateSchemaVersion(_client, migration.targetSchemaVersion) diff --git a/src/migrations/migration.type.ts b/src/migrations/migration.type.ts index ae576864b506317f7df54c84706dc4d6f9332c8a..84ebe24e5da9640799cecf99296f13018944727d 100644 --- a/src/migrations/migration.type.ts +++ b/src/migrations/migration.type.ts @@ -27,6 +27,7 @@ export type Migration = { description: string releaseNotes: Notes | null docTypes: string + isCreate?: boolean queryOptions?: MigrationQueryOptions appVersion: string run: (_client: Client, docs: any[]) => Promise<any[]> diff --git a/src/services/fluidsPrices.service.spec.ts b/src/services/fluidsPrices.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a03bbca881631a697848fd18f35e41a64d0c7f8 --- /dev/null +++ b/src/services/fluidsPrices.service.spec.ts @@ -0,0 +1,12 @@ +import FluidPricesService from './fluidConfig.service' + +describe('FluidPrices service', () => { + const fluidPricesService = new FluidPricesService() + + describe('getFluidConfig', () => { + it('should get fluid config', () => { + const result = fluidPricesService.getFluidConfig() + expect(result).toBeDefined() + }) + }) +}) diff --git a/src/services/fluidsPrices.service.ts b/src/services/fluidsPrices.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..588af20e9f5252aff506294476b5d9bafc2e964e --- /dev/null +++ b/src/services/fluidsPrices.service.ts @@ -0,0 +1,19 @@ +import { Q, Client, QueryDefinition, QueryResult } from 'cozy-client' +import { FLUIDPRICES_DOCTYPE } from 'doctypes' +import { FluidPrice } from 'models' + +export default class FluidPricesService { + private readonly _client: Client + + constructor(_client: Client) { + this._client = _client + } + + public async getAllPrices(): Promise<FluidPrice[]> { + const query: QueryDefinition = Q(FLUIDPRICES_DOCTYPE) + const { + data: fluidsPrices, + }: QueryResult<FluidPrice[]> = await this._client.query(query) + return fluidsPrices + } +}