added service to getSPAllContacts
This commit is contained in:
parent
4efa9794b0
commit
b9198acfe7
@ -11,6 +11,7 @@ import { SwaggerDocumentOptions } from '@nestjs/swagger';
|
|||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const app = await NestFactory.create(AppModule, {
|
const app = await NestFactory.create(AppModule, {
|
||||||
cors: {
|
cors: {
|
||||||
|
// origin: 'https://dev.alphaomegainfosys.com/',
|
||||||
origin: '*',
|
origin: '*',
|
||||||
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
|
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
|
||||||
preflightContinue: false,
|
preflightContinue: false,
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { SpContactsService } from './sp-contacts.service';
|
import { SpContactsService } from './sp-contacts.service';
|
||||||
import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common';
|
import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common';
|
||||||
import {
|
import {
|
||||||
|
getSPAllContactsDTO,
|
||||||
getSPDefaultcontactDTO,
|
getSPDefaultcontactDTO,
|
||||||
inactivateSPContactDTO,
|
inactivateSPContactDTO,
|
||||||
InsertSPContactsDTO,
|
InsertSPContactsDTO,
|
||||||
@ -43,8 +44,9 @@ export class SpContactsController {
|
|||||||
return this.spContactsService.getSPDefaultcontacts(body);
|
return this.spContactsService.getSPDefaultcontacts(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Get('/GetAllSPcontacts')
|
@ApiTags('SPContacts - Oracle')
|
||||||
// getSPcontacts() {
|
@Get('/GetSPAllContacts')
|
||||||
// return this.oarcleService.getSPcontacts();
|
getSPAllContacts(@Query() body: getSPAllContactsDTO) {
|
||||||
// }
|
return this.spContactsService.getSPDefaultcontacts(body);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -117,3 +117,5 @@ export class getSPDefaultcontactDTO {
|
|||||||
@IsDefined({ message: 'Property p_SPid is required' })
|
@IsDefined({ message: 'Property p_SPid is required' })
|
||||||
p_SPid: number;
|
p_SPid: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class getSPAllContactsDTO extends getSPDefaultcontactDTO{}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
|
|||||||
import { OracleDBService } from 'src/db/db.service';
|
import { OracleDBService } from 'src/db/db.service';
|
||||||
import * as oracledb from 'oracledb';
|
import * as oracledb from 'oracledb';
|
||||||
import {
|
import {
|
||||||
|
getSPAllContactsDTO,
|
||||||
getSPDefaultcontactDTO,
|
getSPDefaultcontactDTO,
|
||||||
inactivateSPContactDTO,
|
inactivateSPContactDTO,
|
||||||
InsertSPContactsDTO,
|
InsertSPContactsDTO,
|
||||||
@ -357,4 +358,57 @@ export class SpContactsService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getSPAllContacts(body: getSPAllContactsDTO) {
|
||||||
|
|
||||||
|
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_SPid,:p_cursor);
|
||||||
|
END;`,
|
||||||
|
{
|
||||||
|
p_SPid: {
|
||||||
|
val: body.p_SPid,
|
||||||
|
type: oracledb.DB_TYPE_NUMBER,
|
||||||
|
},
|
||||||
|
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' };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user