Skip to content

Commit

Permalink
chore: add event when email is deleted or expired
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasCharrier committed Nov 20, 2024
1 parent 9f1c48a commit 2e87bca
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/models/actionEvent/actionEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -70,6 +71,7 @@ export const EventCodeToReadable: Record<EventCode, string> = {
[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";
Expand Down Expand Up @@ -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),
});
Expand Down
5 changes: 5 additions & 0 deletions src/server/schedulers/setEmailExpired.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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é`
);
Expand Down
6 changes: 6 additions & 0 deletions src/server/schedulers/userContractEndingScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 2e87bca

Please sign in to comment.