diff --git a/ormconfig.ts b/ormconfig.ts index 4a72fad..397511c 100644 --- a/ormconfig.ts +++ b/ormconfig.ts @@ -14,7 +14,7 @@ export const OracleConfig: any = { export const MssqlConfig: any = { // type: 'mssql', - host: '172.31.18.76', + server: '172.31.18.76', // port: 1433, user: 'Carnetsys', password: 'Carnet1234', @@ -24,6 +24,7 @@ export const OracleConfig: any = { options: { enableArithAbort: true, trustServerCertificate: true, + encrypt:true }, }; diff --git a/src/mssql/mssql.controller.ts b/src/mssql/mssql.controller.ts index 173b3b9..8eaf785 100644 --- a/src/mssql/mssql.controller.ts +++ b/src/mssql/mssql.controller.ts @@ -1,15 +1,28 @@ -import { Controller, Get } from '@nestjs/common'; +import { Body, Controller, Get, Post } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { MssqlService } from './mssql.service'; +import { InsertRegionsDto } from 'src/oracle/uscib-managed-sp/region/region.dto'; @Controller('mssql') export class MssqlController { - constructor(private readonly mssqlService:MssqlService){} + constructor(private readonly mssqlService: MssqlService) { } @ApiTags('Connection - Mssql') @Get('/checkConnection') checkConnection() { return this.mssqlService.checkConnection(); } + + @ApiTags('Regions - Oracle') + @Get('/GetRegions') + getRegions() { + return this.mssqlService.getRegions(); + } + + @ApiTags('Regions - Oracle') + @Post('/InsertRegions') + insertRegions(@Body() body: InsertRegionsDto) { + return this.mssqlService.insetNewRegions(body); + } } diff --git a/src/mssql/mssql.service.ts b/src/mssql/mssql.service.ts index 7aeee64..5960b39 100644 --- a/src/mssql/mssql.service.ts +++ b/src/mssql/mssql.service.ts @@ -1,6 +1,8 @@ import { Injectable } from '@nestjs/common'; -import { Request } from 'mssql'; +import { Connection, Request } from 'mssql'; import { MssqlDBService } from 'src/db/db.service'; +import * as mssql from 'mssql'; +import { InsertRegionsDto } from 'src/oracle/uscib-managed-sp/region/region.dto'; @Injectable() export class MssqlService { @@ -31,4 +33,41 @@ export class MssqlService { } } } + + async getRegions() { + let connection: Connection; + try { + connection = await this.mssqlDBService.getConnection(); + const request = new Request(connection); + const result = await request.execute('carnetsys.GETREGIONS'); + return { data: result.recordsets }; + + } catch (error) { + console.error('Error executing stored procedure:', error); + } finally { + if (connection) { + connection.close(); + } + } + } + + async insetNewRegions(body:InsertRegionsDto) { + + let connection: Connection; + try { + connection = await this.mssqlDBService.getConnection(); + const request = new Request(connection); + request.input('P_REGION', mssql.VarChar(30), body.p_region); + request.input('P_NAME', mssql.VarChar(30), body.p_name); + const result = await request.execute('carnetsys.INSERTNEWREGION'); + return { data: result.recordsets }; + + } catch (error) { + console.error('Error executing stored procedure:', error); + } finally { + if (connection) { + connection.close(); + } + } + } }