diff --git a/.talismanrc b/.talismanrc index 3faffaac76..bc5d80e473 100644 --- a/.talismanrc +++ b/.talismanrc @@ -1,4 +1,12 @@ fileignoreconfig: +- filename: _scripts/db/dumps/domifa_test.postgres.restore-data-only.sql + checksum: 104c8036ca644bc51bb4c797e56b3a5b178a55b1c293a77308844e54ca7c404d +- filename: _scripts/db/dumps/domifa_test.postgres.truncate-restore-data-only.sql + checksum: 9976de417c719ab5c3bec9d4a1bafc40bfa8d4388d2dbd5da7d1ea4a11d2db75 +- filename: packages/backend/src/_migrations/1699910877010-auto-migration.ts + checksum: bd05dd6b68f7fe2ca36ab1180a0449878cf78f4e048d2e5979b3dbe5fba1db53 +- filename: packages/backend/src/_migrations/_init-db/1603812391580-pr-env-create-database.ts + checksum: 586e3b26481d71256a1b7626956aaf9e68211dfbda527dd862a2aad075b5cc04 - filename: yarn.lock checksum: 4ac842f95592d194e65b208fdc4b9a78a0bb6470ad2d4950626c2ffcec831a33 version: "1.0" diff --git a/_scripts/db/dumps/domifa_test.postgres.custom.gz b/_scripts/db/dumps/domifa_test.postgres.custom.gz index 174d0193a0..3d3b2a55ee 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 7f402e42b9..b61809dbcd 100644 --- a/_scripts/db/dumps/domifa_test.postgres.restore-data-only.sql +++ b/_scripts/db/dumps/domifa_test.postgres.restore-data-only.sql @@ -2,8 +2,8 @@ -- PostgreSQL database dump -- --- Dumped from database version 14.9 (Debian 14.9-1.pgdg110+1) --- Dumped by pg_dump version 14.9 (Debian 14.9-1.pgdg110+1) +-- Dumped from database version 14.9 +-- Dumped by pg_dump version 14.9 SET statement_timeout = 0; SET lock_timeout = 0; @@ -256,8 +256,18 @@ e0bcefc6-f1be-4c83-ac9d-6ea47335a9c3 2021-03-15 16:53:55.740856+01 2023-09-05 23 -- COPY public.user_usager (uuid, "createdAt", "updatedAt", version, id, "usagerUUID", "structureId", login, password, salt, "isTemporaryPassword", "lastLogin", "passwordLastUpdate", "lastPasswordResetDate", "lastPasswordResetStructureUser", enabled) FROM stdin; -a03a9a49-ae31-4160-9879-bab02dc46361 2021-11-30 14:50:26.278073+01 2021-11-30 15:01:39.89434+01 10 2 97b7e840-0e93-4bf4-ba7d-0a406aa898f2 1 LNQIFFBK $2a$10$u..ofvcb5t5a44N0Oriwbew6oz600aoOFzll9yl92Lx1VOb0E8o0a $2a$10$zmuPXxUOuQJ7nE6ag4.x6e f 2021-11-30 15:01:39.893+01 2021-11-30 15:01:39.675+01 2021-11-30 14:50:26.275+01 {"userId": 1, "userName": "Patrick Roméro"} t a657f4bd-e4d1-4c38-bdd0-ffd268b356df 2021-10-05 11:34:41.369505+02 2021-11-30 15:02:07.705535+01 18 1 b2c26e55-ab37-457d-b307-6fe161050a9b 1 WKYJBDXS $2a$10$cmwXTghEgrGRYTkGIJlj3Owjo8YVVDXOgceAGtkgzcD2M/Tf3Dhb. $2a$10$/uFyiR8hCe8XkRe7x2fYm. t 2021-11-30 15:02:07.69+01 \N 2021-10-05 11:34:41.365+02 {"userId": 1, "userName": "Patrick Roméro"} t +a03a9a49-ae31-4160-9879-bab02dc46361 2021-11-30 14:50:26.278073+01 2023-11-20 16:40:58.362384+01 17 2 97b7e840-0e93-4bf4-ba7d-0a406aa898f2 1 LNQIFFBK $2a$10$u..ofvcb5t5a44N0Oriwbew6oz600aoOFzll9yl92Lx1VOb0E8o0a $2a$10$zmuPXxUOuQJ7nE6ag4.x6e f 2023-11-20 16:40:58.36+01 2021-11-30 15:01:39.675+01 2021-11-30 14:50:26.275+01 {"userId": 1, "userName": "Patrick Roméro"} t +\. + + +-- +-- Data for Name: user_usager_login; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public.user_usager_login (uuid, "createdAt", "updatedAt", version, "usagerUUID", "structureId") FROM stdin; +3927beaf-04d8-4cbb-9be7-c7c9086434b3 2023-11-20 16:40:44.4121+01 2023-11-20 16:40:44.4121+01 1 97b7e840-0e93-4bf4-ba7d-0a406aa898f2 1 +e80dafea-8fe4-4792-92b9-3608c723aa1b 2023-11-20 16:40:58.289642+01 2023-11-20 16:40:58.289642+01 1 97b7e840-0e93-4bf4-ba7d-0a406aa898f2 1 \. @@ -266,8 +276,8 @@ a657f4bd-e4d1-4c38-bdd0-ffd268b356df 2021-10-05 11:34:41.369505+02 2021-11-30 15 -- COPY public.user_usager_security (uuid, "createdAt", "updatedAt", version, "userId", "structureId", "eventsHistory") FROM stdin; -fadd55b6-ca41-48d4-bd56-238b1a3c6f7b 2021-11-30 14:50:26.290488+01 2021-11-30 15:01:39.66811+01 8 2 1 [{"date": "2021-11-30T13:50:38.357Z", "type": "login-success"}, {"date": "2021-11-30T13:51:20.351Z", "type": "login-success"}, {"date": "2021-11-30T13:51:20.608Z", "type": "change-password-success"}, {"date": "2021-11-30T14:00:55.533Z", "type": "login-error"}, {"date": "2021-11-30T14:01:21.310Z", "type": "login-success"}, {"date": "2021-11-30T14:01:39.398Z", "type": "login-success"}, {"date": "2021-11-30T14:01:39.667Z", "type": "change-password-success"}] 9bc8decb-5f78-48de-8c1b-9f61ea5acfba 2021-10-05 11:34:41.388922+02 2021-11-30 15:02:07.682311+01 3 1 1 [{"date": "2021-11-30T14:02:07.680Z", "type": "login-success"}] +fadd55b6-ca41-48d4-bd56-238b1a3c6f7b 2021-11-30 14:50:26.290488+01 2023-11-20 16:40:58.2674+01 10 2 1 [{"date": "2023-11-20T15:40:44.378Z", "type": "login-success"}, {"date": "2023-11-20T15:40:58.265Z", "type": "login-success"}] \. 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 8c2e8cb695..dc93ba61ab 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 @@ -28,8 +28,8 @@ TRUNCATE TABLE public.usager_options_history RESTART IDENTITY CASCADE; -- PostgreSQL database dump -- --- Dumped from database version 14.9 (Debian 14.9-1.pgdg110+1) --- Dumped by pg_dump version 14.9 (Debian 14.9-1.pgdg110+1) +-- Dumped from database version 14.9 +-- Dumped by pg_dump version 14.9 SET statement_timeout = 0; SET lock_timeout = 0; @@ -282,8 +282,18 @@ e0bcefc6-f1be-4c83-ac9d-6ea47335a9c3 2021-03-15 16:53:55.740856+01 2023-09-05 23 -- COPY public.user_usager (uuid, "createdAt", "updatedAt", version, id, "usagerUUID", "structureId", login, password, salt, "isTemporaryPassword", "lastLogin", "passwordLastUpdate", "lastPasswordResetDate", "lastPasswordResetStructureUser", enabled) FROM stdin; -a03a9a49-ae31-4160-9879-bab02dc46361 2021-11-30 14:50:26.278073+01 2021-11-30 15:01:39.89434+01 10 2 97b7e840-0e93-4bf4-ba7d-0a406aa898f2 1 LNQIFFBK $2a$10$u..ofvcb5t5a44N0Oriwbew6oz600aoOFzll9yl92Lx1VOb0E8o0a $2a$10$zmuPXxUOuQJ7nE6ag4.x6e f 2021-11-30 15:01:39.893+01 2021-11-30 15:01:39.675+01 2021-11-30 14:50:26.275+01 {"userId": 1, "userName": "Patrick Roméro"} t a657f4bd-e4d1-4c38-bdd0-ffd268b356df 2021-10-05 11:34:41.369505+02 2021-11-30 15:02:07.705535+01 18 1 b2c26e55-ab37-457d-b307-6fe161050a9b 1 WKYJBDXS $2a$10$cmwXTghEgrGRYTkGIJlj3Owjo8YVVDXOgceAGtkgzcD2M/Tf3Dhb. $2a$10$/uFyiR8hCe8XkRe7x2fYm. t 2021-11-30 15:02:07.69+01 \N 2021-10-05 11:34:41.365+02 {"userId": 1, "userName": "Patrick Roméro"} t +a03a9a49-ae31-4160-9879-bab02dc46361 2021-11-30 14:50:26.278073+01 2023-11-20 16:40:58.362384+01 17 2 97b7e840-0e93-4bf4-ba7d-0a406aa898f2 1 LNQIFFBK $2a$10$u..ofvcb5t5a44N0Oriwbew6oz600aoOFzll9yl92Lx1VOb0E8o0a $2a$10$zmuPXxUOuQJ7nE6ag4.x6e f 2023-11-20 16:40:58.36+01 2021-11-30 15:01:39.675+01 2021-11-30 14:50:26.275+01 {"userId": 1, "userName": "Patrick Roméro"} t +\. + + +-- +-- Data for Name: user_usager_login; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public.user_usager_login (uuid, "createdAt", "updatedAt", version, "usagerUUID", "structureId") FROM stdin; +3927beaf-04d8-4cbb-9be7-c7c9086434b3 2023-11-20 16:40:44.4121+01 2023-11-20 16:40:44.4121+01 1 97b7e840-0e93-4bf4-ba7d-0a406aa898f2 1 +e80dafea-8fe4-4792-92b9-3608c723aa1b 2023-11-20 16:40:58.289642+01 2023-11-20 16:40:58.289642+01 1 97b7e840-0e93-4bf4-ba7d-0a406aa898f2 1 \. @@ -292,8 +302,8 @@ a657f4bd-e4d1-4c38-bdd0-ffd268b356df 2021-10-05 11:34:41.369505+02 2021-11-30 15 -- COPY public.user_usager_security (uuid, "createdAt", "updatedAt", version, "userId", "structureId", "eventsHistory") FROM stdin; -fadd55b6-ca41-48d4-bd56-238b1a3c6f7b 2021-11-30 14:50:26.290488+01 2021-11-30 15:01:39.66811+01 8 2 1 [{"date": "2021-11-30T13:50:38.357Z", "type": "login-success"}, {"date": "2021-11-30T13:51:20.351Z", "type": "login-success"}, {"date": "2021-11-30T13:51:20.608Z", "type": "change-password-success"}, {"date": "2021-11-30T14:00:55.533Z", "type": "login-error"}, {"date": "2021-11-30T14:01:21.310Z", "type": "login-success"}, {"date": "2021-11-30T14:01:39.398Z", "type": "login-success"}, {"date": "2021-11-30T14:01:39.667Z", "type": "change-password-success"}] 9bc8decb-5f78-48de-8c1b-9f61ea5acfba 2021-10-05 11:34:41.388922+02 2021-11-30 15:02:07.682311+01 3 1 1 [{"date": "2021-11-30T14:02:07.680Z", "type": "login-success"}] +fadd55b6-ca41-48d4-bd56-238b1a3c6f7b 2021-11-30 14:50:26.290488+01 2023-11-20 16:40:58.2674+01 10 2 1 [{"date": "2023-11-20T15:40:44.378Z", "type": "login-success"}, {"date": "2023-11-20T15:40:58.265Z", "type": "login-success"}] \. diff --git a/packages/backend/src/_common/model/interaction/INTERACTIONS_OK.const.ts b/packages/backend/src/_common/model/interaction/INTERACTIONS_OK.const.ts index e8a2322c0e..116bc209c3 100644 --- a/packages/backend/src/_common/model/interaction/INTERACTIONS_OK.const.ts +++ b/packages/backend/src/_common/model/interaction/INTERACTIONS_OK.const.ts @@ -10,7 +10,6 @@ export const ALL_INTERACTION_TYPES: InteractionType[] = [ "appel", "visite", "npai", - "loginPortail", ]; export const INTERACTION_OK_LIST: InteractionType[] = [ diff --git a/packages/backend/src/_common/model/message-sms/MESSAGE_SMS_STATUS.const.ts b/packages/backend/src/_common/model/message-sms/MESSAGE_SMS_STATUS.const.ts deleted file mode 100644 index 040cd52ee6..0000000000 --- a/packages/backend/src/_common/model/message-sms/MESSAGE_SMS_STATUS.const.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { MessageSmsStatus } from "."; - -export const MESSAGE_SMS_STATUS: { [key: number]: MessageSmsStatus } = { - 0: "ON_HOLD", - 1: "SENT_AND_RECEIVED", - 2: "SENT_AND_NOT_RECEIVED", - 3: "IN_PROGRESS", - 4: "FAILURE", - 5: "EXPIRED", - 6: "DISABLED", -}; diff --git a/packages/backend/src/_common/model/message-sms/MESSAGE_SMS_SUIVI_INDEX.const.ts b/packages/backend/src/_common/model/message-sms/MESSAGE_SMS_SUIVI_INDEX.const.ts deleted file mode 100644 index ea60958c4e..0000000000 --- a/packages/backend/src/_common/model/message-sms/MESSAGE_SMS_SUIVI_INDEX.const.ts +++ /dev/null @@ -1,7 +0,0 @@ -export const INDEX_NUMERO = 0; // Numéro du destinataire -export const INDEX_STATUT = 1; // Statut du message -export const INDEX_DATE_EMISSION = 2; // Date d'émission du message (UNIX timestamp) -export const INDEX_DATE_MISE_A_JOUR = 3; // Date du dernier changement de statut du message (UNIX timestamp) -export const INDEX_STATUT_DETAILLE = 4; // Statut détaillé du message (disponible auprès de votre gestionnaire de compte). -export const INDEX_ID_MESSAGE = 5; // Identifiant du message. -export const INDEX_OPERATEUR = 6; // Code MCCMNC correspondant à l'opérateur du destinataire. diff --git a/packages/backend/src/_common/model/message-sms/MessageSms.type.ts b/packages/backend/src/_common/model/message-sms/MessageSms.type.ts index 56fc15875f..9eb54a5b78 100644 --- a/packages/backend/src/_common/model/message-sms/MessageSms.type.ts +++ b/packages/backend/src/_common/model/message-sms/MessageSms.type.ts @@ -1,9 +1,9 @@ -import { MessageSmsId } from "@domifa/common"; import { - MessageSmsInteractionMetas, + MessageSmsId, MessageSmsReminderMetas, MessageSmsStatus, -} from "."; + MessageSmsInteractionMetas, +} from "@domifa/common"; import { AppEntity } from "../../../_common/model"; export type MessageSms = AppEntity & { diff --git a/packages/backend/src/_common/model/message-sms/MessageSmsInteractionMetas.type.ts b/packages/backend/src/_common/model/message-sms/MessageSmsInteractionMetas.type.ts deleted file mode 100644 index 14cee5a09a..0000000000 --- a/packages/backend/src/_common/model/message-sms/MessageSmsInteractionMetas.type.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { InteractionType } from "@domifa/common"; - -export type MessageSmsInteractionMetas = { - nbCourrier: number; - interactionType: InteractionType; - date: Date; -}; diff --git a/packages/backend/src/_common/model/message-sms/MessageSmsReminderMetas.type.ts b/packages/backend/src/_common/model/message-sms/MessageSmsReminderMetas.type.ts deleted file mode 100644 index 8d2bac62b0..0000000000 --- a/packages/backend/src/_common/model/message-sms/MessageSmsReminderMetas.type.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type MessageSmsReminderMetas = { - type: string; - date: Date; -}; diff --git a/packages/backend/src/_common/model/message-sms/MessageSmsStatus.type.ts b/packages/backend/src/_common/model/message-sms/MessageSmsStatus.type.ts deleted file mode 100644 index e8a83dc1b8..0000000000 --- a/packages/backend/src/_common/model/message-sms/MessageSmsStatus.type.ts +++ /dev/null @@ -1,17 +0,0 @@ -export type MessageSmsStatus = - | "TO_SEND" - | "ON_HOLD" - | "SENT_AND_RECEIVED" - | "SENT_AND_NOT_RECEIVED" - | "IN_PROGRESS" - | "FAILURE" - | "DISABLED" - | "EXPIRED"; - -export const ON_HOLD = 0; -export const SENT_AND_RECEIVED = 1; -export const SENT_AND_NOT_RECEIVED = 2; -export const IN_PROGRESS = 3; -export const FAILURE = 4; -export const EXPIRED = 5; -export const DISABLED = 6; diff --git a/packages/backend/src/_common/model/message-sms/index.ts b/packages/backend/src/_common/model/message-sms/index.ts index d00b4dee9b..e17627c2f2 100644 --- a/packages/backend/src/_common/model/message-sms/index.ts +++ b/packages/backend/src/_common/model/message-sms/index.ts @@ -1,10 +1,5 @@ //@index('./*', f => `export * from '${f.path}'`) export * from "./MESSAGE_SMS_RESPONSE_ERRORS.const"; -export * from "./MESSAGE_SMS_STATUS.const"; -export * from "./MESSAGE_SMS_SUIVI_INDEX.const"; export * from "./MessageSms.type"; -export * from "./MessageSmsInteractionMetas.type"; -export * from "./MessageSmsReminderMetas.type"; export * from "./MessageSmsSendResponse.type"; -export * from "./MessageSmsStatus.type"; export * from "./SuiviSmsErrors.type"; diff --git a/packages/backend/src/_migrations/1699910877010-auto-migration.ts b/packages/backend/src/_migrations/1699910877010-auto-migration.ts new file mode 100644 index 0000000000..43e92009e6 --- /dev/null +++ b/packages/backend/src/_migrations/1699910877010-auto-migration.ts @@ -0,0 +1,38 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; +import { domifaConfig } from "../config"; + +export class AutoMigration1699910877010 implements MigrationInterface { + name = "AutoMigration1699910877010"; + public async up(queryRunner: QueryRunner): Promise { + if ( + domifaConfig().envId !== "preprod" && + domifaConfig().envId === "prod" && + domifaConfig().envId === "local" + ) { + await queryRunner.query( + `CREATE TABLE "user_usager_login" ("uuid" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "version" integer NOT NULL, "usagerUUID" uuid NOT NULL, "structureId" integer NOT NULL, CONSTRAINT "PK_cfb7dc4a81d1db054ab5b4d50bf" PRIMARY KEY ("uuid"))` + ); + await queryRunner.query( + `CREATE INDEX "idx_user_usager_login" ON "user_usager_login" ("structureId", "usagerUUID") ` + ); + await queryRunner.query( + `ALTER TABLE "user_usager_login" ADD CONSTRAINT "FK_4bf76763fec5203f945338a0377" FOREIGN KEY ("usagerUUID") REFERENCES "usager"("uuid") ON DELETE CASCADE ON UPDATE NO ACTION` + ); + await queryRunner.query( + `ALTER TABLE "user_usager_login" ADD CONSTRAINT "FK_8722e56ff917692645abcd29e7c" FOREIGN KEY ("structureId") REFERENCES "structure"("id") ON DELETE CASCADE ON UPDATE NO ACTION` + ); + } + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "user_usager_login" DROP CONSTRAINT "FK_8722e56ff917692645abcd29e7c"` + ); + await queryRunner.query( + `ALTER TABLE "user_usager_login" DROP CONSTRAINT "FK_4bf76763fec5203f945338a0377"` + ); + + await queryRunner.query(`DROP INDEX "public"."idx_user_usager_login"`); + await queryRunner.query(`DROP TABLE "user_usager_login"`); + } +} diff --git a/packages/backend/src/_migrations/1699913113875-manual-migration.ts b/packages/backend/src/_migrations/1699913113875-manual-migration.ts new file mode 100644 index 0000000000..cdfaf1fa47 --- /dev/null +++ b/packages/backend/src/_migrations/1699913113875-manual-migration.ts @@ -0,0 +1,59 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +import { In, MigrationInterface, QueryRunner } from "typeorm"; +import { + UserUsagerLoginTable, + interactionRepository, + userUsagerLoginRepository, +} from "../database"; + +export class ManualMigration1699913113875 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + let i = 0; + const total = await interactionRepository.countBy({ + type: "loginPortail" as any, + }); + + const batch = 25000; + while ( + (await interactionRepository.countBy({ type: "loginPortail" as any })) > 0 + ) { + const uuidsToDelete = []; + const interactions = await interactionRepository.find({ + where: { type: "loginPortail" as any }, + take: batch, + select: { + dateInteraction: true, + uuid: true, + usagerUUID: true, + structureId: true, + updatedAt: true, + }, + }); + + await queryRunner.startTransaction(); + try { + for (const interaction of interactions) { + const userUsagerLogin = new UserUsagerLoginTable(); + userUsagerLogin.usagerUUID = interaction.usagerUUID; + userUsagerLogin.structureId = interaction.structureId; + userUsagerLogin.createdAt = interaction.dateInteraction; + userUsagerLogin.updatedAt = interaction.updatedAt; + await userUsagerLoginRepository.save(userUsagerLogin); + uuidsToDelete.push(interaction.uuid); + } + + await interactionRepository.delete({ uuid: In(uuidsToDelete) }); + await queryRunner.commitTransaction(); + i = i + batch; + console.log(`${i}/${total} interactions migrated`); + } catch (err) { + await queryRunner.rollbackTransaction(); + throw err; + } + } + } + + public async down(_queryRunner: QueryRunner): Promise { + // + } +} diff --git a/packages/backend/src/_migrations/_init-db/1603812391580-pr-env-create-database.ts b/packages/backend/src/_migrations/_init-db/1603812391580-pr-env-create-database.ts index 44636779bd..c026387263 100644 --- a/packages/backend/src/_migrations/_init-db/1603812391580-pr-env-create-database.ts +++ b/packages/backend/src/_migrations/_init-db/1603812391580-pr-env-create-database.ts @@ -237,6 +237,24 @@ async function createTables(queryRunner: QueryRunner) { CREATE INDEX "IDX_fa4dea9a1ff8deb8fcf47c451e" ON public.structure USING btree (departement); + -- public.user_usager_login definition + + -- Drop table + + -- DROP TABLE public.user_usager_login; + + CREATE UNLOGGED TABLE public.user_usager_login ( + uuid uuid NOT NULL DEFAULT uuid_generate_v4(), + "createdAt" timestamptz NOT NULL DEFAULT now(), + "updatedAt" timestamptz NOT NULL DEFAULT now(), + "version" int4 NOT NULL, + "usagerUUID" uuid NOT NULL, + "structureId" int4 NOT NULL, + CONSTRAINT "PK_cfb7dc4a81d1db054ab5b4d50bf" PRIMARY KEY (uuid) + ); + CREATE INDEX idx_user_usager_login ON public.user_usager_login USING btree ("structureId", "usagerUUID"); + + -- public.message_sms definition -- Drop table diff --git a/packages/backend/src/_portail-admin/admin-structures/services/admin-structures.service.ts b/packages/backend/src/_portail-admin/admin-structures/services/admin-structures.service.ts index 8ce1bb1c6b..970f5c2633 100644 --- a/packages/backend/src/_portail-admin/admin-structures/services/admin-structures.service.ts +++ b/packages/backend/src/_portail-admin/admin-structures/services/admin-structures.service.ts @@ -10,6 +10,7 @@ import { typeOrmSearch, usagerRepository, UsagerTable, + userUsagerLoginRepository, } from "../../../database"; import { usagerDocsRepository } from "../../../database/services/usager/usagerDocsRepository.service"; import { StatsDeploiementExportModel } from "../../../excel/export-stats-deploiement"; @@ -140,7 +141,7 @@ export class AdminStructuresService { } public async getInteractionsCountByTypeMap(): Promise<{ - [statut in InteractionType]: number; + [statut in InteractionType | "loginPortail"]: number; }> { return { courrierIn: await this.totalInteractions("courrierIn"), @@ -152,7 +153,7 @@ export class AdminStructuresService { appel: await this.totalInteractions("appel"), visite: await this.totalInteractions("visite"), npai: await this.totalInteractions("npai"), - loginPortail: await this.totalInteractions("loginPortail"), + loginPortail: await userUsagerLoginRepository.count(), }; } @@ -370,7 +371,6 @@ export class AdminStructuresService { if ( interactionType === "appel" || interactionType === "visite" || - interactionType === "loginPortail" || interactionType === "npai" ) { return interactionRepository.count({ diff --git a/packages/backend/src/_portail-usager/portail-usager-login/portail-usagers-login.controller.ts b/packages/backend/src/_portail-usager/portail-usager-login/portail-usagers-login.controller.ts index 61dceee071..45de1deedb 100644 --- a/packages/backend/src/_portail-usager/portail-usager-login/portail-usagers-login.controller.ts +++ b/packages/backend/src/_portail-usager/portail-usager-login/portail-usagers-login.controller.ts @@ -9,7 +9,9 @@ import { } from "@nestjs/common"; import { ApiTags } from "@nestjs/swagger"; import { + UserUsagerLoginTable, usagerRepository, + userUsagerLoginRepository, userUsagerSecurityPasswordChecker, } from "../../database"; import { UsagerLoginDto } from "../../users/dto"; @@ -17,11 +19,9 @@ import { ExpressResponse } from "../../util/express"; import { PortailUsagerAuthApiResponse, PortailUsagerProfile, - UserStructure, } from "../../_common/model"; import { portailUsagerProfilBuilder } from "../portail-usager-profil/services/portail-usager-profil-builder.service"; import { UsagersAuthService } from "./services/usagers-auth.service"; -import { interactionsCreator } from "../../interactions/services"; @Controller("portail-usagers/auth") @ApiTags("auth") @@ -60,26 +60,20 @@ export class PortailUsagersLoginController { id: user.structureId, }); - const userStructure: Pick< - UserStructure, - "id" | "structureId" | "nom" | "prenom" | "structure" - > = { - id: 0, - nom: usager.nom, - prenom: usager.prenom, - structureId: user.structureId, - structure, - }; + const lastLogin = await userUsagerLoginRepository.save( + new UserUsagerLoginTable({ + usagerUUID: usager.uuid, + structureId: usager.structureId, + }) + ); - // Création d'une interaction avec la date de connexion - await interactionsCreator.createInteraction({ - interaction: { - type: "loginPortail", - nbCourrier: 0, - }, - usager, - user: userStructure, - }); + if (structure.portailUsager.usagerLoginUpdateLastInteraction) { + usager.lastInteraction.dateInteraction = lastLogin.createdAt; + await usagerRepository.update( + { uuid: usager.uuid }, + { lastInteraction: usager.lastInteraction } + ); + } const response: PortailUsagerAuthApiResponse = { token: access_token, diff --git a/packages/backend/src/database/entities/message-sms/MessageSmsTable.typeorm.ts b/packages/backend/src/database/entities/message-sms/MessageSmsTable.typeorm.ts index e6bdddd03a..31ed034197 100644 --- a/packages/backend/src/database/entities/message-sms/MessageSmsTable.typeorm.ts +++ b/packages/backend/src/database/entities/message-sms/MessageSmsTable.typeorm.ts @@ -1,12 +1,13 @@ import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm"; +import { MessageSms } from "../../../_common/model/message-sms"; +import { StructureTable } from "../structure"; +import { AppTypeormTable } from "../_core/AppTypeormTable.typeorm"; import { - MessageSms, + MessageSmsId, + MessageSmsStatus, MessageSmsInteractionMetas, MessageSmsReminderMetas, -} from "../../../_common/model/message-sms"; -import { StructureTable } from "../structure"; -import { AppTypeormTable } from "../_core/AppTypeormTable.typeorm"; -import { MessageSmsId, MessageSmsStatus } from "@domifa/common"; +} from "@domifa/common"; // https://typeorm.io/#/entities/column-types-for-postgres @Entity({ name: "message_sms" }) diff --git a/packages/backend/src/database/entities/user-usager/UserUsagerLoginTable.typeorm.ts b/packages/backend/src/database/entities/user-usager/UserUsagerLoginTable.typeorm.ts new file mode 100644 index 0000000000..a8c80569d8 --- /dev/null +++ b/packages/backend/src/database/entities/user-usager/UserUsagerLoginTable.typeorm.ts @@ -0,0 +1,30 @@ +import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm"; +import { StructureTable, UsagerTable } from ".."; +import { AppTypeormTable } from "../_core/AppTypeormTable.typeorm"; +import { UserUsagerLogin } from "@domifa/common"; + +@Entity({ name: "user_usager_login" }) +@Index("idx_user_usager_login", ["structureId", "usagerUUID"]) +export class UserUsagerLoginTable + extends AppTypeormTable + implements UserUsagerLogin +{ + @Column({ type: "uuid", nullable: false }) + @ManyToOne(() => UsagerTable, (usager) => usager.uuid, { + onDelete: "CASCADE", + }) + @JoinColumn({ name: "usagerUUID", referencedColumnName: "uuid" }) + public usagerUUID: string; + + @ManyToOne(() => StructureTable, (structure) => structure.id, { + onDelete: "CASCADE", + }) + @Column({ type: "integer", nullable: false }) + @JoinColumn({ name: "structureId", referencedColumnName: "id" }) + public structureId: number; + + public constructor(entity?: Partial) { + super(entity); + Object.assign(this, entity); + } +} diff --git a/packages/backend/src/database/entities/user-usager/index.ts b/packages/backend/src/database/entities/user-usager/index.ts index 53c0f11936..17898b70b2 100644 --- a/packages/backend/src/database/entities/user-usager/index.ts +++ b/packages/backend/src/database/entities/user-usager/index.ts @@ -1 +1,4 @@ +// @index('./*', f => `export * from '${f.path}'`) +export * from "./UserUsagerLoginTable.typeorm"; +export * from "./UserUsagerSecurityTable.typeorm"; export * from "./UserUsagerTable.typeorm"; diff --git a/packages/backend/src/database/services/interaction/interactionRepository.service.test.ts b/packages/backend/src/database/services/interaction/interactionRepository.service.test.ts index 5541cc0e16..010a8075e9 100644 --- a/packages/backend/src/database/services/interaction/interactionRepository.service.test.ts +++ b/packages/backend/src/database/services/interaction/interactionRepository.service.test.ts @@ -10,21 +10,10 @@ describe("interactionRepository", () => { }); it("get all interactions", async () => { - { - const interactions = await interactionRepository.findBy({ - structureId: 1, - usagerRef: 7, - }); - - expect(interactions.length).toEqual(9); - } - { - const interactions = await interactionRepository.findBy({ - structureId: 1, - usagerRef: 7, - }); - - expect(interactions.length).toBeGreaterThan(2); - } + const interactions = await interactionRepository.findBy({ + structureId: 1, + usagerRef: 7, + }); + expect(interactions.length).toEqual(8); }); }); diff --git a/packages/backend/src/database/services/interaction/interactionRepository.service.ts b/packages/backend/src/database/services/interaction/interactionRepository.service.ts index 292728f9b5..547831daff 100644 --- a/packages/backend/src/database/services/interaction/interactionRepository.service.ts +++ b/packages/backend/src/database/services/interaction/interactionRepository.service.ts @@ -13,6 +13,8 @@ import { import { InteractionsTable } from "../../entities"; import { myDataSource } from "../_postgres"; import { InteractionType } from "@domifa/common"; +import { userUsagerLoginRepository } from "../user-usager"; +import { differenceInMinutes, parseISO } from "date-fns"; export const interactionRepository = myDataSource .getRepository(InteractionsTable) @@ -122,13 +124,6 @@ async function countPendingInteractionsIn({ lastInteractionOut: Date | null; }> { const INTERACTIONS_TO_CHECK = Object.assign([], INTERACTION_OK_LIST); - - if (structure.portailUsager.usagerLoginUpdateLastInteraction) { - INTERACTIONS_TO_CHECK.push("loginPortail"); - } - - const inArray = INTERACTIONS_TO_CHECK.join(", "); - // NOTE: cette requête ne renvoit pas de résultats pour les usagers de cette structure qui n'ont pas d'interaction const query = `SELECT coalesce (SUM(CASE WHEN i.type = 'courrierIn' THEN "nbCourrier" END), 0) AS "courrierIn", @@ -138,31 +133,52 @@ async function countPendingInteractionsIn({ FROM interactions i WHERE i."usagerUUID" = $2 AND i."interactionOutUUID" is null GROUP BY i."usagerRef"`; + const results = await interactionRepository.query(query, [ - inArray, + INTERACTIONS_TO_CHECK.join(", "), usagerUUID, ]); - const defaultResult = { - courrierIn: 0, - recommandeIn: 0, - colisIn: 0, - lastInteractionOut: null, - }; - - if (typeof results[0] === "undefined") { - return defaultResult; + if ( + typeof results[0] === "undefined" || + results[0] === null || + results[0]?.length === 0 + ) { + return { + courrierIn: 0, + recommandeIn: 0, + colisIn: 0, + lastInteractionOut: null, + }; } - if (results[0] === null || results[0].length === 0) { - return defaultResult; + let lastInteractionOut: Date | null = + results[0].lastInteractionOut !== null + ? results[0].lastInteractionOut === "string" + ? parseISO(results[0].lastInteractionOut) + : results[0].lastInteractionOut + : null; + + if (structure.portailUsager.usagerLoginUpdateLastInteraction) { + const lastUserUsagerLogin = await userUsagerLoginRepository.findOne({ + where: { + usagerUUID, + }, + order: { createdAt: "DESC" }, + }); + + if ( + differenceInMinutes(lastInteractionOut, lastUserUsagerLogin.createdAt) > 0 + ) { + lastInteractionOut = lastUserUsagerLogin.createdAt; + } } return { courrierIn: parseInt(results[0].courrierIn, 10), recommandeIn: parseInt(results[0].recommandeIn, 10), colisIn: parseInt(results[0].colisIn, 10), - lastInteractionOut: results[0].lastInteractionOut, + lastInteractionOut, }; } @@ -242,7 +258,6 @@ async function totalInteractionAllUsagersStructure({ colisIn: number; colisOut: number; npai: number; - loginPortail: number; }[] > { // NOTE: cette requête ne renvoit pas de résultats pour les usagers de cette structure qui n'ont pas d'interaction @@ -251,7 +266,6 @@ async function totalInteractionAllUsagersStructure({ coalesce (COUNT(CASE WHEN i.type = 'appel' THEN 1 END), 0) AS "appel", coalesce (COUNT(CASE WHEN i.type = 'visite' THEN 1 END), 0) AS "visite", coalesce (COUNT(CASE WHEN i.type = 'npai' THEN 1 END), 0) AS "npai", - coalesce (COUNT(CASE WHEN i.type = 'loginPortail' THEN 1 END), 0) AS "loginPortail", coalesce (SUM(CASE WHEN i.type = 'courrierIn' THEN "nbCourrier" END), 0) AS "courrierIn", coalesce (SUM(CASE WHEN i.type = 'courrierOut' THEN "nbCourrier" END), 0) AS "courrierOut", coalesce (SUM(CASE WHEN i.type = 'recommandeIn' THEN "nbCourrier" END), 0) AS "recommandeIn", @@ -264,17 +278,29 @@ async function totalInteractionAllUsagersStructure({ const results = await interactionRepository.query(query, [structureId]); - return results.map((x: any) => ({ - usagerRef: x.usagerRef, - courrierIn: parseInt(x.courrierIn, 10), - courrierOut: parseInt(x.courrierOut, 10), - recommandeIn: parseInt(x.recommandeIn, 10), - recommandeOut: parseInt(x.recommandeOut, 10), - colisIn: parseInt(x.colisIn, 10), - colisOut: parseInt(x.colisOut, 10), - appel: parseInt(x.appel, 10), - visite: parseInt(x.visite, 10), - loginPortail: parseInt(x.loginPortail, 10), - npai: parseInt(x.npai, 10), - })); + return results.map( + (x: { + usagerRef: string; + appel: string; + visite: string; + courrierIn: string; + courrierOut: string; + recommandeIn: string; + recommandeOut: string; + colisIn: string; + colisOut: string; + npai: string; + }) => ({ + usagerRef: parseInt(x.usagerRef, 10), + courrierIn: parseInt(x.courrierIn, 10), + courrierOut: parseInt(x.courrierOut, 10), + recommandeIn: parseInt(x.recommandeIn, 10), + recommandeOut: parseInt(x.recommandeOut, 10), + colisIn: parseInt(x.colisIn, 10), + colisOut: parseInt(x.colisOut, 10), + appel: parseInt(x.appel, 10), + visite: parseInt(x.visite, 10), + npai: parseInt(x.npai, 10), + }) + ); } diff --git a/packages/backend/src/database/services/user-usager/index.ts b/packages/backend/src/database/services/user-usager/index.ts index 803c7acd5f..3f8606b87a 100644 --- a/packages/backend/src/database/services/user-usager/index.ts +++ b/packages/backend/src/database/services/user-usager/index.ts @@ -1,2 +1,3 @@ export * from "./user-usager-security"; +export * from "./userUsagerLoginRepository.service"; export * from "./userUsagerRepository.service"; diff --git a/packages/backend/src/database/services/user-usager/userUsagerLoginRepository.service.test.ts b/packages/backend/src/database/services/user-usager/userUsagerLoginRepository.service.test.ts new file mode 100644 index 0000000000..cc95e332fb --- /dev/null +++ b/packages/backend/src/database/services/user-usager/userUsagerLoginRepository.service.test.ts @@ -0,0 +1,17 @@ +import { AppTestHelper } from "../../../util/test"; +import { userUsagerLoginRepository } from "./userUsagerLoginRepository.service"; + +describe("userUsagerLoginRepository", () => { + beforeAll(async () => { + await AppTestHelper.bootstrapTestConnection(); + }); + + afterAll(async () => { + await AppTestHelper.tearDownTestConnection(); + }); + + it("Count all logins made", async () => { + const users = await userUsagerLoginRepository.count(); + expect(users).toBeGreaterThan(2); + }); +}); diff --git a/packages/backend/src/database/services/user-usager/userUsagerLoginRepository.service.ts b/packages/backend/src/database/services/user-usager/userUsagerLoginRepository.service.ts new file mode 100644 index 0000000000..d162281ee7 --- /dev/null +++ b/packages/backend/src/database/services/user-usager/userUsagerLoginRepository.service.ts @@ -0,0 +1,19 @@ +import { UserUsagerLoginTable } from "../../entities"; +import { myDataSource } from "../_postgres"; + +export const userUsagerLoginRepository = myDataSource + .getRepository(UserUsagerLoginTable) + .extend({ + async totalLoginAllUsagersStructure(structureId: number): Promise< + | { + usagerUUID: string; + total: string; + }[] + | null + > { + return await userUsagerLoginRepository.query( + `SELECT u."usagerUUID", COUNT(uuid) AS "total" FROM user_usager_login u WHERE u."structureId" = $1 GROUP BY u."usagerUUID"`, + [structureId] + ); + }, + }); diff --git a/packages/backend/src/excel/export-structure-usagers/StructureUsagersExportModel.type.ts b/packages/backend/src/excel/export-structure-usagers/StructureUsagersExportModel.type.ts index 87f59a5cd3..e79147166c 100644 --- a/packages/backend/src/excel/export-structure-usagers/StructureUsagersExportModel.type.ts +++ b/packages/backend/src/excel/export-structure-usagers/StructureUsagersExportModel.type.ts @@ -5,6 +5,8 @@ export type StructureUsagersExportModel = { exportDate: Date; usagers: Usager[]; usagersInteractionsCountByType: { - [usagerRef: number]: { [interactionType in InteractionType]: number }; + [usagerRef: number]: { + [interactionType in InteractionType | "loginPortail"]: number; + }; }; }; diff --git a/packages/backend/src/interactions/interactions.controller.ts b/packages/backend/src/interactions/interactions.controller.ts index 5a62a3cf73..bc0778b078 100644 --- a/packages/backend/src/interactions/interactions.controller.ts +++ b/packages/backend/src/interactions/interactions.controller.ts @@ -23,7 +23,7 @@ import { UsagerAccessGuard, InteractionsGuard, } from "../auth/guards"; -import { interactionRepository } from "../database"; +import { interactionRepository, userUsagerLoginRepository } from "../database"; import { UserStructureAuthenticated, Interactions, @@ -105,6 +105,31 @@ export class InteractionsController { return new PageResultsDto(entities, pageMetaDto); } + @Post("search-login-portail/:usagerRef") + @AllowUserProfiles("structure") + public async getLoginPortailHistory( + @Param("usagerRef", new ParseIntPipe()) _usagerRef: number, + @CurrentUser() user: UserStructureAuthenticated, + @CurrentUsager() currentUsager: Usager, + @Body() pageOptionsDto: PageOptionsDto + ) { + const queryBuilder = userUsagerLoginRepository + .createQueryBuilder("user_usager_login") + .select([`"createdAt"`]) + .where({ + structureId: user.structureId, + usagerUUID: currentUsager.uuid, + }) + .orderBy(`"createdAt"`, pageOptionsDto.order) + .skip((pageOptionsDto.page - 1) * pageOptionsDto.take) + .take(pageOptionsDto.take); + + const itemCount = await queryBuilder.getCount(); + const entities = await queryBuilder.getRawMany(); + const pageMetaDto = new PageMetaDto({ itemCount, pageOptionsDto }); + return new PageResultsDto(entities, pageMetaDto); + } + @UseGuards(InteractionsGuard) @AllowUserProfiles("structure") @Delete(":usagerRef/:interactionUuid") diff --git a/packages/backend/src/interactions/services/interactionsCreator.service.spec.ts b/packages/backend/src/interactions/services/interactionsCreator.service.spec.ts index 1d147e81bc..529f1135d4 100644 --- a/packages/backend/src/interactions/services/interactionsCreator.service.spec.ts +++ b/packages/backend/src/interactions/services/interactionsCreator.service.spec.ts @@ -434,53 +434,4 @@ describe("interactionsCreator", () => { }); }); }); - - describe("5. Création d'une interaction à la suite d'une connexion au portail", () => { - it("Sans mise à jour de la date de dernier passage", async () => { - const interaction: InteractionDto = { - type: "loginPortail", - nbCourrier: 0, - }; - - const resultat = await interactionsCreator.createInteraction({ - usager, - user, - interaction, - }); - - expect(resultat.usager.lastInteraction.dateInteraction).toEqual( - usager.lastInteraction.dateInteraction - ); - expect(resultat.interaction.nbCourrier).toEqual(0); - }); - - it("Avec mise à jour de la date de dernier passage", async () => { - const interaction: InteractionDto = { - type: "loginPortail", - nbCourrier: 1111, // Test avec un faux numéro, on vérifie que c'est bien 0 qui est enregistré - }; - - user.structure.portailUsager.usagerLoginUpdateLastInteraction = true; - - const resultat = await interactionsCreator.createInteraction({ - usager, - user, - interaction, - }); - - expect(resultat.usager.lastInteraction.dateInteraction).toEqual( - MOCKED_NEW_DATE - ); - - expect(resultat.interaction.nbCourrier).toEqual(0); - - // Suppression de l'interaction sortante - await interactionsDeletor.deleteInteraction({ - interaction: resultat.interaction, - structure: user.structure, - usager, - user, - }); - }); - }); }); diff --git a/packages/backend/src/interactions/services/interactionsCreator.service.ts b/packages/backend/src/interactions/services/interactionsCreator.service.ts index 94143433d8..eab1704ae0 100644 --- a/packages/backend/src/interactions/services/interactionsCreator.service.ts +++ b/packages/backend/src/interactions/services/interactionsCreator.service.ts @@ -88,12 +88,7 @@ async function createInteraction({ interaction.nbCourrier = interaction.nbCourrier ?? 1; } else { interaction.nbCourrier = 0; - if ( - interaction.type === "appel" || - interaction.type === "visite" || - (interaction.type === "loginPortail" && - user.structure.portailUsager.usagerLoginUpdateLastInteraction) - ) { + if (interaction.type === "appel" || interaction.type === "visite") { usager.lastInteraction.dateInteraction = now; } } diff --git a/packages/backend/src/stats/services/structureStatsQuestionsInPeriodInteractionsRepository.service.ts b/packages/backend/src/stats/services/structureStatsQuestionsInPeriodInteractionsRepository.service.ts index 3b89d99044..97e4dea45d 100644 --- a/packages/backend/src/stats/services/structureStatsQuestionsInPeriodInteractionsRepository.service.ts +++ b/packages/backend/src/stats/services/structureStatsQuestionsInPeriodInteractionsRepository.service.ts @@ -1,5 +1,8 @@ import { Between } from "typeorm"; -import { interactionRepository } from "../../database"; +import { + interactionRepository, + userUsagerLoginRepository, +} from "../../database"; import { StructureStatsQuestionsInPeriodInteractions } from "../../_common/model/structure-stats"; import { InteractionType } from "@domifa/common"; @@ -84,13 +87,17 @@ async function getStats({ structureId, interactionType: "npai", }), - loginPortail: await countInteractions({ - dateInteractionBefore: endDateUTCExclusive, - dateInteractionAfter: startDateUTC, - structureId, - interactionType: "loginPortail", + loginPortail: await userUsagerLoginRepository.count({ + where: { + structureId, + createdAt: Between( + startDateUTC, + endDateUTCExclusive + ) as unknown as Date, + }, }), }; + return stats; } @@ -108,7 +115,6 @@ async function countInteractions({ if ( interactionType === "appel" || interactionType === "visite" || - interactionType === "loginPortail" || interactionType === "npai" ) { return interactionRepository.count({ diff --git a/packages/backend/src/usagers/controllers/export-structure-usagers.controller.ts b/packages/backend/src/usagers/controllers/export-structure-usagers.controller.ts index f153c68b15..c13524d091 100644 --- a/packages/backend/src/usagers/controllers/export-structure-usagers.controller.ts +++ b/packages/backend/src/usagers/controllers/export-structure-usagers.controller.ts @@ -22,6 +22,7 @@ import { UsagersService } from "../services/usagers.service"; import { format } from "date-fns"; import { InteractionType } from "@domifa/common"; +import { userUsagerLoginRepository } from "../../database"; @UseGuards(AuthGuard("jwt"), AppUserGuard) @ApiTags("export") @@ -59,7 +60,9 @@ export class ExportStructureUsagersController { const usagers = await this.usagersService.export(user.structureId); const usagersInteractionsCountByType: { - [usagerRef: number]: { [interactionType in InteractionType]: number }; + [usagerRef: number]: { + [interactionType in InteractionType | "loginPortail"]: number; + }; } = {}; const interactionsByUsagerMap = @@ -67,6 +70,11 @@ export class ExportStructureUsagersController { structureId: user.structureId, }); + const userUsagerLoginByUsagerMap = + await userUsagerLoginRepository.totalLoginAllUsagersStructure( + user.structureId + ); + for (const element of usagers) { const usager: Usager = element; const data = interactionsByUsagerMap.find( @@ -81,37 +89,30 @@ export class ExportStructureUsagersController { colisIn: number; colisOut: number; npai: number; - loginPortail: number; }) => x.usagerRef === usager.ref ); - if (data) { - usagersInteractionsCountByType[usager.ref] = { - courrierIn: data.courrierIn, - courrierOut: data.courrierOut, - recommandeIn: data.recommandeIn, - recommandeOut: data.recommandeOut, - colisIn: data.colisIn, - colisOut: data.colisOut, - appel: data.appel, - visite: data.visite, - loginPortail: data.loginPortail, - npai: data.npai, - }; - } else { - usagersInteractionsCountByType[usager.ref] = { - courrierIn: 0, - courrierOut: 0, - recommandeIn: 0, - recommandeOut: 0, - colisIn: 0, - colisOut: 0, - appel: 0, - loginPortail: 0, - visite: 0, - npai: 0, - }; - } + const userUsagerLogin = userUsagerLoginByUsagerMap.find( + (x: { usagerUUID: string; total: string }) => + x.usagerUUID === usager.uuid + ); + + const loginPortail = userUsagerLogin + ? parseInt(userUsagerLogin.total, 10) + : 0; + + usagersInteractionsCountByType[usager.ref] = { + courrierIn: data?.courrierIn ?? 0, + courrierOut: data?.courrierOut ?? 0, + recommandeIn: data?.recommandeIn ?? 0, + recommandeOut: data?.recommandeOut ?? 0, + colisIn: data?.colisIn ?? 0, + colisOut: data?.colisOut ?? 0, + appel: data?.appel ?? 0, + loginPortail, + visite: 0, + npai: data?.npai ?? 0, + }; } const model: StructureUsagersExportModel = { diff --git a/packages/backend/src/usagers/controllers/tests/usagers.controller.spec.ts b/packages/backend/src/usagers/controllers/tests/usagers.controller.spec.ts index 84c569d3b1..69a700468e 100644 --- a/packages/backend/src/usagers/controllers/tests/usagers.controller.spec.ts +++ b/packages/backend/src/usagers/controllers/tests/usagers.controller.spec.ts @@ -84,7 +84,7 @@ describe("Usagers Controller", () => { expect(usager.ayantsDroits[0].nom).toEqual( exceptedResponse.ayantsDroits[0].nom ); - console.log("XXX"); + expect(usager.ayantsDroits[0].prenom).toEqual( exceptedResponse.ayantsDroits[0].prenom ); diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index bb7a30419b..1ea7ec8c86 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -5,3 +5,4 @@ export * from "./message-sms"; export * from "./structure"; export * from "./usager"; export * from "./user-structure"; +export * from "./user-usager"; diff --git a/packages/frontend/src/_common/model/interaction/constants/INTERACTIONS_LABELS.const.ts b/packages/common/src/interactions/constants/INTERACTIONS_LABELS.const.ts similarity index 85% rename from packages/frontend/src/_common/model/interaction/constants/INTERACTIONS_LABELS.const.ts rename to packages/common/src/interactions/constants/INTERACTIONS_LABELS.const.ts index 3ad0129901..b2a23785d7 100644 --- a/packages/frontend/src/_common/model/interaction/constants/INTERACTIONS_LABELS.const.ts +++ b/packages/common/src/interactions/constants/INTERACTIONS_LABELS.const.ts @@ -1,4 +1,4 @@ -import { InteractionType } from "@domifa/common"; +import { type InteractionType } from "../types"; export const INTERACTIONS_LABELS_SINGULIER: { [key in InteractionType]: string; @@ -12,7 +12,6 @@ export const INTERACTIONS_LABELS_SINGULIER: { recommandeOut: "Avis de passage remis", visite: "Passage enregistré", npai: "Le courrier ne sera plus enregistré", - loginPortail: "Connexion au portail usager", }; export const INTERACTIONS_LABELS_PLURIEL: { @@ -27,5 +26,4 @@ export const INTERACTIONS_LABELS_PLURIEL: { recommandeOut: "Avis de passage remis", visite: "Passages enregistrés", npai: "Pli non distribuable enregistré", - loginPortail: "Connexion au portail usager", }; diff --git a/packages/common/src/interactions/constants/index.ts b/packages/common/src/interactions/constants/index.ts index c9b6570824..c4e66ff413 100644 --- a/packages/common/src/interactions/constants/index.ts +++ b/packages/common/src/interactions/constants/index.ts @@ -1,3 +1,4 @@ // @index('./*', f => `export * from '${f.path}'`) export * from "./INTERACTIONS_IN.const"; +export * from "./INTERACTIONS_LABELS.const"; export * from "./INTERACTIONS_OUT.const"; diff --git a/packages/common/src/interactions/types/InteractionType.type.ts b/packages/common/src/interactions/types/InteractionType.type.ts index afa5321fbd..e0f80b336d 100644 --- a/packages/common/src/interactions/types/InteractionType.type.ts +++ b/packages/common/src/interactions/types/InteractionType.type.ts @@ -7,5 +7,4 @@ export type InteractionType = | "colisOut" | "appel" | "visite" - | "npai" - | "loginPortail"; + | "npai"; diff --git a/packages/common/src/user-usager/UserUsagerLogin.interface.ts b/packages/common/src/user-usager/UserUsagerLogin.interface.ts new file mode 100644 index 0000000000..8cc584b8cd --- /dev/null +++ b/packages/common/src/user-usager/UserUsagerLogin.interface.ts @@ -0,0 +1,6 @@ +import { type AppEntity } from "../_core/AppEntity.type"; + +export interface UserUsagerLogin extends AppEntity { + usagerUUID: string; + structureId: number; +} diff --git a/packages/common/src/user-usager/index.ts b/packages/common/src/user-usager/index.ts new file mode 100644 index 0000000000..035b579ab0 --- /dev/null +++ b/packages/common/src/user-usager/index.ts @@ -0,0 +1,2 @@ +// @index('./*', f => `export * from '${f.path}'`) +export * from "./UserUsagerLogin.interface"; diff --git a/packages/frontend/src/_common/model/interaction/constants/index.ts b/packages/frontend/src/_common/model/interaction/constants/index.ts deleted file mode 100644 index 807c428b43..0000000000 --- a/packages/frontend/src/_common/model/interaction/constants/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -//@index('./*', f => `export * from '${f.path}'`) -export * from "./INTERACTIONS_LABELS.const"; diff --git a/packages/frontend/src/_common/model/interaction/index.ts b/packages/frontend/src/_common/model/interaction/index.ts index 7110aa8f58..cdd126ec4a 100644 --- a/packages/frontend/src/_common/model/interaction/index.ts +++ b/packages/frontend/src/_common/model/interaction/index.ts @@ -1,4 +1,3 @@ //@index('./*', f => `export * from '${f.path}'`) -export * from "./constants"; export * from "./InteractionForApi.interface"; export * from "./InteractionForms.type"; diff --git a/packages/frontend/src/_common/model/message-sms/MESSAGE_SMS_STATUS.const.ts b/packages/frontend/src/_common/model/message-sms/MESSAGE_SMS_STATUS.const.ts index 9fa63614fa..69748004f9 100644 --- a/packages/frontend/src/_common/model/message-sms/MESSAGE_SMS_STATUS.const.ts +++ b/packages/frontend/src/_common/model/message-sms/MESSAGE_SMS_STATUS.const.ts @@ -15,5 +15,4 @@ export const SMS_LABELS: { echeanceDeuxMois: "Sms rappel de renouvellement", dernierPassageTroisMois: "Avertissement dernier passage plus de 3 mois", decision: "Nouvelle décision", - loginPortail: "Connexion au portail usager", }; diff --git a/packages/frontend/src/_common/model/message-sms/MessageSms.type.ts b/packages/frontend/src/_common/model/message-sms/MessageSms.type.ts index 5abc4bbec7..448756991a 100644 --- a/packages/frontend/src/_common/model/message-sms/MessageSms.type.ts +++ b/packages/frontend/src/_common/model/message-sms/MessageSms.type.ts @@ -2,8 +2,9 @@ import { MessageSmsId, MessageSmsInteractionMetas, MessageSmsStatus, + MessageSmsReminderMetas, } from "@domifa/common"; -import { MessageSmsReminderMetas } from "."; + import { AppEntity } from "../../../_common/model"; export type MessageSms = AppEntity & { diff --git a/packages/frontend/src/_common/model/message-sms/MessageSmsReminderMetas.type.ts b/packages/frontend/src/_common/model/message-sms/MessageSmsReminderMetas.type.ts deleted file mode 100644 index 8d2bac62b0..0000000000 --- a/packages/frontend/src/_common/model/message-sms/MessageSmsReminderMetas.type.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type MessageSmsReminderMetas = { - type: string; - date: Date; -}; diff --git a/packages/frontend/src/_common/model/message-sms/index.ts b/packages/frontend/src/_common/model/message-sms/index.ts index 760a6f0b76..4fca211a56 100644 --- a/packages/frontend/src/_common/model/message-sms/index.ts +++ b/packages/frontend/src/_common/model/message-sms/index.ts @@ -1,4 +1,3 @@ // @index('./*', f => `export * from '${f.path}'`) export * from "./MESSAGE_SMS_STATUS.const"; export * from "./MessageSms.type"; -export * from "./MessageSmsReminderMetas.type"; diff --git a/packages/frontend/src/app/modules/manage-usagers/components/column-interactions/column-interactions.component.ts b/packages/frontend/src/app/modules/manage-usagers/components/column-interactions/column-interactions.component.ts index bc7e37aa91..02124d01b5 100644 --- a/packages/frontend/src/app/modules/manage-usagers/components/column-interactions/column-interactions.component.ts +++ b/packages/frontend/src/app/modules/manage-usagers/components/column-interactions/column-interactions.component.ts @@ -10,13 +10,12 @@ import { NgbModalRef, NgbModal } from "@ng-bootstrap/ng-bootstrap"; import { Subscription } from "rxjs"; import { InteractionInForApi, - INTERACTIONS_LABELS_SINGULIER, DEFAULT_MODAL_OPTIONS, } from "../../../../../_common/model"; import { CustomToastService } from "../../../shared/services"; import { UsagerFormModel } from "../../../usager-shared/interfaces"; import { InteractionService } from "../../../usager-shared/services"; -import { InteractionType } from "@domifa/common"; +import { INTERACTIONS_LABELS_SINGULIER, InteractionType } from "@domifa/common"; @Component({ selector: "app-manage-usagers-interactions", diff --git a/packages/frontend/src/app/modules/stats/components/structure-stats/structure-stats.component.ts b/packages/frontend/src/app/modules/stats/components/structure-stats/structure-stats.component.ts index 0cd49d6ae6..165e887021 100644 --- a/packages/frontend/src/app/modules/stats/components/structure-stats/structure-stats.component.ts +++ b/packages/frontend/src/app/modules/stats/components/structure-stats/structure-stats.component.ts @@ -137,7 +137,13 @@ export class StatsComponent implements OnInit, AfterViewInit, OnDestroy { if (year) { period.start = new Date(year.toString() + "-01-01"); period.end = new Date(year.toString() + "-12-31"); + } else { + this.end = + this.toDate !== null + ? new Date(this.formatter.formatEn(this.toDate)) + : null; } + const structureId = this.me?.structureId as number; this.subscription.add( diff --git a/packages/frontend/src/app/modules/usager-profil/components/_historiques/profil-historique-login-portail/profil-historique-login-portail.component.html b/packages/frontend/src/app/modules/usager-profil/components/_historiques/profil-historique-login-portail/profil-historique-login-portail.component.html new file mode 100644 index 0000000000..884fadbe0c --- /dev/null +++ b/packages/frontend/src/app/modules/usager-profil/components/_historiques/profil-historique-login-portail/profil-historique-login-portail.component.html @@ -0,0 +1,83 @@ +

+ Historique des connexions à Mon DomiFa: + {{ searchResults.meta.itemCount }} connexions +

+ + + +
+ + + + + + + + + + + + + + +
+ Historique des connexions au portail "Mon DomiFa" +
Date
+ {{ interaction.createdAt | date : "dd MMMM yyyy à HH:mm" }} +
+
+
+

Aucune connexion enregistrée sur Mon DomiFa

+
+
+ +
+
+ + +
+ + +
diff --git a/packages/frontend/src/app/modules/usager-profil/components/_historiques/profil-historique-login-portail/profil-historique-login-portail.component.spec.ts b/packages/frontend/src/app/modules/usager-profil/components/_historiques/profil-historique-login-portail/profil-historique-login-portail.component.spec.ts new file mode 100644 index 0000000000..1fb9367cce --- /dev/null +++ b/packages/frontend/src/app/modules/usager-profil/components/_historiques/profil-historique-login-portail/profil-historique-login-portail.component.spec.ts @@ -0,0 +1,35 @@ +import { ComponentFixture, TestBed } from "@angular/core/testing"; + +import { ProfilHistoriqueLoginPortailComponent } from "./profil-historique-login-portail.component"; +import { HttpClientTestingModule } from "@angular/common/http/testing"; +import { NoopAnimationsModule } from "@angular/platform-browser/animations"; +import { StoreModule } from "@ngrx/store"; +import { _usagerReducer } from "../../../../../shared"; +import { UsagerFormModel } from "../../../../usager-shared/interfaces"; +import { SharedModule } from "../../../../shared/shared.module"; + +describe("ProfilHistoriqueLoginPortailComponent", () => { + let component: ProfilHistoriqueLoginPortailComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ProfilHistoriqueLoginPortailComponent], + imports: [ + HttpClientTestingModule, + StoreModule.forRoot({ app: _usagerReducer }), + NoopAnimationsModule, + SharedModule, + ], + }).compileComponents(); + + fixture = TestBed.createComponent(ProfilHistoriqueLoginPortailComponent); + component = fixture.componentInstance; + component.usager = new UsagerFormModel(); + fixture.detectChanges(); + }); + + it("should create", () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/packages/frontend/src/app/modules/usager-profil/components/_historiques/profil-historique-login-portail/profil-historique-login-portail.component.ts b/packages/frontend/src/app/modules/usager-profil/components/_historiques/profil-historique-login-portail/profil-historique-login-portail.component.ts new file mode 100644 index 0000000000..907b6fc7d4 --- /dev/null +++ b/packages/frontend/src/app/modules/usager-profil/components/_historiques/profil-historique-login-portail/profil-historique-login-portail.component.ts @@ -0,0 +1,80 @@ +import { Component, Input, OnDestroy, OnInit } from "@angular/core"; +import { UserUsagerLogin } from "@domifa/common"; +import { Subscription } from "rxjs"; +import { + UserStructure, + PageOptions, + Order, + PageResults, +} from "../../../../../../_common/model"; +import { UsagerFormModel } from "../../../../usager-shared/interfaces"; +import { InteractionService } from "../../../../usager-shared/services"; +import { fadeIn } from "../../../../../shared"; + +@Component({ + animations: [fadeIn], + selector: "app-profil-historique-login-portail", + templateUrl: "./profil-historique-login-portail.component.html", + styleUrls: ["../historique-table.scss"], +}) +export class ProfilHistoriqueLoginPortailComponent + implements OnInit, OnDestroy +{ + @Input() public usager!: UsagerFormModel; + @Input() public me!: UserStructure; + + public interactions: UserUsagerLogin[]; + private subscription = new Subscription(); + + public loading: boolean; + + public params: PageOptions = { + order: Order.DESC, + page: 1, + take: 10, + }; + + public searchResults: PageResults = { + data: [], + meta: { + page: 0, + take: 0, + itemCount: 0, + pageCount: 0, + hasPreviousPage: false, + hasNextPage: false, + }, + }; + + constructor(private readonly interactionService: InteractionService) { + this.loading = true; + this.interactions = []; + } + + public ngOnInit(): void { + this.getInteractions(); + } + + public getInteractions() { + this.loading = true; + this.subscription.add( + this.interactionService + .getLoginPortail(this.usager.ref, this.params) + .subscribe((searchResults: PageResults) => { + console.log(searchResults); + this.loading = false; + this.interactions = searchResults.data; + this.searchResults = searchResults; + window.scroll({ + behavior: "smooth", + left: 0, + top: 0, + }); + }) + ); + } + + public ngOnDestroy(): void { + this.subscription.unsubscribe(); + } +} diff --git a/packages/frontend/src/app/modules/usager-profil/components/pages/profil-general-section/profil-general-section.component.ts b/packages/frontend/src/app/modules/usager-profil/components/pages/profil-general-section/profil-general-section.component.ts index ae60e21b86..e6df2825e2 100644 --- a/packages/frontend/src/app/modules/usager-profil/components/pages/profil-general-section/profil-general-section.component.ts +++ b/packages/frontend/src/app/modules/usager-profil/components/pages/profil-general-section/profil-general-section.component.ts @@ -12,7 +12,6 @@ import { BaseUsagerProfilPageComponent } from "../base-usager-profil-page/base-u import { ETAPES_DEMANDE_URL, InteractionInForApi, - INTERACTIONS_LABELS_SINGULIER, DEFAULT_MODAL_OPTIONS, } from "../../../../../../_common/model"; import { minDateNaissance, formatDateToNgb } from "../../../../../shared"; @@ -21,7 +20,11 @@ import { Interaction } from "../../../../usager-shared/interfaces"; import { InteractionService } from "../../../../usager-shared/services/interaction.service"; import { UsagerProfilService } from "../../../services/usager-profil.service"; import { Store } from "@ngrx/store"; -import { USAGER_DECISION_STATUT_LABELS, InteractionType } from "@domifa/common"; +import { + INTERACTIONS_LABELS_SINGULIER, + USAGER_DECISION_STATUT_LABELS, + InteractionType, +} from "@domifa/common"; @Component({ selector: "app-profil-general-section", diff --git a/packages/frontend/src/app/modules/usager-profil/components/pages/profil-historique/profil-historique.component.html b/packages/frontend/src/app/modules/usager-profil/components/pages/profil-historique/profil-historique.component.html index 9635190827..de306398da 100644 --- a/packages/frontend/src/app/modules/usager-profil/components/pages/profil-historique/profil-historique.component.html +++ b/packages/frontend/src/app/modules/usager-profil/components/pages/profil-historique/profil-historique.component.html @@ -111,6 +111,7 @@

Historique du dossier

[usager]="usager" > +
Historique du dossier [usager]="usager" >
+
+ +
diff --git a/packages/frontend/src/app/modules/usager-profil/components/pages/profil-historique/profil-historique.component.ts b/packages/frontend/src/app/modules/usager-profil/components/pages/profil-historique/profil-historique.component.ts index 9a57ef64f0..437db32070 100644 --- a/packages/frontend/src/app/modules/usager-profil/components/pages/profil-historique/profil-historique.component.ts +++ b/packages/frontend/src/app/modules/usager-profil/components/pages/profil-historique/profil-historique.component.ts @@ -14,6 +14,7 @@ type HistorySections = | "notes" | "sms" | "procurations" + | "login-portail" | "transferts"; @Component({ selector: "app-profil-historique", @@ -86,5 +87,14 @@ export class ProfilHistoriqueComponent name: "SMS envoyés", }); } + if ( + this.me.structure.portailUsager.enabledByDomifa && + this.me.structure.portailUsager.enabledByStructure + ) { + this.sections.push({ + id: "login-portail", + name: "Connexions à Mon DomiFa", + }); + } } } diff --git a/packages/frontend/src/app/modules/usager-profil/usager-profil.module.ts b/packages/frontend/src/app/modules/usager-profil/usager-profil.module.ts index c199e3aebb..ac99bb618b 100644 --- a/packages/frontend/src/app/modules/usager-profil/usager-profil.module.ts +++ b/packages/frontend/src/app/modules/usager-profil/usager-profil.module.ts @@ -36,6 +36,7 @@ import { NgbDateCustomParserFormatter, CustomDatepickerI18n, } from "../shared/services"; +import { ProfilHistoriqueLoginPortailComponent } from "./components/_historiques/profil-historique-login-portail/profil-historique-login-portail.component"; @NgModule({ declarations: [ @@ -58,6 +59,7 @@ import { ProfilHistoriqueProcurationsComponent, ProfilHistoriqueTransfertsComponent, ProfilHistoriqueDecisionsComponent, + ProfilHistoriqueLoginPortailComponent, ], imports: [ CommonModule, diff --git a/packages/frontend/src/app/modules/usager-shared/interfaces/interaction.ts b/packages/frontend/src/app/modules/usager-shared/interfaces/interaction.ts index 3490e2c00d..5239026aea 100644 --- a/packages/frontend/src/app/modules/usager-shared/interfaces/interaction.ts +++ b/packages/frontend/src/app/modules/usager-shared/interfaces/interaction.ts @@ -1,8 +1,9 @@ -import { InteractionType, CommonInteraction } from "@domifa/common"; import { INTERACTIONS_LABELS_PLURIEL, INTERACTIONS_LABELS_SINGULIER, -} from "../../../../_common/model/interaction"; + InteractionType, + CommonInteraction, +} from "@domifa/common"; export class Interaction implements CommonInteraction { public type: InteractionType; diff --git a/packages/frontend/src/app/modules/usager-shared/services/interaction.service.ts b/packages/frontend/src/app/modules/usager-shared/services/interaction.service.ts index 485971d385..a35666f52f 100644 --- a/packages/frontend/src/app/modules/usager-shared/services/interaction.service.ts +++ b/packages/frontend/src/app/modules/usager-shared/services/interaction.service.ts @@ -14,6 +14,7 @@ import { import { Interaction } from "../interfaces"; import { Store } from "@ngrx/store"; import { cacheManager } from "../../../shared"; +import { UserUsagerLogin } from "@domifa/common"; @Injectable({ providedIn: "root", @@ -59,6 +60,16 @@ export class InteractionService { ); } + public getLoginPortail( + usagerRef: number, + pageOptions: PageOptions + ): Observable> { + return this.http.post>( + `${this.endPoint}search-login-portail/${usagerRef}`, + pageOptions + ); + } + public delete( usagerRef: number, interactionUuid: string diff --git a/packages/portail-admins/src/_common/_core/ApiMessage.type.ts b/packages/portail-admins/src/_common/_core/ApiMessage.type.ts deleted file mode 100644 index e110311c12..0000000000 --- a/packages/portail-admins/src/_common/_core/ApiMessage.type.ts +++ /dev/null @@ -1 +0,0 @@ -export type ApiMessage = { message: string }; diff --git a/packages/portail-admins/src/_common/_core/index.ts b/packages/portail-admins/src/_common/_core/index.ts index 077e42eed1..64fdd18590 100644 --- a/packages/portail-admins/src/_common/_core/index.ts +++ b/packages/portail-admins/src/_common/_core/index.ts @@ -1,3 +1,2 @@ //@index('./*', f => `export * from '${f.path}'`) -export * from "./ApiMessage.type"; export * from "./AppEntity.type"; diff --git a/packages/portail-admins/src/_common/index.ts b/packages/portail-admins/src/_common/index.ts index b00da00468..b223ccf38b 100644 --- a/packages/portail-admins/src/_common/index.ts +++ b/packages/portail-admins/src/_common/index.ts @@ -1,7 +1,6 @@ // @index('./*', f => `export * from '${f.path}'`) export * from "./_core"; export * from "./_portail-admin"; -export * from "./interaction"; export * from "./stats"; export * from "./structure"; export * from "./structure-doc"; diff --git a/packages/portail-admins/src/_common/interaction/InteractionEvent.type.ts b/packages/portail-admins/src/_common/interaction/InteractionEvent.type.ts deleted file mode 100644 index 25ed980f22..0000000000 --- a/packages/portail-admins/src/_common/interaction/InteractionEvent.type.ts +++ /dev/null @@ -1 +0,0 @@ -export type InteractionEvent = "create" | "delete"; diff --git a/packages/portail-admins/src/_common/interaction/InteractionIn.type.ts b/packages/portail-admins/src/_common/interaction/InteractionIn.type.ts deleted file mode 100644 index de4a73971f..0000000000 --- a/packages/portail-admins/src/_common/interaction/InteractionIn.type.ts +++ /dev/null @@ -1 +0,0 @@ -export type InteractionIn = "courrierIn" | "recommandeIn" | "colisIn"; diff --git a/packages/portail-admins/src/_common/interaction/InteractionOut.type.ts b/packages/portail-admins/src/_common/interaction/InteractionOut.type.ts deleted file mode 100644 index 0fb4544c0f..0000000000 --- a/packages/portail-admins/src/_common/interaction/InteractionOut.type.ts +++ /dev/null @@ -1 +0,0 @@ -export type InteractionOut = "courrierOut" | "recommandeOut" | "colisOut"; diff --git a/packages/portail-admins/src/_common/interaction/InteractionType.type.ts b/packages/portail-admins/src/_common/interaction/InteractionType.type.ts deleted file mode 100644 index afa5321fbd..0000000000 --- a/packages/portail-admins/src/_common/interaction/InteractionType.type.ts +++ /dev/null @@ -1,11 +0,0 @@ -export type InteractionType = - | "courrierIn" - | "courrierOut" - | "recommandeIn" - | "recommandeOut" - | "colisIn" - | "colisOut" - | "appel" - | "visite" - | "npai" - | "loginPortail"; diff --git a/packages/portail-admins/src/_common/interaction/Interactions.type.ts b/packages/portail-admins/src/_common/interaction/Interactions.type.ts deleted file mode 100644 index 8e9df6d809..0000000000 --- a/packages/portail-admins/src/_common/interaction/Interactions.type.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { AppEntity } from ".."; -import { InteractionEvent } from "./InteractionEvent.type"; -import { InteractionType } from "./InteractionType.type"; - -export type Interactions = AppEntity & { - id?: number | null; - createdAt?: Date; - content?: string; - dateInteraction: Date | null; - nbCourrier: number; - structureId: number | null; - type: InteractionType; - usagerRef: number | null; - usagerUUID?: string | null; - userId: number | null; - userName: string | null; - uuid: string; - event: InteractionEvent; - previousValue?: Interactions; // if event === 'delete' -}; diff --git a/packages/portail-admins/src/_common/interaction/constants/INTERACTIONS_IN_AVAILABLE.const.ts b/packages/portail-admins/src/_common/interaction/constants/INTERACTIONS_IN_AVAILABLE.const.ts deleted file mode 100644 index f350534300..0000000000 --- a/packages/portail-admins/src/_common/interaction/constants/INTERACTIONS_IN_AVAILABLE.const.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { InteractionIn } from "../InteractionIn.type"; - -export const INTERACTIONS_IN_AVAILABLE: InteractionIn[] = [ - "courrierIn", - "recommandeIn", - "colisIn", -]; diff --git a/packages/portail-admins/src/_common/interaction/constants/INTERACTIONS_LABELS.const.ts b/packages/portail-admins/src/_common/interaction/constants/INTERACTIONS_LABELS.const.ts deleted file mode 100644 index af91bba38b..0000000000 --- a/packages/portail-admins/src/_common/interaction/constants/INTERACTIONS_LABELS.const.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { InteractionType } from "../InteractionType.type"; - -export const INTERACTIONS_LABELS_SINGULIER: { - [key in InteractionType]: string; -} = { - appel: "Appel téléphonique enregistré", - colisIn: "Colis enregistré", - colisOut: "Colis remis", - courrierIn: "Courrier enregistré", - courrierOut: "Courrier remis", - recommandeIn: "Avis de passage enregistré", - recommandeOut: "Avis de passage remis", - visite: "Passage enregistré", - npai: "Le courrier ne sera plus enregistré", - loginPortail: "Connexion au portail usager", -}; - -export const INTERACTIONS_LABELS_PLURIEL: { - [key in InteractionType]: string; -} = { - appel: "Appels téléphoniques", - colisIn: "Colis enregistrés", - colisOut: "Colis remis", - courrierIn: "Courriers enregistrés", - courrierOut: "Courriers remis", - recommandeIn: "Avis de passage enregistrés", - recommandeOut: "Avis de passage remis", - visite: "Passages enregistrés", - npai: "Pli non distribuable enregistré", - loginPortail: "Connexion au portail usager", -}; diff --git a/packages/portail-admins/src/_common/interaction/constants/INTERACTIONS_OUT_AVAILABLE.const.ts b/packages/portail-admins/src/_common/interaction/constants/INTERACTIONS_OUT_AVAILABLE.const.ts deleted file mode 100644 index cda2e8dc26..0000000000 --- a/packages/portail-admins/src/_common/interaction/constants/INTERACTIONS_OUT_AVAILABLE.const.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { InteractionOut } from "../InteractionOut.type"; - -export const INTERACTIONS_OUT_AVAILABLE: InteractionOut[] = [ - "courrierOut", - "recommandeOut", - "colisOut", -]; diff --git a/packages/portail-admins/src/_common/interaction/constants/index.ts b/packages/portail-admins/src/_common/interaction/constants/index.ts deleted file mode 100644 index 113c9b869d..0000000000 --- a/packages/portail-admins/src/_common/interaction/constants/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -//@index('./*', f => `export * from '${f.path}'`) -export * from "./INTERACTIONS_IN_AVAILABLE.const"; -export * from "./INTERACTIONS_LABELS.const"; -export * from "./INTERACTIONS_OUT_AVAILABLE.const"; diff --git a/packages/portail-admins/src/_common/interaction/index.ts b/packages/portail-admins/src/_common/interaction/index.ts deleted file mode 100644 index e5aacfaa17..0000000000 --- a/packages/portail-admins/src/_common/interaction/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -//@index('./*', f => `export * from '${f.path}'`) -export * from "./constants"; -export * from "./InteractionEvent.type"; -export * from "./InteractionIn.type"; -export * from "./InteractionOut.type"; -export * from "./Interactions.type"; -export * from "./InteractionType.type"; diff --git a/packages/portail-admins/src/_common/stats/AdminStructureStatsData.type.ts b/packages/portail-admins/src/_common/stats/AdminStructureStatsData.type.ts index f61c0cddc9..6b0e81599f 100644 --- a/packages/portail-admins/src/_common/stats/AdminStructureStatsData.type.ts +++ b/packages/portail-admins/src/_common/stats/AdminStructureStatsData.type.ts @@ -1,7 +1,9 @@ -import { InteractionType } from "../interaction/InteractionType.type"; +import { + InteractionType, + StructureType, + UsagerDecisionStatut, +} from "@domifa/common"; import { StructureAdmin } from "../structure/StructureAdmin.type"; -import { StructureType } from "../structure/StructureType.type"; -import { UsagerDecisionStatut } from "../usager/UsagerDecisionStatut.type"; import { StatsByRegion } from "./StatsByRegion.type"; export type AdminStructureStatsData = { diff --git a/packages/portail-admins/src/_common/stats/MessageSmsId.type.ts b/packages/portail-admins/src/_common/stats/MessageSmsId.type.ts deleted file mode 100644 index e2a9637d6d..0000000000 --- a/packages/portail-admins/src/_common/stats/MessageSmsId.type.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { MessageSmsReminders } from "."; -import { InteractionType } from "../interaction"; - -export type MessageSmsId = InteractionType | MessageSmsReminders; diff --git a/packages/portail-admins/src/_common/stats/MessageSmsReminders.type.ts b/packages/portail-admins/src/_common/stats/MessageSmsReminders.type.ts deleted file mode 100644 index 55e33f398c..0000000000 --- a/packages/portail-admins/src/_common/stats/MessageSmsReminders.type.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type MessageSmsReminders = - | "echeanceDeuxMois" // Fin de dom à venir - | "dernierPassageTroisMois" // N'est pas passé depuis 3 mois, radiation à venir - | "decision"; // Validation ou non d'une demande diff --git a/packages/portail-admins/src/_common/stats/StatsPeriod.type.ts b/packages/portail-admins/src/_common/stats/StatsPeriod.type.ts deleted file mode 100644 index af0ba0e197..0000000000 --- a/packages/portail-admins/src/_common/stats/StatsPeriod.type.ts +++ /dev/null @@ -1 +0,0 @@ -export type StatsPeriod = "days" | "months"; diff --git a/packages/portail-admins/src/_common/stats/StatsSmsApiDatas.type.ts b/packages/portail-admins/src/_common/stats/StatsSmsApiDatas.type.ts deleted file mode 100644 index af1b934ca9..0000000000 --- a/packages/portail-admins/src/_common/stats/StatsSmsApiDatas.type.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type StatsSmsApiDatas = { - name: string; - value: string; -}[]; diff --git a/packages/portail-admins/src/_common/stats/StatsSmsChartsDatas.type.ts b/packages/portail-admins/src/_common/stats/StatsSmsChartsDatas.type.ts deleted file mode 100644 index 19ffdfdde6..0000000000 --- a/packages/portail-admins/src/_common/stats/StatsSmsChartsDatas.type.ts +++ /dev/null @@ -1,7 +0,0 @@ -export type StatsSmsChartsDatas = { - name: string; - series: { - name: string; - value: string; - }[]; -}[]; diff --git a/packages/portail-admins/src/_common/stats/index.ts b/packages/portail-admins/src/_common/stats/index.ts index e86811c0eb..a554e5682f 100644 --- a/packages/portail-admins/src/_common/stats/index.ts +++ b/packages/portail-admins/src/_common/stats/index.ts @@ -1,13 +1,8 @@ // @index('./*', f => `export * from '${f.path}'`) export * from "./AdminStructureStatsData.type"; export * from "./DEFAULT_PUBLIC_STATS.const"; -export * from "./MessageSmsId.type"; -export * from "./MessageSmsReminders.type"; export * from "./PublicStats.type"; export * from "./STATS_REGIONS_FOR_MAP.const"; export * from "./StatsByMonth.type"; export * from "./StatsByRegion.type"; -export * from "./StatsPeriod.type"; -export * from "./StatsSmsApiDatas.type"; -export * from "./StatsSmsChartsDatas.type"; export * from "./StatsTerritory.type"; diff --git a/packages/portail-admins/src/_common/usager/AyantDroitLienParente.type.ts b/packages/portail-admins/src/_common/usager/AyantDroitLienParente.type.ts deleted file mode 100644 index 736900194d..0000000000 --- a/packages/portail-admins/src/_common/usager/AyantDroitLienParente.type.ts +++ /dev/null @@ -1 +0,0 @@ -export type AyantDroiLienParent = "AUTRE" | "CONJOINT" | "ENFANT" | "PARENT"; diff --git a/packages/portail-admins/src/_common/usager/UsagerAyantDroit.type.ts b/packages/portail-admins/src/_common/usager/UsagerAyantDroit.type.ts index 1c22e70360..b96807aeaf 100644 --- a/packages/portail-admins/src/_common/usager/UsagerAyantDroit.type.ts +++ b/packages/portail-admins/src/_common/usager/UsagerAyantDroit.type.ts @@ -1,4 +1,4 @@ -import { AyantDroiLienParent } from "./AyantDroitLienParente.type"; +import { AyantDroiLienParent } from "@domifa/common"; export type UsagerAyantDroit = { nom: string; diff --git a/packages/portail-admins/src/_common/usager/UsagerDecision.type.ts b/packages/portail-admins/src/_common/usager/UsagerDecision.type.ts index d637ed8a9e..190bd82672 100644 --- a/packages/portail-admins/src/_common/usager/UsagerDecision.type.ts +++ b/packages/portail-admins/src/_common/usager/UsagerDecision.type.ts @@ -1,7 +1,6 @@ +import { UsagerDecisionStatut, UsagerTypeDom } from "@domifa/common"; import { UsagerDecisionMotif } from "./UsagerDecisionMotif.type"; import { UsagerDecisionOrientation } from "./UsagerDecisionOrientation.type"; -import { UsagerDecisionStatut } from "./UsagerDecisionStatut.type"; -import { UsagerTypeDom } from "./UsagerTypeDom.type"; export type UsagerDecision = { uuid?: string; // permet d'identifier une décision en cas de suppression de l'historique diff --git a/packages/portail-admins/src/_common/usager/UsagerDecisionStatut.type.ts b/packages/portail-admins/src/_common/usager/UsagerDecisionStatut.type.ts deleted file mode 100644 index 419b224b9b..0000000000 --- a/packages/portail-admins/src/_common/usager/UsagerDecisionStatut.type.ts +++ /dev/null @@ -1,6 +0,0 @@ -export type UsagerDecisionStatut = - | "VALIDE" - | "INSTRUCTION" - | "ATTENTE_DECISION" - | "REFUS" - | "RADIE"; diff --git a/packages/portail-admins/src/_common/usager/UsagerSexe.type.ts b/packages/portail-admins/src/_common/usager/UsagerSexe.type.ts deleted file mode 100644 index 523cae30f6..0000000000 --- a/packages/portail-admins/src/_common/usager/UsagerSexe.type.ts +++ /dev/null @@ -1 +0,0 @@ -export type UsagerSexe = "homme" | "femme"; diff --git a/packages/portail-admins/src/_common/usager/UsagerTypeDom.type.ts b/packages/portail-admins/src/_common/usager/UsagerTypeDom.type.ts deleted file mode 100644 index 174be3cafe..0000000000 --- a/packages/portail-admins/src/_common/usager/UsagerTypeDom.type.ts +++ /dev/null @@ -1 +0,0 @@ -export type UsagerTypeDom = "PREMIERE_DOM" | "RENOUVELLEMENT"; diff --git a/packages/portail-admins/src/_common/usager/constants/LIEN_PARENTE_LABELS.const.ts b/packages/portail-admins/src/_common/usager/constants/LIEN_PARENTE_LABELS.const.ts index 196edc6fcc..2af8452a1f 100644 --- a/packages/portail-admins/src/_common/usager/constants/LIEN_PARENTE_LABELS.const.ts +++ b/packages/portail-admins/src/_common/usager/constants/LIEN_PARENTE_LABELS.const.ts @@ -1,4 +1,4 @@ -import { AyantDroiLienParent } from "../AyantDroitLienParente.type"; +import { AyantDroiLienParent } from "@domifa/common"; export const LIEN_PARENTE_LABELS: { [key in AyantDroiLienParent]: string } = { AUTRE: "Autre personne à la charge du domicilié", diff --git a/packages/portail-admins/src/_common/usager/constants/USAGER_DECISION_STATUT_COLORS.const.ts b/packages/portail-admins/src/_common/usager/constants/USAGER_DECISION_STATUT_COLORS.const.ts index 553128beae..6ba37e3b34 100644 --- a/packages/portail-admins/src/_common/usager/constants/USAGER_DECISION_STATUT_COLORS.const.ts +++ b/packages/portail-admins/src/_common/usager/constants/USAGER_DECISION_STATUT_COLORS.const.ts @@ -1,4 +1,4 @@ -import { UsagerDecisionStatut } from ".."; +import { UsagerDecisionStatut } from "@domifa/common"; export const USAGER_DECISION_STATUT_COLORS: { [key in UsagerDecisionStatut]: string; diff --git a/packages/portail-admins/src/_common/usager/constants/USAGER_DECISION_STATUT_LABELS.const.ts b/packages/portail-admins/src/_common/usager/constants/USAGER_DECISION_STATUT_LABELS.const.ts index b1e8c91d74..8906a8158b 100644 --- a/packages/portail-admins/src/_common/usager/constants/USAGER_DECISION_STATUT_LABELS.const.ts +++ b/packages/portail-admins/src/_common/usager/constants/USAGER_DECISION_STATUT_LABELS.const.ts @@ -1,4 +1,4 @@ -import { UsagerDecisionStatut } from ".."; +import { UsagerDecisionStatut } from "@domifa/common"; export const USAGER_DECISION_STATUT_LABELS: { [key in UsagerDecisionStatut]: string; diff --git a/packages/portail-admins/src/_common/usager/constants/USAGER_DECISION_STATUT_LABELS_PROFIL.const.ts b/packages/portail-admins/src/_common/usager/constants/USAGER_DECISION_STATUT_LABELS_PROFIL.const.ts index 93a197f7a7..35f4ad6f2b 100644 --- a/packages/portail-admins/src/_common/usager/constants/USAGER_DECISION_STATUT_LABELS_PROFIL.const.ts +++ b/packages/portail-admins/src/_common/usager/constants/USAGER_DECISION_STATUT_LABELS_PROFIL.const.ts @@ -1,6 +1,5 @@ -import { UsagerDecisionStatut } from ".."; +import { UsagerDecisionStatut } from "@domifa/common"; -/* DÉCISIONS */ export const USAGER_DECISION_STATUT_LABELS_PROFIL: { [key in UsagerDecisionStatut]: string; } = { diff --git a/packages/portail-admins/src/_common/usager/index.ts b/packages/portail-admins/src/_common/usager/index.ts index 1c52cc1564..2e15248d1c 100644 --- a/packages/portail-admins/src/_common/usager/index.ts +++ b/packages/portail-admins/src/_common/usager/index.ts @@ -1,8 +1,10 @@ -export * from "./AyantDroitLienParente.type"; +//@index('./*', f => `export * from '${f.path}'`) +export * from "./constants"; export * from "./UsagerAyantDroit.type"; export * from "./UsagerDecision.type"; export * from "./UsagerDecisionMotif.type"; -export * from "./UsagerDecisionStatut.type"; +export * from "./UsagerDecisionOrientation.type"; +export * from "./UsagerDecisionStatusColor.type"; export * from "./UsagerEcheanceInfos.type"; export * from "./UsagerLastInteractions.type"; export * from "./UsagerOptions.type"; @@ -12,5 +14,3 @@ export * from "./UsagerOptionsTransfert.type"; export * from "./UsagerPreferenceContact.type"; export * from "./UsagerRdv.type"; export * from "./UsagerRdvInfos.type"; -export * from "./UsagerSexe.type"; -export * from "./UsagerTypeDom.type"; diff --git a/packages/portail-admins/src/app/modules/admin-structures/components/admin-structures-stats/admin-structures-stats.component.ts b/packages/portail-admins/src/app/modules/admin-structures/components/admin-structures-stats/admin-structures-stats.component.ts index 3b6d474a86..f8ddd1076c 100644 --- a/packages/portail-admins/src/app/modules/admin-structures/components/admin-structures-stats/admin-structures-stats.component.ts +++ b/packages/portail-admins/src/app/modules/admin-structures/components/admin-structures-stats/admin-structures-stats.component.ts @@ -5,7 +5,7 @@ import { AdminStructureStatsData, PortailAdminProfile, } from "../../../../../_common"; -import { INTERACTIONS_LABELS_PLURIEL } from "../../../../../_common/interaction"; + import { DASHBOARD_STATUS_LABELS, STRUCTURE_TYPE_LABELS, @@ -15,6 +15,7 @@ import { AdminAuthService } from "../../../admin-auth/services/admin-auth.servic import { AdminStructuresApiClient } from "../../../shared/services"; import { REGIONS_LISTE } from "../../../shared/territoires"; import { AdminStructuresStatsVM, adminStructuresStatsVmBuilder } from "./vm"; +import { INTERACTIONS_LABELS_PLURIEL } from "@domifa/common"; @Component({ selector: "app-admin-structures-stats", diff --git a/packages/portail-admins/src/app/modules/admin-structures/components/admin-structures-stats/vm/AdminStructuresStatsVM.type.ts b/packages/portail-admins/src/app/modules/admin-structures/components/admin-structures-stats/vm/AdminStructuresStatsVM.type.ts index f9a2e9875d..bd9c2abac9 100644 --- a/packages/portail-admins/src/app/modules/admin-structures/components/admin-structures-stats/vm/AdminStructuresStatsVM.type.ts +++ b/packages/portail-admins/src/app/modules/admin-structures/components/admin-structures-stats/vm/AdminStructuresStatsVM.type.ts @@ -1,9 +1,9 @@ import { InteractionType, - StatsByRegion, StructureType, UsagerDecisionStatut, -} from "../../../../../../_common"; +} from "@domifa/common"; +import { StatsByRegion } from "../../../../../../_common"; export type AdminStructuresStatsVM = { usersCount: number; diff --git a/packages/portail-admins/src/app/modules/admin-structures/components/admin-structures-stats/vm/adminStructuresStatsVmBuilder.service.ts b/packages/portail-admins/src/app/modules/admin-structures/components/admin-structures-stats/vm/adminStructuresStatsVmBuilder.service.ts index 2e0a32ce0a..a9a9f73801 100644 --- a/packages/portail-admins/src/app/modules/admin-structures/components/admin-structures-stats/vm/adminStructuresStatsVmBuilder.service.ts +++ b/packages/portail-admins/src/app/modules/admin-structures/components/admin-structures-stats/vm/adminStructuresStatsVmBuilder.service.ts @@ -1,10 +1,10 @@ import { - AdminStructureStatsData, - INTERACTIONS_LABELS_PLURIEL, InteractionType, StructureType, UsagerDecisionStatut, -} from "../../../../../../_common"; + INTERACTIONS_LABELS_PLURIEL, +} from "@domifa/common"; +import { AdminStructureStatsData } from "../../../../../../_common"; import { DASHBOARD_STATUS_LABELS, STRUCTURE_TYPE_LABELS, diff --git a/packages/portail-admins/src/app/modules/shared/services/api/admin-structures-api-client.service.ts b/packages/portail-admins/src/app/modules/shared/services/api/admin-structures-api-client.service.ts index 57fd2b4601..a0aa1131e7 100644 --- a/packages/portail-admins/src/app/modules/shared/services/api/admin-structures-api-client.service.ts +++ b/packages/portail-admins/src/app/modules/shared/services/api/admin-structures-api-client.service.ts @@ -9,8 +9,8 @@ import { StructureAdmin, UserNewAdmin, } from "../../../../../_common"; -import { ApiMessage } from "../../../../../_common/_core"; import { structuresCache } from "../../store/structuresCache.service"; +import { ApiMessage } from "@domifa/common"; const BASE_URL = environment.apiUrl + "admin/structures"; @Injectable()