Files
cargaMasiva_api/src/excel/excel.controller.ts
T

35 lines
1.1 KiB
TypeScript

// src/excel/excel.controller.ts
import {
Controller,
Post,
UploadedFile,
UseInterceptors,
BadRequestException,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { ExcelService } from './excel.service';
import { ExcelDocumentation } from './excel.documentation';
@Controller('excel')
export class ExcelController {
constructor(private readonly excelService: ExcelService) {}
@Post('verify')
@UseInterceptors(FileInterceptor('file'))
@ExcelDocumentation.verifyExcel()
async verifyExcel(@UploadedFile() file: Express.Multer.File) {
if (!file) throw new BadRequestException('Se requiere un archivo .xlsx');
const errors = await this.excelService.validateFile(file.buffer);
return { valid: errors.length === 0, errors };
}
@Post('load')
@UseInterceptors(FileInterceptor('file'))
@ExcelDocumentation.loadExcel()
async loadExcel(@UploadedFile() file: Express.Multer.File) {
if (!file) throw new BadRequestException('Se requiere un archivo .xlsx');
const result = await this.excelService.loadFile(file.buffer);
return result; // { inserted: X }
}
}