-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
134 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// src/events/notification-events/email-failed.event.ts | ||
export class EmailFailedEvent { | ||
constructor( | ||
public readonly email: string, | ||
public readonly errorMessage: string, | ||
) {} | ||
} |
24 changes: 24 additions & 0 deletions
24
api/src/modules/events/api-events/handlers/emai-failed-event.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// src/events/notification-events/handlers/email-failed-event.handler.ts | ||
import { EventsHandler, IEventHandler } from '@nestjs/cqrs'; | ||
import { EmailFailedEvent } from '../email-failed.event'; | ||
import { API_EVENT_TYPES } from '@api/modules/events/events.enum'; | ||
import { ApiEventsService } from '@api/modules/events/api-events/api-events.service'; | ||
|
||
@EventsHandler(EmailFailedEvent) | ||
export class EmailFailedEventHandler | ||
implements IEventHandler<EmailFailedEvent> | ||
{ | ||
constructor(private readonly apiEventsService: ApiEventsService) {} | ||
|
||
async handle(event: EmailFailedEvent): Promise<void> { | ||
console.warn('EmailFailedEventHandler', event); | ||
await this.apiEventsService.create({ | ||
eventType: API_EVENT_TYPES.EMAIL_FAILED, | ||
resourceId: null, | ||
payload: { | ||
email: event.email, | ||
errorMessage: event.errorMessage, | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { Global, Module } from '@nestjs/common'; | ||
import { ApiEventsModule } from './api-events/api-events.module'; | ||
import { CqrsModule } from '@nestjs/cqrs'; | ||
import { UserSignedUpEventHandler } from '@api/modules/events/user-events/handlers/user-signed-up.handler'; | ||
import { PasswordRecoveryRequestedEventHandler } from '@api/modules/events/user-events/handlers/password-recovery-requested.handler'; | ||
import { EmailFailedEventHandler } from '@api/modules/events/api-events/handlers/emai-failed-event.handler'; | ||
|
||
@Global() | ||
@Module({ | ||
imports: [ApiEventsModule], | ||
imports: [CqrsModule, ApiEventsModule], | ||
providers: [ | ||
UserSignedUpEventHandler, | ||
PasswordRecoveryRequestedEventHandler, | ||
EmailFailedEventHandler, | ||
], | ||
exports: [CqrsModule], | ||
}) | ||
export class EventsModule {} |
26 changes: 26 additions & 0 deletions
26
api/src/modules/events/user-events/handlers/password-recovery-requested.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// src/events/user-events/handlers/password-recovery-requested.handler.ts | ||
import { EventsHandler, IEventHandler } from '@nestjs/cqrs'; | ||
import { PasswordRecoveryRequestedEvent } from '../password-recovery-requested.event'; | ||
import { ApiEventsService } from '@api/modules/events/api-events/api-events.service'; | ||
import { API_EVENT_TYPES } from '@api/modules/events/events.enum'; | ||
|
||
@EventsHandler(PasswordRecoveryRequestedEvent) | ||
export class PasswordRecoveryRequestedEventHandler | ||
implements IEventHandler<PasswordRecoveryRequestedEvent> | ||
{ | ||
constructor(private readonly apiEventsService: ApiEventsService) {} | ||
|
||
async handle(event: PasswordRecoveryRequestedEvent): Promise<void> { | ||
console.warn('PasswordRecoveryRequestedEventHandler', event); | ||
await this.apiEventsService.create({ | ||
eventType: API_EVENT_TYPES.USER_PASSWORD_RECOVERY_REQUESTED, | ||
resourceId: event.userId, | ||
payload: { | ||
email: event.email, | ||
warning: event.userId | ||
? null | ||
: `Email ${event.email} not found when trying to recover password`, | ||
}, | ||
}); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
api/src/modules/events/user-events/handlers/user-signed-up.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// src/events/user-events/handlers/user-signed-up.handler.ts | ||
import { EventsHandler, IEventHandler } from '@nestjs/cqrs'; | ||
import { UserSignedUpEvent } from '../user-signed-up.event'; | ||
import { ApiEventsService } from '@api/modules/events/api-events/api-events.service'; | ||
import { API_EVENT_TYPES } from '@api/modules/events/events.enum'; | ||
|
||
@EventsHandler(UserSignedUpEvent) | ||
export class UserSignedUpEventHandler | ||
implements IEventHandler<UserSignedUpEvent> | ||
{ | ||
constructor(private readonly apiEventsService: ApiEventsService) {} | ||
|
||
async handle(event: UserSignedUpEvent): Promise<void> { | ||
await this.apiEventsService.create({ | ||
eventType: API_EVENT_TYPES.USER_SIGNED_UP, | ||
resourceId: event.userId, | ||
payload: { | ||
email: event.email, | ||
}, | ||
}); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
api/src/modules/events/user-events/password-recovery-requested.event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// src/events/user-events/password-recovery-requested.event.ts | ||
export class PasswordRecoveryRequestedEvent { | ||
constructor( | ||
public readonly email: string, | ||
public readonly userId?: string, | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// src/events/user-events/user-signed-up.event.ts | ||
export class UserSignedUpEvent { | ||
constructor( | ||
public readonly userId: string, | ||
public readonly email: string, | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { User } from "@shared/entities/users/user.entity"; | ||
|
||
export const DATABASE_ENTITIES = [User]; | ||
export const COMMON_DATABASE_ENTITIES = [User]; |