added api
This commit is contained in:
parent
bf52f8a56b
commit
cf42aa87c6
@ -1,28 +1,15 @@
|
|||||||
import { Body, Controller, Get, Post } from '@nestjs/common';
|
import { Controller, Get } 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 {
|
||||||
|
|
||||||
constructor(private readonly mssqlService: MssqlService) { }
|
constructor(private readonly mssqlService: MssqlService) { }
|
||||||
|
|
||||||
@ApiTags('Connection - Mssql')
|
// @ApiTags('Connection - Mssql')
|
||||||
@Get('/checkConnection')
|
// @Get('/checkConnection')
|
||||||
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,9 +1,11 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { MssqlController } from './mssql.controller';
|
import { MssqlController } from './mssql.controller';
|
||||||
import { MssqlService } from './mssql.service';
|
import { MssqlService } from './mssql.service';
|
||||||
|
import { UscibManagedSpModule } from './uscib-managed-sp/uscib-managed-sp.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
controllers: [MssqlController],
|
controllers: [MssqlController],
|
||||||
providers: [MssqlService]
|
providers: [MssqlService],
|
||||||
|
imports: [UscibManagedSpModule]
|
||||||
})
|
})
|
||||||
export class MssqlModule {}
|
export class MssqlModule {}
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { Connection, 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 {
|
||||||
@ -10,40 +8,17 @@ export class MssqlService {
|
|||||||
constructor(private readonly mssqlDBService: MssqlDBService) { }
|
constructor(private readonly mssqlDBService: MssqlDBService) { }
|
||||||
|
|
||||||
async checkConnection() {
|
async checkConnection() {
|
||||||
let connection;
|
let connection : Connection;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
connection = await this.mssqlDBService.getConnection();
|
connection = await this.mssqlDBService.getConnection();
|
||||||
|
|
||||||
// Create a new Request object
|
|
||||||
const request = new Request(connection);
|
const request = new Request(connection);
|
||||||
|
|
||||||
// Execute the query
|
|
||||||
const result = await request.query('SELECT GETDATE() AS CurrentDateTime');
|
const result = await request.query('SELECT GETDATE() AS CurrentDateTime');
|
||||||
|
|
||||||
console.log("Connection successful. Current date and time from the server:");
|
|
||||||
console.log(result.recordset[0].CurrentDateTime);
|
|
||||||
return { data: result.recordset[0].CurrentDateTime }
|
return { data: result.recordset[0].CurrentDateTime }
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error checking connection:', error);
|
console.error('Error checking connection:', error);
|
||||||
} finally {
|
return {error:error.message}
|
||||||
if (connection) {
|
|
||||||
connection.close(); // Ensure the connection is closed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
} finally {
|
||||||
if (connection) {
|
if (connection) {
|
||||||
connection.close();
|
connection.close();
|
||||||
@ -51,23 +26,4 @@ export class MssqlService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
22
src/mssql/uscib-managed-sp/region/region.controller.ts
Normal file
22
src/mssql/uscib-managed-sp/region/region.controller.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { Body, Controller, Get, Post } from '@nestjs/common';
|
||||||
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
|
import { RegionService } from './region.service';
|
||||||
|
import { InsertRegionsDto } from 'src/oracle/uscib-managed-sp/region/region.dto';
|
||||||
|
|
||||||
|
@Controller('mssql')
|
||||||
|
export class RegionController {
|
||||||
|
|
||||||
|
constructor(private readonly regionService:RegionService){}
|
||||||
|
|
||||||
|
@ApiTags('Regions - Mssql')
|
||||||
|
@Get('/GetRegions')
|
||||||
|
getRegions() {
|
||||||
|
return this.regionService.getRegions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiTags('Regions - Mssql')
|
||||||
|
@Post('/InsertRegions')
|
||||||
|
insertRegions(@Body() body: InsertRegionsDto) {
|
||||||
|
return this.regionService.insetNewRegions(body);
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/mssql/uscib-managed-sp/region/region.module.ts
Normal file
9
src/mssql/uscib-managed-sp/region/region.module.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { RegionController } from './region.controller';
|
||||||
|
import { RegionService } from './region.service';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
controllers: [RegionController],
|
||||||
|
providers: [RegionService]
|
||||||
|
})
|
||||||
|
export class RegionModule {}
|
||||||
49
src/mssql/uscib-managed-sp/region/region.service.ts
Normal file
49
src/mssql/uscib-managed-sp/region/region.service.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { Connection, Request } from 'mssql';
|
||||||
|
import { MssqlDBService } from 'src/db/db.service';
|
||||||
|
import { InsertRegionsDto } from 'src/oracle/uscib-managed-sp/region/region.dto';
|
||||||
|
import * as mssql from 'mssql';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class RegionService {
|
||||||
|
|
||||||
|
constructor(private readonly mssqlDBService: MssqlDBService) { }
|
||||||
|
|
||||||
|
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);
|
||||||
|
return {error:error.message}
|
||||||
|
} finally {
|
||||||
|
if (connection) {
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/mssql/uscib-managed-sp/sp/sp.controller.ts
Normal file
15
src/mssql/uscib-managed-sp/sp/sp.controller.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { Controller, Get } from '@nestjs/common';
|
||||||
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
|
import { SpService } from './sp.service';
|
||||||
|
|
||||||
|
@Controller('mssql')
|
||||||
|
export class SpController {
|
||||||
|
|
||||||
|
constructor(private readonly spService: SpService) {}
|
||||||
|
|
||||||
|
@ApiTags('SP - Mssql')
|
||||||
|
@Get('/GetAllServiceproviders')
|
||||||
|
getAllServiceproviders() {
|
||||||
|
return this.spService.getAllServiceproviders();
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/mssql/uscib-managed-sp/sp/sp.module.ts
Normal file
9
src/mssql/uscib-managed-sp/sp/sp.module.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { SpController } from './sp.controller';
|
||||||
|
import { SpService } from './sp.service';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
controllers: [SpController],
|
||||||
|
providers: [SpService]
|
||||||
|
})
|
||||||
|
export class SpModule {}
|
||||||
27
src/mssql/uscib-managed-sp/sp/sp.service.ts
Normal file
27
src/mssql/uscib-managed-sp/sp/sp.service.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { Connection, Request } from 'mssql';
|
||||||
|
import { MssqlDBService } from 'src/db/db.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class SpService {
|
||||||
|
|
||||||
|
constructor(private readonly mssqlDBService: MssqlDBService) { }
|
||||||
|
|
||||||
|
async getAllServiceproviders() {
|
||||||
|
|
||||||
|
let connection: Connection;
|
||||||
|
try {
|
||||||
|
connection = await this.mssqlDBService.getConnection();
|
||||||
|
const request = new Request(connection);
|
||||||
|
const result = await request.execute('carnetsys.GETALLSPS');
|
||||||
|
return { data: result.recordsets };
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error executing stored procedure:', error);
|
||||||
|
} finally {
|
||||||
|
if (connection) {
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
8
src/mssql/uscib-managed-sp/uscib-managed-sp.module.ts
Normal file
8
src/mssql/uscib-managed-sp/uscib-managed-sp.module.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { RegionModule } from './region/region.module';
|
||||||
|
import { SpModule } from './sp/sp.module';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [RegionModule, SpModule]
|
||||||
|
})
|
||||||
|
export class UscibManagedSpModule {}
|
||||||
Loading…
x
Reference in New Issue
Block a user