From 2e87bcad767d38135af2e1ca05c656369a1f3a53 Mon Sep 17 00:00:00 2001 From: Lucas Charrier Date: Wed, 20 Nov 2024 16:00:07 +0100 Subject: [PATCH] chore: add event when email is deleted or expired --- src/models/actionEvent/actionEvent.ts | 6 ++++++ src/server/schedulers/setEmailExpired.ts | 5 +++++ src/server/schedulers/userContractEndingScheduler.ts | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/src/models/actionEvent/actionEvent.ts b/src/models/actionEvent/actionEvent.ts index 6beb7793..4ce6f92a 100644 --- a/src/models/actionEvent/actionEvent.ts +++ b/src/models/actionEvent/actionEvent.ts @@ -13,6 +13,7 @@ export enum EventCode { MEMBER_REDIRECTION_DELETED = "MEMBER_REDIRECTION_DELETED", MEMBER_EMAIL_CREATED = "MEMBER_EMAIL_CREATED", MEMBER_EMAIL_DELETED = "MEMBER_EMAIL_DELETED", + MEMBER_EMAIL_EXPIRED = "MEMBER_EMAIL_EXPIRED", MEMBER_PASSWORD_UPDATED = "MEMBER_PASSWORD_UPDATED", MEMBER_RESPONDER_CREATED = "MEMBER_RESPONDER_CREATED", MEMBER_RESPONDER_UPDATED = "MEMBER_RESPONDER_UPDATED", @@ -70,6 +71,7 @@ export const EventCodeToReadable: Record = { [EventCode.ORGANIZATION_CREATED]: "Organization créée", [EventCode.ORGANIZATION_UPDATED]: "Organization mise à jour", [EventCode.MEMBER_SERVICE_ACCOUNT_DELETED]: "Compte de service supprimé", + [EventCode.MEMBER_EMAIL_EXPIRED]: "Compte défini comme expiré", }; export const SYSTEM_NAME = "system"; @@ -111,6 +113,10 @@ export const EventMemberEmailDeletedPayload = z.object({ action_code: z.literal(EventCode.MEMBER_EMAIL_DELETED), }); +export const EventMemberEmailExpiredPayload = z.object({ + action_code: z.literal(EventCode.MEMBER_EMAIL_EXPIRED), +}); + export const EventMemberPasswordUpdatedPayload = z.object({ action_code: z.literal(EventCode.MEMBER_PASSWORD_UPDATED), }); diff --git a/src/server/schedulers/setEmailExpired.ts b/src/server/schedulers/setEmailExpired.ts index f54b80a5..4b73b3e7 100644 --- a/src/server/schedulers/setEmailExpired.ts +++ b/src/server/schedulers/setEmailExpired.ts @@ -38,6 +38,11 @@ export async function setEmailExpired( primary_email_status: EmailStatusCode.EMAIL_EXPIRED, }) .execute(); + await addEvent({ + action_code: EventCode.MEMBER_EMAIL_EXPIRED, + created_by_username: SYSTEM_NAME, + action_on_username: user.username, + }); console.log( `Email principal pour ${user.username} défini comme expiré` ); diff --git a/src/server/schedulers/userContractEndingScheduler.ts b/src/server/schedulers/userContractEndingScheduler.ts index 0deba8af..fe8c69b3 100644 --- a/src/server/schedulers/userContractEndingScheduler.ts +++ b/src/server/schedulers/userContractEndingScheduler.ts @@ -292,6 +292,12 @@ export async function deleteOVHEmailAcounts( primary_email_status: EmailStatusCode.EMAIL_DELETED, }) .execute(); + await addEvent({ + action_code: EventCode.MEMBER_EMAIL_DELETED, + created_by_username: SYSTEM_NAME, + action_on_username: user.username, + }); + console.log(`Suppression de l'email ovh pour ${user.username}`); } catch { console.log(