mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
feat(nestjs): migrate to NestJS
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { events } from '@/common/events/events';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import {
|
||||
IAuthSendedResetPassword,
|
||||
IAuthSignedUpEventPayload,
|
||||
} from '../Auth.interfaces';
|
||||
import { Queue } from 'bullmq';
|
||||
import { InjectQueue } from '@nestjs/bullmq';
|
||||
import { SendResetPasswordMailJobPayload } from '../processors/SendResetPasswordMail.processor';
|
||||
import {
|
||||
SendResetPasswordMailJob,
|
||||
SendResetPasswordMailQueue,
|
||||
SendSignupVerificationMailJob,
|
||||
SendSignupVerificationMailQueue,
|
||||
} from '../Auth.constants';
|
||||
import { SendSignupVerificationMailJobPayload } from '../processors/SendSignupVerificationMail.processor';
|
||||
|
||||
@Injectable()
|
||||
export class AuthMailSubscriber {
|
||||
constructor(
|
||||
@InjectQueue(SendResetPasswordMailQueue)
|
||||
private readonly sendResetPasswordMailQueue: Queue,
|
||||
|
||||
@InjectQueue(SendSignupVerificationMailQueue)
|
||||
private readonly sendSignupVerificationMailQueue: Queue,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param {IAuthSignedUpEventPayload} payload
|
||||
*/
|
||||
@OnEvent(events.auth.signUp)
|
||||
async handleSignupSendVerificationMail(payload: IAuthSignedUpEventPayload) {
|
||||
try {
|
||||
const job = await this.sendSignupVerificationMailQueue.add(
|
||||
SendSignupVerificationMailJob,
|
||||
{
|
||||
email: payload.user.email,
|
||||
fullName: payload.user.firstName,
|
||||
token: payload.user.verifyToken,
|
||||
} as SendSignupVerificationMailJobPayload,
|
||||
{
|
||||
delay: 0,
|
||||
},
|
||||
);
|
||||
console.log(job);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {IAuthSendedResetPassword} payload
|
||||
*/
|
||||
@OnEvent(events.auth.sendResetPassword)
|
||||
async handleSendResetPasswordMail(payload: IAuthSendedResetPassword) {
|
||||
await this.sendResetPasswordMailQueue.add(
|
||||
SendResetPasswordMailJob,
|
||||
{
|
||||
user: payload.user,
|
||||
token: payload.token,
|
||||
} as SendResetPasswordMailJobPayload,
|
||||
{
|
||||
delay: 0,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user