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