Se agredó la entidad servActivos, se agregaron funciones para activacion de dervicio
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// src/excel/excel.controller.ts
|
||||
import { Controller, Post, Get, UseGuards, Request, Res, UploadedFile, UseInterceptors, HttpStatus } from '@nestjs/common';
|
||||
import { Controller, Post, Get, UseGuards, Request, Res, UploadedFile, UseInterceptors, HttpStatus, Param, ParseIntPipe } from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
@@ -22,7 +22,8 @@ export class ExcelController {
|
||||
@ExcelDocumentation.verifyExcel()
|
||||
async verifyExcel(@UploadedFile() file: Express.Multer.File, @Request() req) {
|
||||
const userId: number = req.user.userId; // ahora sí existe
|
||||
const errors = await this.excelService.validateFile(file.buffer);
|
||||
const status = await this.excelService.validateFile(file.buffer);
|
||||
const errors = status.errors;
|
||||
await this.movimientoService.log(
|
||||
|
||||
'VERIFY',
|
||||
@@ -47,14 +48,17 @@ export class ExcelController {
|
||||
}
|
||||
try {
|
||||
const result = await this.excelService.loadFile(file.buffer);
|
||||
await this.movimientoService.log(
|
||||
|
||||
'LOAD',
|
||||
//Actualizar el estado de los movimientos
|
||||
if (!result) {
|
||||
throw new Error('No se pudo procesar el archivo.');
|
||||
}
|
||||
await this.movimientoService.updateStatus(
|
||||
result.id_movimiento,
|
||||
'SUCCESS',
|
||||
undefined,
|
||||
`inserted=${result.inserted}`
|
||||
);
|
||||
return result;
|
||||
return result
|
||||
|
||||
} catch (err) {
|
||||
await this.movimientoService.log(
|
||||
|
||||
@@ -189,4 +193,28 @@ export class ExcelController {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Agregarlo en su propio controller
|
||||
@Get('movimientos')
|
||||
async getMovimientos() {
|
||||
const movimientos = await this.movimientoService.findAll();
|
||||
return movimientos;
|
||||
}
|
||||
|
||||
@Post('activar-servicios/:id_movimiento')
|
||||
async activarServicios(
|
||||
@Param('id_movimiento', ParseIntPipe) id_movimiento: number,
|
||||
@Request() req,
|
||||
): Promise<{ message: string }> {
|
||||
const origen = req.user.origen;
|
||||
|
||||
if (!origen) {
|
||||
throw new Error('No se encontró origen en el JWT');
|
||||
}
|
||||
|
||||
await this.excelService.activarServicios(id_movimiento, origen);
|
||||
|
||||
return { message: 'Servicios activados correctamente' };
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user