wallet
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
import { Processor, WorkerHost, OnWorkerEvent } from '@nestjs/bullmq';
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { Job } from 'bullmq';
|
||||
import { UserRepository } from 'src/modules/users/repositories/user.repository';
|
||||
import { SmsNotificationQueueJob } from '../interfaces/jobs-queue.interface';
|
||||
import { SmsNotificationQueueJob } from '../interfaces/jobs-queue.interface';
|
||||
import { AdminRepository } from 'src/modules/admin/repositories/admin.repository';
|
||||
import { NotificationQueueNameEnum } from '../constants/queue';
|
||||
import { SmsService } from '../services/sms.service';
|
||||
import { SmsSentEvent } from '../events/sms.events';
|
||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||
|
||||
@Processor(NotificationQueueNameEnum.SMS)
|
||||
@@ -15,8 +13,7 @@ export class SmsProcessor extends WorkerHost {
|
||||
|
||||
constructor(
|
||||
private readonly adminRepository: AdminRepository,
|
||||
private readonly userRepository: UserRepository,
|
||||
private readonly smsService: SmsService,
|
||||
private readonly smsService: SmsService,
|
||||
private readonly eventEmitter: EventEmitter2,
|
||||
) {
|
||||
super();
|
||||
@@ -29,14 +26,7 @@ export class SmsProcessor extends WorkerHost {
|
||||
|
||||
try {
|
||||
let phone!: string;
|
||||
if ('userId' in recipient) {
|
||||
const user = await this.userRepository.findOne({ id: recipient.userId });
|
||||
if (!user || !user.phone) {
|
||||
this.logger.warn(`User ${recipient.userId} not found or has no phone number`);
|
||||
throw new Error('User phone number is required for SMS notifications');
|
||||
}
|
||||
phone = user.phone;
|
||||
}
|
||||
|
||||
if ('adminId' in recipient) {
|
||||
const admin = await this.adminRepository.findOne({ id: recipient.adminId });
|
||||
if (!admin || !admin.phone) {
|
||||
@@ -58,7 +48,6 @@ export class SmsProcessor extends WorkerHost {
|
||||
|
||||
this.logger.log(`SMS notification sent successfully to ${phone}`);
|
||||
|
||||
this.eventEmitter.emit(SmsSentEvent.name, new SmsSentEvent(phone, restaurantId));
|
||||
|
||||
return {
|
||||
success: true,
|
||||
|
||||
Reference in New Issue
Block a user