30 lines
846 B
TypeScript
30 lines
846 B
TypeScript
import { Controller } from '@nestjs/common'
|
|
import { Ctx, EventPattern, Payload, RmqContext } from '@nestjs/microservices'
|
|
import type { OtpRequestedEvent } from '@teacinema/contracts'
|
|
|
|
import { RmqService } from '../../infra/rmq/rmq.service'
|
|
|
|
import { NotificationsService } from './notifications.service'
|
|
|
|
@Controller()
|
|
export class NotificationsController {
|
|
constructor(
|
|
private readonly notificationsService: NotificationsService,
|
|
private readonly rmqService: RmqService
|
|
) {}
|
|
|
|
@EventPattern('auth.otp.requested')
|
|
public async otpRequested(
|
|
@Payload() data: OtpRequestedEvent,
|
|
@Ctx() ctx: RmqContext
|
|
) {
|
|
try {
|
|
await this.notificationsService.sendOtp(data)
|
|
this.rmqService.ack(ctx)
|
|
} catch (e) {
|
|
console.log('OTP processing error', e.message ?? e)
|
|
this.rmqService.nack(ctx)
|
|
}
|
|
}
|
|
}
|