import { BadRequestException, Body, Controller, Inject, Param, Post, Req, UploadedFile, UseGuards, UseInterceptors, } from '@nestjs/common'; import { FileInterceptor } from '@nestjs/platform-express'; import { MasterService } from '../service/master.service'; import { Express } from 'express'; import { UserService } from 'src/module/user/service/user.service'; import { ENTITYTYPE_USER } from 'src/constant/global.constant'; import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service'; import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard'; @Controller('master') @UseGuards(JwtAuthGuard) export class MasterController { constructor( private readonly masterService: MasterService, private readonly entityService: EntityServiceImpl, ) {} @Post('uploadMeta') @UseInterceptors(FileInterceptor('file')) async uploadMasterMetaXls(@UploadedFile() file: Express.Multer.File) { if (!file) { throw new BadRequestException('File is required'); } return await this.masterService.uploadMeta(file.buffer); } @Post('uploadData') @UseInterceptors(FileInterceptor('file')) async uploadMasterDataXls( @UploadedFile() file: Express.Multer.File, @Req() req: Request & { user: any }, ) { const loggedInUser = req.user.userData; if (!file) { throw new BadRequestException('File is required'); } return await this.masterService.uploadData(file.buffer, loggedInUser); } @Post('uploadEntity/:entityType') @UseInterceptors(FileInterceptor('file')) async uploadEntityDataXls( @Param('entityType') entityType: string, @UploadedFile() file: Express.Multer.File, @Req() req: Request & { user: any }, @Body('duplicateHandling') duplicateHandling: 'skip_duplicates' | 'overwrite_items', ) { const loggedInUser = req.user.userData; // let loggedInUser = await this.entityService.getEntityData(ENTITYTYPE_USER, requestedUser.userId); if (!file) { throw new BadRequestException('File is required'); } return await this.masterService.uploadEntityData( file.buffer, entityType, loggedInUser, duplicateHandling, ); } }