From 3cb3566a283ade888186e88aa7af40d9914ab5a6 Mon Sep 17 00:00:00 2001 From: ghost Date: Fri, 31 Jan 2025 12:53:02 -0500 Subject: [PATCH] =?UTF-8?q?feat:=20Genearaci=C3=B3n=20consecutivo=20y=20n?= =?UTF-8?q?=C3=BAmero=20de=20contrato?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../contrato-general.controller.ts | 77 +++++++++++++++ .../contrato-general.service.ts | 37 +++++++ src/shared/interfaces/conteo.interface.ts | 38 ++++++++ swagger/swagger.json | 96 ++++++++++++++++++- swagger/swagger.yaml | 64 ++++++++++++- 5 files changed, 310 insertions(+), 2 deletions(-) create mode 100644 src/shared/interfaces/conteo.interface.ts diff --git a/src/contrato-general/contrato-general.controller.ts b/src/contrato-general/contrato-general.controller.ts index e8a6606..4c42c51 100644 --- a/src/contrato-general/contrato-general.controller.ts +++ b/src/contrato-general/contrato-general.controller.ts @@ -26,6 +26,10 @@ import { } from '@nestjs/swagger'; import { StandardResponse } from '../utils/standardResponse.interface'; import { BaseQueryParamsDto } from '../shared/dto/query-params.base.dto'; +import { + ConteoConsecutivo, + ConteoNumeroContrato, +} from 'src/shared/interfaces/conteo.interface'; @ApiTags('contratos-generales') @Controller('contratos-generales') @@ -258,4 +262,77 @@ export class ContratoGeneralController { res.status(HttpStatus.NOT_FOUND).json(response); } } + + @Post('conteo-consecutivo') + @ApiOperation({ summary: 'Conteo de contratos por unidad ejecutora' }) + @ApiBody({ type: ConteoConsecutivo }) + @ApiResponse({ + status: HttpStatus.OK, + description: 'Conteo de los contratos', + }) + @ApiResponse({ + status: HttpStatus.INTERNAL_SERVER_ERROR, + description: 'Error al realizar el conteo de los contratos', + }) + async contarConsecutivo( + @Res() res: Response, + @Body() body: ConteoConsecutivo, + ): Promise { + try { + const conteo = await this.contratoGeneralService.contarConsecutivo(body); + const response: StandardResponse = { + Success: true, + Status: HttpStatus.OK, + Message: 'Conteo de los contratos', + Data: conteo, + }; + res.status(HttpStatus.CREATED).json(response); + } catch (error) { + const response: StandardResponse = { + Success: false, + Status: HttpStatus.INTERNAL_SERVER_ERROR, + Message: error.message, + Data: error, + }; + res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(response); + } + } + + @Post('conteo-numero-contrato') + @ApiOperation({ + summary: 'Conteo de contratos por unidad ejecutora, vigencia y estado', + }) + @ApiBody({ type: ConteoNumeroContrato }) + @ApiResponse({ + status: 200, + description: 'Conteo de los contratos', + }) + @ApiResponse({ + status: HttpStatus.INTERNAL_SERVER_ERROR, + description: 'Error al realizar el conteo de los contratos', + }) + async contarNumeroContrato( + @Res() res: Response, + @Body() body: ConteoNumeroContrato, + ): Promise { + try { + const conteo = + await this.contratoGeneralService.contarNumeroContrato(body); + const response: StandardResponse = { + Success: true, + Status: HttpStatus.OK, + Message: 'Conteo de los contratos', + Data: conteo, + }; + res.status(HttpStatus.CREATED).json(response); + } catch (error) { + const response: StandardResponse = { + Success: false, + Status: HttpStatus.INTERNAL_SERVER_ERROR, + Message: error.message, + Data: error, + }; + res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(response); + } + } } diff --git a/src/contrato-general/contrato-general.service.ts b/src/contrato-general/contrato-general.service.ts index f5d0006..871d739 100644 --- a/src/contrato-general/contrato-general.service.ts +++ b/src/contrato-general/contrato-general.service.ts @@ -114,4 +114,41 @@ export class ContratoGeneralService extends BaseCrudService { ); } } + + // Conteo de contratos por unidad ejecutora (obtener consecutivo del contrato) + async contarConsecutivo(body: any): Promise { + try { + const { unidad_ejecutora_id } = body; + return this.contratoGeneralRepository.count({ + where: { unidad_ejecutora_id }, + }); + } catch (error) { + throw new Error( + `Error al realizar el conteo de los contratos: ${error.message}`, + ); + } + } + + // Conteo de contratos por unidad ejecutora, vigencia y estado en SUSCRITO (obtener nĂºmero de contrato) + async contarNumeroContrato(body: any): Promise { + try { + const { unidad_ejecutora_id, vigencia, estado } = body; + const resultado = await this.contratoGeneralRepository + .createQueryBuilder('cg') + .innerJoin('estado_contrato', 'ec', 'ec.contrato_general_id = cg.id') + .where('cg.unidad_ejecutora_id = :unidad_ejecutora_id', { + unidad_ejecutora_id, + }) + .andWhere('cg.vigencia = :vigencia', { vigencia }) + .andWhere('ec.estado_parametro_id = :estado', { estado: estado }) + .select('COUNT(DISTINCT cg.id)', 'total') + .getRawOne(); + + return resultado ? parseInt(resultado?.total) : null; + } catch (error) { + throw new Error( + `Error al realizar el conteo de los contratos: ${error.message}`, + ); + } + } } diff --git a/src/shared/interfaces/conteo.interface.ts b/src/shared/interfaces/conteo.interface.ts new file mode 100644 index 0000000..36c86bb --- /dev/null +++ b/src/shared/interfaces/conteo.interface.ts @@ -0,0 +1,38 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { IsNotEmpty, IsNumber, IsOptional, IsString } from 'class-validator'; + +export class ConteoConsecutivo { + @ApiProperty({ + example: 1, + description: 'Id de unidad ejecutora', + }) + @IsNotEmpty() + @IsNumber() + unidad_ejecutora_id: number; +} + +export class ConteoNumeroContrato { + @ApiProperty({ + example: 1, + description: 'Id de unidad ejecutora', + }) + @IsNotEmpty() + @IsNumber() + unidad_ejecutora_id: number; + + @ApiProperty({ + example: '2024', + description: 'Vigencia', + }) + @IsNotEmpty() + @IsString() + vigencia: string; + + @ApiProperty({ + example: 1, + description: 'Id del estado', + }) + @IsNotEmpty() + @IsNumber() + estado: number; +} diff --git a/swagger/swagger.json b/swagger/swagger.json index 7337ecf..804dc69 100644 --- a/swagger/swagger.json +++ b/swagger/swagger.json @@ -313,7 +313,63 @@ ] } }, - "/documentos-contratos": { + "/contratos-generales/conteo-consecutivo": { + "post": { + "operationId": "ContratoGeneralController_contarConsecutivo", + "parameters": [], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ConteoConsecutivo" + } + } + } + }, + "responses": { + "200": { + "description": "Conteo de los contratos" + }, + "500": { + "description": "Error al realizar el conteo de los contratos" + } + }, + "summary": "Conteo de contratos por unidad ejecutora", + "tags": [ + "contratos-generales" + ] + } + }, + "/contratos-generales/conteo-numero-contrato": { + "post": { + "operationId": "ContratoGeneralController_contarNumeroContrato", + "parameters": [], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ConteoNumeroContrato" + } + } + } + }, + "responses": { + "200": { + "description": "Conteo de los contratos" + }, + "500": { + "description": "Error al realizar el conteo de los contratos" + } + }, + "summary": "Conteo de contratos por unidad ejecutora, vigencia y estado", + "tags": [ + "contratos-generales" + ] + } + }, + "/documentos-contrato": { "post": { "operationId": "DocumentoContratoController_create", "parameters": [], @@ -2522,6 +2578,44 @@ "type": "object", "properties": {} }, + "ConteoConsecutivo": { + "type": "object", + "properties": { + "unidad_ejecutora_id": { + "type": "number", + "example": 1, + "description": "Id de unidad ejecutora" + } + }, + "required": [ + "unidad_ejecutora_id" + ] + }, + "ConteoNumeroContrato": { + "type": "object", + "properties": { + "unidad_ejecutora_id": { + "type": "number", + "example": 1, + "description": "Id de unidad ejecutora" + }, + "vigencia": { + "type": "string", + "example": "2024", + "description": "Vigencia" + }, + "estado": { + "type": "number", + "example": 1, + "description": "Id del estado" + } + }, + "required": [ + "unidad_ejecutora_id", + "vigencia", + "estado" + ] + }, "CreateDocumentoContratoDto": { "type": "object", "properties": { diff --git a/swagger/swagger.yaml b/swagger/swagger.yaml index 7dfa1f5..91db758 100644 --- a/swagger/swagger.yaml +++ b/swagger/swagger.yaml @@ -207,7 +207,41 @@ paths: description: Contrato general no encontrado summary: Eliminar un contrato general tags: *ref_0 - /documentos-contratos: + /contratos-generales/conteo-consecutivo: + post: + operationId: ContratoGeneralController_contarConsecutivo + parameters: [] + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/ConteoConsecutivo' + responses: + '200': + description: Conteo de los contratos + '500': + description: Error al realizar el conteo de los contratos + summary: Conteo de contratos por unidad ejecutora + tags: *ref_0 + /contratos-generales/conteo-numero-contrato: + post: + operationId: ContratoGeneralController_contarNumeroContrato + parameters: [] + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/ConteoNumeroContrato' + responses: + '200': + description: Conteo de los contratos + '500': + description: Error al realizar el conteo de los contratos + summary: Conteo de contratos por unidad ejecutora, vigencia y estado + tags: *ref_0 + /documentos-contrato: post: operationId: DocumentoContratoController_create parameters: [] @@ -1598,6 +1632,34 @@ components: ActualizarContratoGeneralDto: type: object properties: {} + ConteoConsecutivo: + type: object + properties: + unidad_ejecutora_id: + type: number + example: 1 + description: Id de unidad ejecutora + required: + - unidad_ejecutora_id + ConteoNumeroContrato: + type: object + properties: + unidad_ejecutora_id: + type: number + example: 1 + description: Id de unidad ejecutora + vigencia: + type: string + example: '2024' + description: Vigencia + estado: + type: number + example: 1 + description: Id del estado + required: + - unidad_ejecutora_id + - vigencia + - estado CreateDocumentoContratoDto: type: object properties: