mssql batch1 API done
This commit is contained in:
parent
cf42aa87c6
commit
32258090f5
@ -0,0 +1,16 @@
|
||||
import { Controller, Get, Query } from '@nestjs/common';
|
||||
import { CarnetSequenceService } from './carnet-sequence.service';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { GetCarnetSequenceDTO } from 'src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.dto';
|
||||
|
||||
@Controller('mssql')
|
||||
export class CarnetSequenceController {
|
||||
|
||||
constructor(private readonly carnetSequenceService: CarnetSequenceService) { }
|
||||
|
||||
@ApiTags('Carnet Sequence - Mssql')
|
||||
@Get('/GetCarnetSequence')
|
||||
getCarnetSequence(@Query() body: GetCarnetSequenceDTO) {
|
||||
return this.carnetSequenceService.getCarnetSequence(body);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { CarnetSequenceController } from './carnet-sequence.controller';
|
||||
import { CarnetSequenceService } from './carnet-sequence.service';
|
||||
|
||||
@Module({
|
||||
controllers: [CarnetSequenceController],
|
||||
providers: [CarnetSequenceService]
|
||||
})
|
||||
export class CarnetSequenceModule {}
|
||||
@ -0,0 +1,30 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Connection, Request } from 'mssql';
|
||||
import { MssqlDBService } from 'src/db/db.service';
|
||||
import * as mssql from 'mssql'
|
||||
import { GetCarnetSequenceDTO } from 'src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.dto';
|
||||
|
||||
@Injectable()
|
||||
export class CarnetSequenceService {
|
||||
|
||||
constructor(private readonly mssqlDBService: MssqlDBService) { }
|
||||
|
||||
async getCarnetSequence(body:GetCarnetSequenceDTO) {
|
||||
|
||||
let connection: Connection;
|
||||
try {
|
||||
connection = await this.mssqlDBService.getConnection();
|
||||
const request = new Request(connection);
|
||||
request.input('P_SPID', mssql.Int, body.p_spid);
|
||||
const result = await request.execute('carnetsys.GETCARNETSEQUENCE');
|
||||
return { data: result.recordsets };
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error executing stored procedure:', error);
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
import { Body, Controller, Get, Post, Query } from '@nestjs/common';
|
||||
import { SpContactsService } from './sp-contacts.service';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { getSPAllContactsDTO, getSPDefaultcontactDTO, inactivateSPContactDTO } from 'src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.dto';
|
||||
|
||||
@Controller('mssql')
|
||||
export class SpContactsController {
|
||||
|
||||
constructor(private readonly spContactsService: SpContactsService) { }
|
||||
|
||||
|
||||
@ApiTags('SPContacts - Mssql')
|
||||
@Post('/InactivateSPContact')
|
||||
inactivateSPContact(@Query() body: inactivateSPContactDTO) {
|
||||
return this.spContactsService.inactivateSPContact(body);
|
||||
}
|
||||
|
||||
@ApiTags('SPContacts - Mssql')
|
||||
@Get('/GetSPDefaultContact')
|
||||
getSPDefaultcontact(@Query() body: getSPDefaultcontactDTO) {
|
||||
return this.spContactsService.getSPDefaultcontacts(body);
|
||||
}
|
||||
|
||||
@ApiTags('SPContacts - Mssql')
|
||||
@Get('/GetSPAllContacts')
|
||||
getSPAllContacts(@Query() body: getSPAllContactsDTO) {
|
||||
return this.spContactsService.getSpAllContacts(body);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { SpContactsController } from './sp-contacts.controller';
|
||||
import { SpContactsService } from './sp-contacts.service';
|
||||
|
||||
@Module({
|
||||
controllers: [SpContactsController],
|
||||
providers: [SpContactsService]
|
||||
})
|
||||
export class SpContactsModule {}
|
||||
@ -0,0 +1,68 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { MssqlDBService } from 'src/db/db.service';
|
||||
import * as mssql from 'mssql'
|
||||
import { Connection , Request} from 'mssql';
|
||||
import { getSPAllContactsDTO, getSPDefaultcontactDTO, inactivateSPContactDTO } from 'src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.dto';
|
||||
|
||||
@Injectable()
|
||||
export class SpContactsService {
|
||||
|
||||
constructor(private readonly mssqlDBService: MssqlDBService) { }
|
||||
|
||||
async getSpAllContacts(body:getSPAllContactsDTO) {
|
||||
|
||||
let connection: Connection;
|
||||
try {
|
||||
connection = await this.mssqlDBService.getConnection();
|
||||
const request = new Request(connection);
|
||||
request.input('P_SPID', mssql.Int, body.p_SPid);
|
||||
const result = await request.execute('carnetsys.GETSPALLCONTACTS');
|
||||
return { data: result.recordsets };
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error executing stored procedure:', error);
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async getSPDefaultcontacts(body:getSPDefaultcontactDTO) {
|
||||
|
||||
let connection: Connection;
|
||||
try {
|
||||
connection = await this.mssqlDBService.getConnection();
|
||||
const request = new Request(connection);
|
||||
request.input('P_SPID', mssql.Int, body.p_SPid);
|
||||
const result = await request.execute('carnetsys.GETSPDEFAULTCONTACTS');
|
||||
return { data: result.recordsets };
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error executing stored procedure:', error);
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async inactivateSPContact(body:inactivateSPContactDTO) {
|
||||
|
||||
let connection: Connection;
|
||||
try {
|
||||
connection = await this.mssqlDBService.getConnection();
|
||||
const request = new Request(connection);
|
||||
request.input('P_SPCONTACTID', mssql.Int, body.p_spcontactid);
|
||||
const result = await request.execute('carnetsys.INACTIVATESPCONTACTS');
|
||||
return { data: result.recordsets };
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error executing stored procedure:', error);
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Connection, Request } from 'mssql';
|
||||
import { MssqlDBService } from 'src/db/db.service';
|
||||
import { getSelectedServiceproviderDTO } from 'src/oracle/uscib-managed-sp/sp/sp.dto';
|
||||
import * as mssql from 'mssql'
|
||||
|
||||
@Injectable()
|
||||
export class SpService {
|
||||
@ -24,4 +26,23 @@ export class SpService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async getSpBySpid(body:getSelectedServiceproviderDTO) {
|
||||
|
||||
let connection: Connection;
|
||||
try {
|
||||
connection = await this.mssqlDBService.getConnection();
|
||||
const request = new Request(connection);
|
||||
request.input('P_SPID', mssql.Int, body.p_spid);
|
||||
const result = await request.execute('carnetsys.GETSPBYSPID');
|
||||
return { data: result.recordsets };
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error executing stored procedure:', error);
|
||||
} finally {
|
||||
if (connection) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { RegionModule } from './region/region.module';
|
||||
import { SpModule } from './sp/sp.module';
|
||||
import { CarnetSequenceModule } from './carnet-sequence/carnet-sequence.module';
|
||||
import { SpContactsModule } from './sp-contacts/sp-contacts.module';
|
||||
|
||||
@Module({
|
||||
imports: [RegionModule, SpModule]
|
||||
imports: [RegionModule, SpModule, CarnetSequenceModule, SpContactsModule]
|
||||
})
|
||||
export class UscibManagedSpModule {}
|
||||
|
||||
@ -21,7 +21,7 @@ export class SpContactsController {
|
||||
}
|
||||
|
||||
@ApiTags('SPContacts - Oracle')
|
||||
@Post('/SetSPDefaultcontact')
|
||||
@Post('/SetSPDefaultContact')
|
||||
setSPDefaultcontact(@Query() body: setSPDefaultcontactDTO) {
|
||||
return this.spContactsService.setSPDefaultcontact(body);
|
||||
}
|
||||
@ -39,7 +39,7 @@ export class SpContactsController {
|
||||
}
|
||||
|
||||
@ApiTags('SPContacts - Oracle')
|
||||
@Get('/GetSPDefaultcontact')
|
||||
@Get('/GetSPDefaultContact')
|
||||
getSPDefaultcontact(@Query() body: getSPDefaultcontactDTO) {
|
||||
return this.spContactsService.getSPDefaultcontacts(body);
|
||||
}
|
||||
@ -47,6 +47,6 @@ export class SpContactsController {
|
||||
@ApiTags('SPContacts - Oracle')
|
||||
@Get('/GetSPAllContacts')
|
||||
getSPAllContacts(@Query() body: getSPAllContactsDTO) {
|
||||
return this.spContactsService.getSPDefaultcontacts(body);
|
||||
return this.spContactsService.getSPAllContacts(body);
|
||||
}
|
||||
}
|
||||
|
||||
@ -311,54 +311,6 @@ export class SpContactsService {
|
||||
}
|
||||
}
|
||||
|
||||
async getSPcontacts() {
|
||||
let connection;
|
||||
let rows = [];
|
||||
try {
|
||||
connection = await this.oracleDBService.getConnection();
|
||||
if (!connection) {
|
||||
throw new Error('No DB Connected');
|
||||
}
|
||||
|
||||
const result = await connection.execute(
|
||||
`BEGIN
|
||||
USCIB_Managed_Pkg.GetSPAllContacts(:p_cursor);
|
||||
END;`,
|
||||
{
|
||||
p_cursor: {
|
||||
type: oracledb.CURSOR,
|
||||
dir: oracledb.BIND_OUT,
|
||||
},
|
||||
},
|
||||
{
|
||||
outFormat: oracledb.OUT_FORMAT_OBJECT,
|
||||
},
|
||||
);
|
||||
|
||||
if (result.outBinds && result.outBinds.p_cursor) {
|
||||
const cursor = result.outBinds.p_cursor;
|
||||
let rowsBatch;
|
||||
|
||||
do {
|
||||
rowsBatch = await cursor.getRows(100);
|
||||
rows = rows.concat(rowsBatch);
|
||||
} while (rowsBatch.length > 0);
|
||||
|
||||
await cursor.close();
|
||||
} else {
|
||||
throw new Error('No cursor returned from the stored procedure');
|
||||
}
|
||||
|
||||
return rows;
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
return { error: err.message };
|
||||
} else {
|
||||
return { error: 'An unknown error occurred' };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async getSPAllContacts(body: getSPAllContactsDTO) {
|
||||
|
||||
let connection;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user