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 = {
|
||||
// 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
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user