sample mssql region api
This commit is contained in:
parent
59fc4c2399
commit
bf52f8a56b
@ -14,7 +14,7 @@ export const OracleConfig: any = {
|
|||||||
|
|
||||||
export const MssqlConfig: any = {
|
export const MssqlConfig: any = {
|
||||||
// type: 'mssql',
|
// type: 'mssql',
|
||||||
host: '172.31.18.76',
|
server: '172.31.18.76',
|
||||||
// port: 1433,
|
// port: 1433,
|
||||||
user: 'Carnetsys',
|
user: 'Carnetsys',
|
||||||
password: 'Carnet1234',
|
password: 'Carnet1234',
|
||||||
@ -24,6 +24,7 @@ export const OracleConfig: any = {
|
|||||||
options: {
|
options: {
|
||||||
enableArithAbort: true,
|
enableArithAbort: true,
|
||||||
trustServerCertificate: true,
|
trustServerCertificate: true,
|
||||||
|
encrypt:true
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { Controller, Get } from '@nestjs/common';
|
import { Body, Controller, Get, Post } from '@nestjs/common';
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import { MssqlService } from './mssql.service';
|
import { MssqlService } from './mssql.service';
|
||||||
|
import { InsertRegionsDto } from 'src/oracle/uscib-managed-sp/region/region.dto';
|
||||||
|
|
||||||
@Controller('mssql')
|
@Controller('mssql')
|
||||||
export class MssqlController {
|
export class MssqlController {
|
||||||
@ -12,4 +13,16 @@ export class MssqlController {
|
|||||||
checkConnection() {
|
checkConnection() {
|
||||||
return this.mssqlService.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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { Request } from 'mssql';
|
import { Connection, Request } from 'mssql';
|
||||||
import { MssqlDBService } from 'src/db/db.service';
|
import { MssqlDBService } from 'src/db/db.service';
|
||||||
|
import * as mssql from 'mssql';
|
||||||
|
import { InsertRegionsDto } from 'src/oracle/uscib-managed-sp/region/region.dto';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MssqlService {
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user