From cac938a312014c30f99f7d9ee498407b8df84cc6 Mon Sep 17 00:00:00 2001 From: Yassine R Date: Wed, 13 Dec 2023 20:25:44 +0100 Subject: [PATCH] feat(open-data): add soliguide link --- .talismanrc | 6 +- .../db/dumps/domifa_test.postgres.custom.gz | Bin 91862 -> 93109 bytes ...domifa_test.postgres.restore-data-only.sql | 8 ++- ...st.postgres.truncate-restore-data-only.sql | 8 ++- .../1702480247859-auto-migration.ts | 15 ---- .../1702483465656-auto-migration.ts | 67 ++++++++++++++++++ .../OpenDataPlaceTable.typeorm.ts | 11 ++- .../place/open-data-place-repository.ts | 4 +- .../interfaces/OpenDataPlace.interface.ts | 3 +- .../src/open-data-places/load-domifa.ts | 5 +- .../src/open-data-places/load-soliguide.ts | 8 ++- packages/backend/src/run-app.ts | 2 +- 12 files changed, 110 insertions(+), 27 deletions(-) delete mode 100644 packages/backend/src/_migrations/1702480247859-auto-migration.ts create mode 100644 packages/backend/src/_migrations/1702483465656-auto-migration.ts diff --git a/.talismanrc b/.talismanrc index 3a14a7c483..f9438077e2 100644 --- a/.talismanrc +++ b/.talismanrc @@ -1,14 +1,16 @@ fileignoreconfig: - filename: _scripts/db/dumps/domifa_test.postgres.restore-data-only.sql - checksum: fc2c3720259ae183a86581dc71daa2e2762964470d112ec8cc4bb7c83b44bc02 + checksum: 40a85fc5e2ee32756348aecf74a0b85754a55959160b84f0dad9dccdba830468 - filename: _scripts/db/dumps/domifa_test.postgres.truncate-restore-data-only.sql - checksum: cc017bae84047b7761f61da63226cd3e419dc0bdd86264214922d4eeaf4cb5c1 + checksum: 68720419374aa7549545e234e5097408ac669fb4514d6d0d0fffe20e26bfff55 - filename: packages/backend/src/_common/decorators/IsValidPasswordDecorator.ts checksum: f0d4b3cd2e6e2d9b1e0271c34d64adacf87a5f1e7a505402a20869962543608d - filename: packages/backend/src/_migrations/1699910877010-auto-migration.ts checksum: bd05dd6b68f7fe2ca36ab1180a0449878cf78f4e048d2e5979b3dbe5fba1db53 - filename: packages/backend/src/_migrations/1701870413794-auto-migration.ts checksum: 281adc67c437b0c3ea874865872dafb0b6a4b23be044694caa6f0d210bbba0f9 +- filename: packages/backend/src/_migrations/1702483465656-auto-migration.ts + checksum: 2dbc2450c1df10f68a54897946318976bf8163711f3143e0608ce6c0e7275447 - filename: packages/backend/src/_migrations/_init-db/1603812391580-pr-env-create-database.ts checksum: 5e9ab65fc62b00a2a2092ccbcf0e2c9fdecefe418452b15b579425774cc1e1e2 - filename: packages/backend/src/_portail-admin/portail-admin-login/portail-admin-login.controller.spec.ts diff --git a/_scripts/db/dumps/domifa_test.postgres.custom.gz b/_scripts/db/dumps/domifa_test.postgres.custom.gz index 478f988d7d7cf102d7c62a69c9ebed01e0cba128..df53ac4807e0eaacc5be7ca6fc9194f7c38da80f 100644 GIT binary patch delta 2692 zcmaJ=3pkYN9-sfXjS+?zGvhWWX>yrqhCy^9bg-#}P-0|g#{E`wo21xC#Y;wy5GEsyPN|D~FE1VvMQ41(Y*|jcc0<$*PGWNdmes-;f=Yog%hmXNa>hY^iKw zS;izMN@7JzGtx3wWn`v_Q88tzNpgZDE>jXC{uA|$v1ChG{kl_M%tz{9GMSO z(GRwCd>_Y*jD#L^{Fbf60NMG`@r53bDX1(^(Gv@g@N=d>mZIgkxkgCrVT|_%{yYVp zj$)#=$bRxHE`n$a{C1QBP;0oLxGaejh(u{dh#mcoe1VIKV%WITs$ih@PMU)hX1qQo z2&npw6CuIMkUD(>+%a|oP#q@m5G8&m?gaIlNhnkqUbWg0sNqf%;b8>EK<_0^WFtTh z(srSOF_#&85c>T#3O4=BJ0^%v;wN9uyk&S1?&mdC`Tqde4S5(1U z6YYUKj!%-7HV&!E*yy<9ryczye79FVTq9<%|gv|*5oK0YX zu@l&8CB|Q$2h@nw6PQ$ip`HydsXXZf6t9GyZ5&l;lLBgynV?t1+_i6}BRkm~G?e3u zjxhDm0pfcfhpEIhHe)C?hmLO98lrVu=;+tYCCHE17kV&IWzKPAldG7KtFVa}4}5O! z!EjXZi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BMv-^w-`+q9YTsxB{3SRb>bWrEpTGikY_pEuiy|JjM0U9>NsCut=-ZiKB zUzDZQ#&37%zie6`ermB%ChnYh|Mu#Q*@=6!%I~qNa-eHikX(N-ZzLo}uwW#NCDAk< z|5)g7ghe(4(s_@m5a { - await queryRunner.query(`ALTER TABLE "open_data_places" ADD "mail" text`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query( - `ALTER TABLE "open_data_places" DROP COLUMN "mail"` - ); - } -} diff --git a/packages/backend/src/_migrations/1702483465656-auto-migration.ts b/packages/backend/src/_migrations/1702483465656-auto-migration.ts new file mode 100644 index 0000000000..cf530d1cfd --- /dev/null +++ b/packages/backend/src/_migrations/1702483465656-auto-migration.ts @@ -0,0 +1,67 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; +import { domifaConfig } from "../config"; + +export class AutoMigration1702483465656 implements MigrationInterface { + name = "AutoMigration1702483465656"; + + public async up(queryRunner: QueryRunner): Promise { + if ( + domifaConfig().envId === "preprod" || + domifaConfig().envId === "prod" || + domifaConfig().envId === "local" + ) { + await queryRunner.query(`ALTER TABLE "open_data_places" ADD "mail" text`); + + await queryRunner.query( + `ALTER TABLE "open_data_places" ADD "structureType" text` + ); + + await queryRunner.query( + `ALTER TABLE "open_data_places" DROP CONSTRAINT "FK_d10ac71fca9180b787ef468659e"` + ); + await queryRunner.query( + `DROP INDEX "public"."IDX_d10ac71fca9180b787ef468659"` + ); + await queryRunner.query( + `ALTER TABLE "open_data_places" DROP COLUMN "structureId"` + ); + await queryRunner.query( + `ALTER TABLE "open_data_places" ADD "domifaStructureId" integer` + ); + await queryRunner.query( + `ALTER TABLE "open_data_places" ADD "soliguideStructureId" integer` + ); + + await queryRunner.query( + `CREATE INDEX "IDX_7ee1e7a8d9441eb76ab7b4aa5a" ON "open_data_places" ("domifaStructureId") ` + ); + await queryRunner.query( + `ALTER TABLE "open_data_places" ADD CONSTRAINT "FK_7ee1e7a8d9441eb76ab7b4aa5a3" FOREIGN KEY ("domifaStructureId") REFERENCES "structure"("id") ON DELETE CASCADE ON UPDATE NO ACTION` + ); + } + } + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "open_data_places" DROP CONSTRAINT "FK_7ee1e7a8d9441eb76ab7b4aa5a3"` + ); + await queryRunner.query( + `DROP INDEX "public"."IDX_7ee1e7a8d9441eb76ab7b4aa5a"` + ); + + await queryRunner.query( + `ALTER TABLE "open_data_places" DROP COLUMN "soliguideStructureId"` + ); + await queryRunner.query( + `ALTER TABLE "open_data_places" DROP COLUMN "domifaStructureId"` + ); + await queryRunner.query( + `ALTER TABLE "open_data_places" ADD "structureId" integer` + ); + await queryRunner.query( + `CREATE INDEX "IDX_d10ac71fca9180b787ef468659" ON "open_data_places" ("structureId") ` + ); + await queryRunner.query( + `ALTER TABLE "open_data_places" ADD CONSTRAINT "FK_d10ac71fca9180b787ef468659e" FOREIGN KEY ("structureId") REFERENCES "structure"("id") ON DELETE CASCADE ON UPDATE NO ACTION` + ); + } +} diff --git a/packages/backend/src/database/entities/open-data-place/OpenDataPlaceTable.typeorm.ts b/packages/backend/src/database/entities/open-data-place/OpenDataPlaceTable.typeorm.ts index 134fb77986..2421506ae2 100644 --- a/packages/backend/src/database/entities/open-data-place/OpenDataPlaceTable.typeorm.ts +++ b/packages/backend/src/database/entities/open-data-place/OpenDataPlaceTable.typeorm.ts @@ -1,6 +1,7 @@ import { Entity, Column, ManyToOne, JoinColumn, Index } from "typeorm"; import { StructureTable } from "../structure"; import { AppTypeormTable } from "../_core"; +import { StructureType } from "@domifa/common"; @Entity("open_data_places") export class OpenDataPlaceTable extends AppTypeormTable { @@ -48,12 +49,18 @@ export class OpenDataPlaceTable extends AppTypeormTable { @ManyToOne(() => StructureTable, (structure) => structure.id, { onDelete: "CASCADE", }) - @JoinColumn({ name: "structureId", referencedColumnName: "id" }) - structureId: number; + @JoinColumn({ name: "domifaStructureId", referencedColumnName: "id" }) + domifaStructureId: number; + + @Column({ type: "integer", nullable: true }) + soliguideStructureId: number; @Column({ type: "text", nullable: true }) mail: string; + @Column({ type: "text", nullable: true }) + structureType: StructureType; + public constructor(entity?: Partial) { super(entity); Object.assign(this, entity); diff --git a/packages/backend/src/database/services/place/open-data-place-repository.ts b/packages/backend/src/database/services/place/open-data-place-repository.ts index 828df908fb..5d1c541a86 100644 --- a/packages/backend/src/database/services/place/open-data-place-repository.ts +++ b/packages/backend/src/database/services/place/open-data-place-repository.ts @@ -8,9 +8,9 @@ export const openDataPlaceRepository = myDataSource findExistingPlace: async (latitude: number, longitude: number) => { return openDataPlaceRepository .createQueryBuilder("open_data_places") - .select(`nom, ville, "structureId"`) + .select(`nom, ville, "domifaStructureId"`) .where( - `source='domifa' and ST_DWithin(ST_SetSRID(ST_MakePoint(longitude, latitude), 4326)::geography, ST_SetSRID(ST_MakePoint(:longitude, :latitude), 4326)::geography, 250);`, + `source='domifa' and ST_DWithin(ST_SetSRID(ST_MakePoint(longitude, latitude), 4326)::geography, ST_SetSRID(ST_MakePoint(:longitude, :latitude), 4326)::geography, 400);`, { longitude, latitude, diff --git a/packages/backend/src/open-data-places/interfaces/OpenDataPlace.interface.ts b/packages/backend/src/open-data-places/interfaces/OpenDataPlace.interface.ts index 4cee10a480..8f67c4b43b 100644 --- a/packages/backend/src/open-data-places/interfaces/OpenDataPlace.interface.ts +++ b/packages/backend/src/open-data-places/interfaces/OpenDataPlace.interface.ts @@ -13,5 +13,6 @@ export interface OpenDataPlace extends AppEntity { source: "soliguide" | "domifa" | "data-inclusion"; uniqueId: string; // ID from soliguide | data-inclusion software: "domifa" | "millesime" | "other"; - structureId: number; + domifaStructureId: number; + soliguideStructureId: number; } diff --git a/packages/backend/src/open-data-places/load-domifa.ts b/packages/backend/src/open-data-places/load-domifa.ts index ab182a4a8b..42891e1080 100644 --- a/packages/backend/src/open-data-places/load-domifa.ts +++ b/packages/backend/src/open-data-places/load-domifa.ts @@ -24,6 +24,7 @@ export const loadDomifaData = async () => { "region", "latitude", "longitude", + "email", "id", ], }); @@ -47,7 +48,9 @@ export const loadDomifaData = async () => { latitude: place.latitude, longitude: place.longitude, source: "domifa", - structureId: place.id, + domifaStructureId: place.id, + soliguideStructureId: null, + mail: place.email, uniqueId: place.id.toString(), }) ); diff --git a/packages/backend/src/open-data-places/load-soliguide.ts b/packages/backend/src/open-data-places/load-soliguide.ts index 4efb5c4449..2f0222b8b0 100644 --- a/packages/backend/src/open-data-places/load-soliguide.ts +++ b/packages/backend/src/open-data-places/load-soliguide.ts @@ -76,6 +76,7 @@ const getFromSoliguide = async () => { source: "soliguide", uniqueId: place.lieu_id.toString(), mail: place?.entity?.mail?.toString(), + soliguideStructureId: parseInt(place.lieu_id as any, 10), }) ); } @@ -89,7 +90,12 @@ const getFromSoliguide = async () => { if (placeExist) { await openDataPlaceRepository.update( { uuid: soliguidePlace.uuid }, - { structureId: placeExist.structureId } + { domifaStructureId: placeExist.domifaStructureId } + ); + + await openDataPlaceRepository.update( + { domifaStructureId: placeExist.domifaStructureId }, + { soliguideStructureId: soliguidePlace.soliguideStructureId } ); } } diff --git a/packages/backend/src/run-app.ts b/packages/backend/src/run-app.ts index cd5b496be0..7d69e3e7f2 100644 --- a/packages/backend/src/run-app.ts +++ b/packages/backend/src/run-app.ts @@ -17,7 +17,7 @@ import { domifaConfig } from "./config"; server.setTimeout(1000 * 60 * 5); appLogger.warn(`[${__filename}] Application listening on port 3000`); - if (domifaConfig().envId === "local" && domifaConfig().cron.enable) { + if (domifaConfig().envId === "local") { await loadDomifaData(); await loadSoliguideData(); // await loadDataInclusionData("CCAS");