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 478f988d7d..df53ac4807 100644 Binary files a/_scripts/db/dumps/domifa_test.postgres.custom.gz and b/_scripts/db/dumps/domifa_test.postgres.custom.gz differ diff --git a/_scripts/db/dumps/domifa_test.postgres.restore-data-only.sql b/_scripts/db/dumps/domifa_test.postgres.restore-data-only.sql index 70c5af146a..c40e15458b 100644 --- a/_scripts/db/dumps/domifa_test.postgres.restore-data-only.sql +++ b/_scripts/db/dumps/domifa_test.postgres.restore-data-only.sql @@ -129,7 +129,13 @@ COPY public.monitor_batch_process (uuid, "createdAt", "updatedAt", version, "pro -- Data for Name: open_data_places; Type: TABLE DATA; Schema: public; Owner: - -- -COPY public.open_data_places (uuid, "createdAt", "updatedAt", version, nom, adresse, "complementAdresse", ville, "codePostal", departement, region, latitude, longitude, source, "uniqueId", software, "structureId", mail) FROM stdin; +COPY public.open_data_places (uuid, "createdAt", "updatedAt", version, nom, adresse, "complementAdresse", ville, "codePostal", departement, region, latitude, longitude, source, "uniqueId", software, mail, "structureType", "domifaStructureId", "soliguideStructureId") FROM stdin; +2e311da7-5acf-4c4b-844a-49fe237ff60b 2023-12-13 20:22:43.289737+01 2023-12-13 20:22:43.289737+01 1 Structure de Test d'import rue de l import \N Nantes 44000 44 52 47.2139730 -1.5369230 domifa 4 domifa test.import@yopmail.com \N 4 \N +9a53b6e9-0e58-43d0-bebd-d4f679f6aa74 2023-12-13 20:22:43.302599+01 2023-12-13 20:22:43.302599+01 1 CCAS de Test 1 rue de l ocean \N Asnieres sur seine 92600 92 11 48.9037590 2.2837460 domifa 1 domifa ccas.test@yopmail.com \N 1 \N +ad8a4b0a-c5a1-40eb-9f92-220d1e9c548f 2023-12-13 20:22:43.307155+01 2023-12-13 20:22:43.307155+01 1 CCAS de Cayenne 24 avenue louis pasteur \N Cayenne 97300 973 03 4.9434540 -52.3244580 domifa 5 domifa ccas-cayenne@yopmail.com \N 5 \N +bb9949ec-206d-4ad6-88a4-1309dec2f2a0 2023-12-13 20:22:43.310765+01 2023-12-13 20:22:43.310765+01 1 Organisme agréé de Test 1 rue du test de l organise agree \N Nantes 44000 44 52 47.2181930 -1.5613680 domifa 3 domifa structure@yopmail.com \N 3 \N +3f1db6bf-14d0-48a0-903e-bec13998480d 2023-12-13 20:22:43.313864+01 2023-12-13 20:22:43.313864+01 1 CIAS de Test 2 rue du test \N Pessac 33600 33 75 44.8176020 -0.6129570 domifa 2 domifa cias.test@yopmail.com \N 2 \N +af7254b8-78c7-4760-a821-f8e20b996628 2023-12-13 20:22:44.125163+01 2023-12-13 20:22:44.125163+01 1 ESI La maison du partage 32 rue bouret 75019 paris \N Paris 75019 75 11 48.8817267 2.3742211 soliguide 0 other mpartage@armeedusalut.fr \N \N 0 \. diff --git a/_scripts/db/dumps/domifa_test.postgres.truncate-restore-data-only.sql b/_scripts/db/dumps/domifa_test.postgres.truncate-restore-data-only.sql index 0f3388aece..7409891ba5 100644 --- a/_scripts/db/dumps/domifa_test.postgres.truncate-restore-data-only.sql +++ b/_scripts/db/dumps/domifa_test.postgres.truncate-restore-data-only.sql @@ -155,7 +155,13 @@ COPY public.monitor_batch_process (uuid, "createdAt", "updatedAt", version, "pro -- Data for Name: open_data_places; Type: TABLE DATA; Schema: public; Owner: - -- -COPY public.open_data_places (uuid, "createdAt", "updatedAt", version, nom, adresse, "complementAdresse", ville, "codePostal", departement, region, latitude, longitude, source, "uniqueId", software, "structureId", mail) FROM stdin; +COPY public.open_data_places (uuid, "createdAt", "updatedAt", version, nom, adresse, "complementAdresse", ville, "codePostal", departement, region, latitude, longitude, source, "uniqueId", software, mail, "structureType", "domifaStructureId", "soliguideStructureId") FROM stdin; +2e311da7-5acf-4c4b-844a-49fe237ff60b 2023-12-13 20:22:43.289737+01 2023-12-13 20:22:43.289737+01 1 Structure de Test d'import rue de l import \N Nantes 44000 44 52 47.2139730 -1.5369230 domifa 4 domifa test.import@yopmail.com \N 4 \N +9a53b6e9-0e58-43d0-bebd-d4f679f6aa74 2023-12-13 20:22:43.302599+01 2023-12-13 20:22:43.302599+01 1 CCAS de Test 1 rue de l ocean \N Asnieres sur seine 92600 92 11 48.9037590 2.2837460 domifa 1 domifa ccas.test@yopmail.com \N 1 \N +ad8a4b0a-c5a1-40eb-9f92-220d1e9c548f 2023-12-13 20:22:43.307155+01 2023-12-13 20:22:43.307155+01 1 CCAS de Cayenne 24 avenue louis pasteur \N Cayenne 97300 973 03 4.9434540 -52.3244580 domifa 5 domifa ccas-cayenne@yopmail.com \N 5 \N +bb9949ec-206d-4ad6-88a4-1309dec2f2a0 2023-12-13 20:22:43.310765+01 2023-12-13 20:22:43.310765+01 1 Organisme agréé de Test 1 rue du test de l organise agree \N Nantes 44000 44 52 47.2181930 -1.5613680 domifa 3 domifa structure@yopmail.com \N 3 \N +3f1db6bf-14d0-48a0-903e-bec13998480d 2023-12-13 20:22:43.313864+01 2023-12-13 20:22:43.313864+01 1 CIAS de Test 2 rue du test \N Pessac 33600 33 75 44.8176020 -0.6129570 domifa 2 domifa cias.test@yopmail.com \N 2 \N +af7254b8-78c7-4760-a821-f8e20b996628 2023-12-13 20:22:44.125163+01 2023-12-13 20:22:44.125163+01 1 ESI La maison du partage 32 rue bouret 75019 paris \N Paris 75019 75 11 48.8817267 2.3742211 soliguide 0 other mpartage@armeedusalut.fr \N \N 0 \. diff --git a/packages/backend/src/_migrations/1702480247859-auto-migration.ts b/packages/backend/src/_migrations/1702480247859-auto-migration.ts deleted file mode 100644 index 59ffb1ff61..0000000000 --- a/packages/backend/src/_migrations/1702480247859-auto-migration.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class AutoMigration1702480247859 implements MigrationInterface { - name = "AutoMigration1702480247859"; - - public async up(queryRunner: QueryRunner): Promise { - 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");