upload fix bug
This commit is contained in:
@@ -20,6 +20,8 @@ import { UtilsModule } from '../utils/utils.module';
|
||||
import { NotificationsGateway } from './notifications.gateway';
|
||||
import { WsAdminAuthGuard } from './guards/ws-admin-auth.guard';
|
||||
import { InAppProcessor } from './processors/in-app.processor';
|
||||
import { AdminModule } from '../admin/admin.module';
|
||||
import { UserModule } from '../users/user.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -42,6 +44,8 @@ import { InAppProcessor } from './processors/in-app.processor';
|
||||
},
|
||||
}),
|
||||
}),
|
||||
AdminModule,
|
||||
UserModule,
|
||||
],
|
||||
controllers: [NotificationsController],
|
||||
providers: [
|
||||
|
||||
@@ -1,22 +1,19 @@
|
||||
import { Processor, WorkerHost, OnWorkerEvent } from '@nestjs/bullmq';
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { Job } from 'bullmq';
|
||||
import { InjectRepository } from '@mikro-orm/nestjs';
|
||||
import { EntityManager } from '@mikro-orm/postgresql';
|
||||
import { Notification } from '../entities/notification.entity';
|
||||
import { UserRepository } from 'src/modules/users/repositories/user.repository';
|
||||
import { SmsNotificationQueueJob } from '../interfaces/jobs-queue.interface';
|
||||
import { User } from '../../users/entities/user.entity';
|
||||
import { AdminRepository } from 'src/modules/admin/repositories/admin.repository';
|
||||
import { NotificationQueueNameEnum } from '../constants/queue';
|
||||
import { SmsService } from 'src/modules/utils/sms.service';
|
||||
import { Admin } from 'src/modules/admin/entities/admin.entity';
|
||||
|
||||
@Processor(NotificationQueueNameEnum.SMS)
|
||||
export class SmsProcessor extends WorkerHost {
|
||||
private readonly logger = new Logger(SmsProcessor.name);
|
||||
|
||||
constructor(
|
||||
@InjectRepository(Notification)
|
||||
private readonly em: EntityManager,
|
||||
private readonly adminRepository: AdminRepository,
|
||||
private readonly userRepository: UserRepository,
|
||||
private readonly smsService: SmsService,
|
||||
) {
|
||||
super();
|
||||
@@ -30,7 +27,7 @@ export class SmsProcessor extends WorkerHost {
|
||||
try {
|
||||
let phone!: string;
|
||||
if ('userId' in recipient) {
|
||||
const user = await this.em.findOne(User, { id: recipient.userId });
|
||||
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');
|
||||
@@ -38,7 +35,7 @@ export class SmsProcessor extends WorkerHost {
|
||||
phone = user.phone;
|
||||
}
|
||||
if ('adminId' in recipient) {
|
||||
const admin = await this.em.findOne(Admin, { id: recipient.adminId });
|
||||
const admin = await this.adminRepository.findOne({ id: recipient.adminId });
|
||||
if (!admin || !admin.phone) {
|
||||
this.logger.warn(`Admin ${recipient.adminId} not found or has no phone number`);
|
||||
throw new Error('Admin phone number is required for SMS notifications');
|
||||
|
||||
@@ -1,33 +1,57 @@
|
||||
import { type File, FileInterceptor, FilesInterceptor } from '@nest-lab/fastify-multer';
|
||||
import { Controller, Post, UploadedFile, UploadedFiles, UseGuards, UseInterceptors } from '@nestjs/common';
|
||||
import { ApiBody, ApiConsumes, ApiOperation, ApiBearerAuth, ApiTags, ApiHeader } from '@nestjs/swagger';
|
||||
|
||||
import { ApiBody, ApiConsumes, ApiOperation, ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { UploadMultipleFileDto, UploadSingleFileDto } from '../DTO/upload-file.dto';
|
||||
import { UploaderService } from '../providers/uploader.service';
|
||||
import { AdminAuthGuard } from '../../auth/guards/adminAuth.guard';
|
||||
import { AuthGuard } from '../../auth/guards/auth.guard';
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiTags('uploader')
|
||||
@Controller('uploader')
|
||||
@Controller()
|
||||
export class UploaderController {
|
||||
constructor(private readonly uploaderService: UploaderService) {}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Upload a file (admin)' })
|
||||
@ApiConsumes('multipart/form-data')
|
||||
@UseInterceptors(FileInterceptor('file'))
|
||||
@ApiBody({ type: UploadSingleFileDto })
|
||||
@Post('single-file')
|
||||
@Post('public/single-file')
|
||||
uploadFile(@UploadedFile() file: File) {
|
||||
return this.uploaderService.uploadFile(file);
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Uploads multiple files' })
|
||||
@ApiConsumes('multipart/form-data')
|
||||
@UseInterceptors(FilesInterceptor('files'))
|
||||
@ApiBody({ type: UploadMultipleFileDto })
|
||||
@Post('multi-file')
|
||||
@Post('public/multi-file')
|
||||
uploadFiles(@UploadedFiles() files: File[]) {
|
||||
return this.uploaderService.uploadMultiple(files);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Upload a file (admin)' })
|
||||
@ApiConsumes('multipart/form-data')
|
||||
@UseInterceptors(FileInterceptor('file'))
|
||||
@ApiBody({ type: UploadSingleFileDto })
|
||||
@Post('admin/single-file')
|
||||
uploadFileAdmin(@UploadedFile() file: File) {
|
||||
return this.uploaderService.uploadFile(file);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Uploads multiple files' })
|
||||
@ApiConsumes('multipart/form-data')
|
||||
@UseInterceptors(FilesInterceptor('files'))
|
||||
@ApiBody({ type: UploadMultipleFileDto })
|
||||
@Post('admin/multi-file')
|
||||
uploadFilesAdmin(@UploadedFiles() files: File[]) {
|
||||
return this.uploaderService.uploadMultiple(files);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user