primera instancia de validador y carga del excel de usuarios, falta agregar las relaciones con las carreras y verificar los validadores
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
// 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 }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user