feat: add email/phone change notifications
This commit is contained in:
parent
5d3e468bf6
commit
e7292e7f74
@ -1,6 +1,10 @@
|
||||
import { Inject, Injectable } from '@nestjs/common'
|
||||
import { ClientProxy } from '@nestjs/microservices'
|
||||
import { OtpRequestedEvent } from '@teacinema/contracts'
|
||||
import {
|
||||
EmailChangedEvent,
|
||||
OtpRequestedEvent,
|
||||
PhoneChangedEvent
|
||||
} from '@teacinema/contracts'
|
||||
|
||||
@Injectable()
|
||||
export class MessagingService {
|
||||
@ -11,4 +15,12 @@ export class MessagingService {
|
||||
public otpRequested(data: OtpRequestedEvent) {
|
||||
return this.client.emit('auth.otp.requested', data)
|
||||
}
|
||||
|
||||
public phoneChangeRequested(data: PhoneChangedEvent) {
|
||||
return this.client.emit('account.phone.changed', data)
|
||||
}
|
||||
|
||||
public emailChangeRequested(data: EmailChangedEvent) {
|
||||
return this.client.emit('account.email.changed', data)
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import {
|
||||
InitPhoneChangeRequest
|
||||
} from '@teacinema/contracts/gen/account'
|
||||
|
||||
import { MessagingService } from '@/infra/messaging/messaging.service'
|
||||
import { OtpService } from '@/modules/otp/otp.service'
|
||||
import { UserRepository } from '@/shared/utils/repositories'
|
||||
|
||||
@ -19,6 +20,7 @@ import { AccountRepository } from './account.repository'
|
||||
@Injectable()
|
||||
export class AccountService {
|
||||
public constructor(
|
||||
private readonly messagingService: MessagingService,
|
||||
private readonly accountRepository: AccountRepository,
|
||||
private readonly userRepository: UserRepository,
|
||||
private readonly otpService: OtpService
|
||||
@ -60,7 +62,7 @@ export class AccountService {
|
||||
}
|
||||
|
||||
const { code, hash } = await this.otpService.send(email, 'email')
|
||||
console.log('CODE', code)
|
||||
this.messagingService.emailChangeRequested({ email, code: code.toString() })
|
||||
await this.accountRepository.upsertPendingChange({
|
||||
accountId: userId,
|
||||
type: 'email',
|
||||
@ -124,7 +126,10 @@ export class AccountService {
|
||||
}
|
||||
|
||||
const { code, hash } = await this.otpService.send(phone, 'phone')
|
||||
console.log('CODE', code)
|
||||
this.messagingService.phoneChangeRequested({
|
||||
phone,
|
||||
code: code.toString()
|
||||
})
|
||||
await this.accountRepository.upsertPendingChange({
|
||||
accountId: userId,
|
||||
type: 'phone',
|
||||
|
||||
@ -1383,9 +1383,9 @@
|
||||
integrity sha512-q3DURJbSk3k8MNWFIYaSM4LEcBgPbWa+HJmBz/nzYT4kuYitJVSXxpZ97kr0Ea+81AZwAU3JhQKlkK0SBWUi0A==
|
||||
|
||||
"@teacinema/contracts@^1.0.0":
|
||||
version "1.1.0"
|
||||
resolved "https://git.ksv741.keenetic.pro/api/packages/teacinema/npm/%40teacinema%2Fcontracts/-/1.1.0/contracts-1.1.0.tgz#0d2f03f283dc9ee048eeb770152127f2037b7133"
|
||||
integrity sha512-x90R4R96AgrUDzOjUT7ePtc7phG3Gx61sI8/CZ1hETF3Ok/TWTHblxX/CIZVcOormBrxEh1FfU39P8/nfno91g==
|
||||
version "1.1.1"
|
||||
resolved "https://git.ksv741.keenetic.pro/api/packages/teacinema/npm/%40teacinema%2Fcontracts/-/1.1.1/contracts-1.1.1.tgz#69fc54e0e096cad5ecc5d8bb654d982b6c70996b"
|
||||
integrity sha512-yK3Th430sWumcnm2/jyEx8dtaA59hmCvCAnul+q/JbW+C2s/AyhBEBoxToDVxx/KKTDixDePJ3O3EnNnIHGgRw==
|
||||
dependencies:
|
||||
"@nestjs/microservices" "^11.1.12"
|
||||
protoc "33.4.0"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user