added param table API

This commit is contained in:
Kallesh B S 2025-03-01 11:18:38 +05:30
parent b0a9487b07
commit e1924ed85c
5 changed files with 621 additions and 26 deletions

View File

@ -98,6 +98,7 @@ Content-Type: application/json
{
"p_spid": 12345,
"p_defcontactflag":"N",
"p_firstname": "John",
"p_lastname": "Doe",
"p_title": "Mr.",
@ -150,7 +151,7 @@ GET http://localhost:3000/oracle/GetSPDefaultcontact/12
//GetAllSPcontacts
GET http://localhost:3000/oracle/GetAllSPcontacts
//GET http://localhost:3000/oracle/GetAllSPcontacts
###
@ -175,6 +176,63 @@ GET http://localhost:3000/oracle/GetCarnetSequence/12
###
//GetParamValues
GET http://localhost:3000/oracle/GetParamValues?id=1&type=original
###
//CreateParamRecord
POST http://localhost:3000/oracle/CreateParamRecord
Content-Type: application/json
{
# "P_SPID": 123,
"P_PARAMTYPE": "TypeA",
"P_PARAMDESC": "Description of the parameter",
"P_PARAMVALUE": "Value of the parameter",
# "P_ADDLPARAMVALUE1": "Additional Value 1",
# "P_ADDLPARAMVALUE2": "Additional Value 2",
# "P_ADDLPARAMVALUE3": null,
# "P_ADDLPARAMVALUE4": "Additional Value 4",
# "P_ADDLPARAMVALUE5": null,
"P_SORTSEQ": 1,
"P_USERID": "user123"
}
###
// UpdateParamRecord
PATCH http://localhost:3000/oracle/UpdateParamRecord
Content-Type: application/json
{
"P_SPID": 123,
"P_PARAMID": 456,
"P_PARAMDESC": "Description of the parameter",
"P_ADDLPARAMVALUE1": "Additional Value 1",
"P_ADDLPARAMVALUE2": "Additional Value 2",
"P_ADDLPARAMVALUE3": null,
"P_ADDLPARAMVALUE4": "Additional Value 4",
"P_ADDLPARAMVALUE5": null,
"P_SORTSEQ": 1,
"P_USERID": "user123"
}
###
// InActivateParamRecord
PATCH http://localhost:3000/oracle/InActivateParamRecord?pid=1&uid=2
###
// ReActivateParamRecord
PATCH http://localhost:3000/oracle/ReActivateParamRecord?pid=1&uid=2
###

View File

@ -1,10 +1,13 @@
import { Body, Controller, Get, Param, ParseIntPipe, Patch, Post, Put } from '@nestjs/common';
import { Body, Controller, Get, Param, ParseIntPipe, Patch, Post, Put, Query, UsePipes } from '@nestjs/common';
import { OracleService } from './oracle.service';
import { CreateCarnetSequenceDTO, InsertNewServiceProviderDTO, InsertRegionsDto, InsertSPContactsDTO, UpdateRegionDto, UpdateServiceProviderDTO, UpdateSPContactsDTO } from './oracle.dto';
import { CreateCarnetSequenceDTO, CreateParamRecordDTO, CreateTableRecordDTO, InsertNewServiceProviderDTO, InsertRegionsDto, InsertSPContactsDTO, UpdateParamRecordDTO, UpdateRegionDto, UpdateServiceProviderDTO, UpdateSPContactsDTO } from './oracle.dto';
import { ParamTableService } from './paramTable.service';
@Controller('oracle')
export class OracleController {
constructor(private readonly oarcleService: OracleService) { }
constructor(
private readonly oarcleService: OracleService,
private readonly paramTableService: ParamTableService) { }
// Regions
@ -66,7 +69,7 @@ export class OracleController {
)
}
@Get('GetAllServiceproviders')
@Get('/GetAllServiceproviders')
getAllServiceproviders() {
return this.oarcleService.getAllServiceproviders();
}
@ -125,10 +128,10 @@ export class OracleController {
return this.oarcleService.getSPDefaultcontacts(id)
}
@Get('/GetAllSPcontacts')
getSPcontacts() {
return this.oarcleService.getSPcontacts();
}
// @Get('/GetAllSPcontacts')
// getSPcontacts() {
// return this.oarcleService.getSPcontacts();
// }
// Carnet Sequence
@ -147,4 +150,52 @@ export class OracleController {
getCarnetSequence(@Param('id', ParseIntPipe) id: number) {
return this.oarcleService.getCarnetSequence(id)
}
// param table
@Get('/GetParamValues')
@UsePipes()
getParamValues(
@Query('id') id: string,
@Query('type') type: string
) {
return this.paramTableService.GETPARAMVALUES(id ? Number(id) : undefined, type);
}
@Post('/CreateTableRecord')
createTableRecord(@Body() body: CreateTableRecordDTO) {
return this.paramTableService.CREATETABLERECORD(body.P_USERID, body.P_TABLEFULLDESC)
}
@Post('/CreateParamRecord')
createParamRecord(@Body() body: CreateParamRecordDTO) {
return this.paramTableService.CREATEPARAMRECORD(
body.P_PARAMTYPE,
body.P_PARAMDESC,
body.P_PARAMVALUE,
body.P_SORTSEQ,
body.P_USERID,
body.P_SPID,
body.P_ADDLPARAMVALUE1,
body.P_ADDLPARAMVALUE2,
body.P_ADDLPARAMVALUE3,
body.P_ADDLPARAMVALUE4,
body.P_ADDLPARAMVALUE5,
)
}
@Patch('/UpdateParamRecord')
UpdateParamRecord(@Body() body: UpdateParamRecordDTO) {
return this.paramTableService.UPDATEPARAMRECORD(body)
}
@Patch('/InActivateParamRecord')
inActivateParamRecord(@Query('pid') pid,@Query('uid') uid) {
return this.paramTableService.INACTIVATEPARAMRECORD(pid?Number(pid):pid,uid)
}
@Patch('/ReActivateParamRecord')
reActivateParamRecord(@Query('pid') pid,@Query('uid') uid) {
return this.paramTableService.REACTIVATEPARAMRECORD(pid?Number(pid):pid,uid)
}
}

View File

@ -1,4 +1,4 @@
import { IsEmail, IsNumber, IsString } from 'class-validator';
import { IsEmail, IsNumber, IsOptional, IsString } from 'class-validator';
export class InsertRegionsDto {
@IsString()
@ -190,3 +190,92 @@ export class CreateCarnetSequenceDTO {
@IsString()
p_carnettype: string
}
export class CreateTableRecordDTO {
@IsString()
P_USERID: string;
@IsString()
P_TABLEFULLDESC: string
}
export class CreateParamRecordDTO {
@IsOptional()
@IsNumber()
P_SPID?: number;
@IsString()
P_PARAMTYPE: string;
@IsString()
P_PARAMDESC: string;
@IsString()
P_PARAMVALUE: string;
@IsOptional()
@IsString()
P_ADDLPARAMVALUE1?: string;
@IsOptional()
@IsString()
P_ADDLPARAMVALUE2?: string;
@IsOptional()
@IsString()
P_ADDLPARAMVALUE3?: string;
@IsOptional()
@IsString()
P_ADDLPARAMVALUE4?: string;
@IsOptional()
@IsString()
P_ADDLPARAMVALUE5?: string;
@IsNumber()
P_SORTSEQ: number;
@IsString()
P_USERID: string;
}
export class UpdateParamRecordDTO {
@IsOptional()
@IsNumber()
P_SPID?: number;
@IsNumber()
P_PARAMID: number;
@IsString()
P_PARAMDESC: string;
@IsOptional()
@IsString()
P_ADDLPARAMVALUE1?: string;
@IsOptional()
@IsString()
P_ADDLPARAMVALUE2?: string;
@IsOptional()
@IsString()
P_ADDLPARAMVALUE3?: string;
@IsOptional()
@IsString()
P_ADDLPARAMVALUE4?: string;
@IsOptional()
@IsString()
P_ADDLPARAMVALUE5?: string;
@IsNumber()
P_SORTSEQ: number;
@IsString()
P_USERID: string;
}

View File

@ -1,13 +1,13 @@
import { Module } from '@nestjs/common';
import { OracleService } from './oracle.service';
import { OracleController } from './oracle.controller';
import { OracleDBService } from 'src/db/db.service';
import { DbModule } from 'src/db/db.module';
import { ParamTableService } from './paramTable.service';
@Module({
imports:[DbModule],
providers: [OracleService],
providers: [OracleService,ParamTableService],
controllers: [OracleController],
exports:[OracleService]
exports:[OracleService,ParamTableService]
})
export class OracleModule {}

View File

@ -0,0 +1,397 @@
import { Injectable } from '@nestjs/common';
import { OracleDBService } from 'src/db/db.service';
import * as oracledb from 'oracledb'
import { UpdateParamRecordDTO } from './oracle.dto';
@Injectable()
export class ParamTableService {
constructor(private readonly oracleDBService: OracleDBService) { }
async GETPARAMVALUES(P_SPID?: number | null, P_PARAMTYPE?: string | null) {
P_SPID = P_SPID ? P_SPID : null;
P_PARAMTYPE = P_PARAMTYPE ? P_PARAMTYPE : null;
let connection;
let rows = [];
try {
connection = await this.oracleDBService.getConnection()
if (!connection) {
throw new Error('No DB Connected')
}
const result = await connection.execute(
`BEGIN
MANAGEPARAMTABLE_PKG.GETPARAMVALUES(:P_SPID,:P_PARAMTYPE,:p_cursor);
END;`,
{
P_SPID: {
val: P_SPID,
type: oracledb.DB_TYPE_NVARCHAR
},
P_PARAMTYPE: {
val: P_PARAMTYPE,
type: oracledb.DB_TYPE_NVARCHAR
},
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; // The OUT cursor
let rowsBatch;
do {
rowsBatch = await cursor.getRows(100); // Fetch 100 rows at a time
rows = rows.concat(rowsBatch); // Append fetched rows to the main array
} while (rowsBatch.length > 0);
console.log('Rows fetched:', rows);
// Close the cursor after you're done
await cursor.close();
} else {
throw new Error('No cursor returned from the stored procedure');
}
return rows;
} catch (err) {
console.error('Error fetching users: ', err);
throw new Error('Error fetching users');
} finally { }
}
async CREATETABLERECORD(P_USERID: string, P_TABLEFULLDESC: string) {
let connection;
try {
// Connect to the Oracle database using oracledb
connection = await this.oracleDBService.getConnection()
if (!connection) {
throw new Error('No DB Connected')
}
const result = await connection.execute(
`BEGIN
MANAGEPARAMTABLE_PKG.CREATETABLERECORD(:P_USERID,:P_TABLEFULLDESC,:p_cursor);
END;`,
{
P_TABLEFULLDESC: {
val: P_TABLEFULLDESC,
type: oracledb.DB_TYPE_VARCHAR
},
P_USERID: {
val: P_USERID,
type: oracledb.DB_TYPE_VARCHAR
},
p_cursor: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
}
}, {
outFormat: oracledb.OUT_FORMAT_OBJECT
}
);
await connection.commit();
let fres = await result.outBinds.p_cursor.getRows();
return fres
} catch (err) {
console.error('Error fetching users: ', err);
throw new Error('Error fetching users');
} finally { }
}
async CREATEPARAMRECORD(
P_PARAMTYPE: string,
P_PARAMDESC: string,
P_PARAMVALUE: string,
P_SORTSEQ: number,
P_USERID: string,
P_SPID?: number,
P_ADDLPARAMVALUE1?: string,
P_ADDLPARAMVALUE2?: string,
P_ADDLPARAMVALUE3?: string,
P_ADDLPARAMVALUE4?: string,
P_ADDLPARAMVALUE5?: string,
) {
let connection;
try {
// Connect to the Oracle database using oracledb
connection = await this.oracleDBService.getConnection()
if (!connection) {
throw new Error('No DB Connected')
}
const result = await connection.execute(
`BEGIN
MANAGEPARAMTABLE_PKG.CREATEPARAMRECORD(
:P_SPID,
:P_PARAMTYPE,
:P_PARAMDESC,
:P_PARAMVALUE,
:P_ADDLPARAMVALUE1,
:P_ADDLPARAMVALUE2,
:P_ADDLPARAMVALUE3,
:P_ADDLPARAMVALUE4,
:P_ADDLPARAMVALUE5,
:P_SORTSEQ,
:P_USERID,
:p_cursor);
END;`,
{
P_SPID: {
val: P_SPID,
type: oracledb.DB_TYPE_NUMBER
},
P_PARAMTYPE: {
val: P_PARAMTYPE,
type: oracledb.DB_TYPE_VARCHAR
},
P_PARAMDESC: {
val: P_PARAMDESC,
type: oracledb.DB_TYPE_VARCHAR
},
P_PARAMVALUE: {
val: P_PARAMVALUE,
type: oracledb.DB_TYPE_VARCHAR
},
P_ADDLPARAMVALUE1: {
val: P_ADDLPARAMVALUE1,
type: oracledb.DB_TYPE_VARCHAR
},
P_ADDLPARAMVALUE2: {
val: P_ADDLPARAMVALUE2,
type: oracledb.DB_TYPE_VARCHAR
},
P_ADDLPARAMVALUE3: {
val: P_ADDLPARAMVALUE3,
type: oracledb.DB_TYPE_VARCHAR
},
P_ADDLPARAMVALUE4: {
val: P_ADDLPARAMVALUE4,
type: oracledb.DB_TYPE_VARCHAR
},
P_ADDLPARAMVALUE5: {
val: P_ADDLPARAMVALUE5,
type: oracledb.DB_TYPE_VARCHAR
},
P_SORTSEQ: {
val: P_SORTSEQ,
type: oracledb.DB_TYPE_NUMBER
},
P_USERID: {
val: P_USERID,
type: oracledb.DB_TYPE_VARCHAR
},
p_cursor: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
}
}, {
outFormat: oracledb.OUT_FORMAT_OBJECT
}
);
await connection.commit();
let fres = await result.outBinds.p_cursor.getRows();
return fres
} catch (err) {
console.error('Error fetching users: ', err);
throw new Error('Error fetching users');
} finally { }
}
async UPDATEPARAMRECORD(body: UpdateParamRecordDTO) {
let connection;
try {
// Connect to the Oracle database using oracledb
connection = await this.oracleDBService.getConnection()
if (!connection) {
throw new Error('No DB Connected')
}
const result = await connection.execute(
`BEGIN
MANAGEPARAMTABLE_PKG.UPDATEPARAMRECORD(
:P_SPID,
:P_PARAMID,
:P_PARAMDESC,
:P_ADDLPARAMVALUE1,
:P_ADDLPARAMVALUE2,
:P_ADDLPARAMVALUE3,
:P_ADDLPARAMVALUE4,
:P_ADDLPARAMVALUE5,
:P_SORTSEQ,
:P_USERID,
:p_cursor);
END;`,
{
P_SPID: {
val: body.P_SPID,
type: oracledb.DB_TYPE_NUMBER
},
P_PARAMID: {
val: body.P_PARAMID,
type: oracledb.DB_TYPE_VARCHAR
},
P_PARAMDESC: {
val: body.P_PARAMDESC,
type: oracledb.DB_TYPE_VARCHAR
},
P_ADDLPARAMVALUE1: {
val: body.P_ADDLPARAMVALUE1,
type: oracledb.DB_TYPE_VARCHAR
},
P_ADDLPARAMVALUE2: {
val: body.P_ADDLPARAMVALUE2,
type: oracledb.DB_TYPE_VARCHAR
},
P_ADDLPARAMVALUE3: {
val: body.P_ADDLPARAMVALUE3,
type: oracledb.DB_TYPE_VARCHAR
},
P_ADDLPARAMVALUE4: {
val: body.P_ADDLPARAMVALUE4,
type: oracledb.DB_TYPE_VARCHAR
},
P_ADDLPARAMVALUE5: {
val: body.P_ADDLPARAMVALUE5,
type: oracledb.DB_TYPE_VARCHAR
},
P_SORTSEQ: {
val: body.P_SORTSEQ,
type: oracledb.DB_TYPE_NUMBER
},
P_USERID: {
val: body.P_USERID,
type: oracledb.DB_TYPE_VARCHAR
},
p_cursor: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
}
}, {
outFormat: oracledb.OUT_FORMAT_OBJECT
}
);
await connection.commit();
let fres = await result.outBinds.p_cursor.getRows();
return fres
} catch (err) {
console.error('Error fetching users: ', err);
throw new Error('Error fetching users');
} finally { }
}
async INACTIVATEPARAMRECORD(P_PARAMID: number, P_USERID: string) {
let connection;
try {
// Connect to the Oracle database using oracledb
connection = await this.oracleDBService.getConnection()
if (!connection) {
throw new Error('No DB Connected')
}
const result = await connection.execute(
`BEGIN
MANAGEPARAMTABLE_PKG.INACTIVATEPARAMRECORD(
:P_PARAMID,
:P_USERID,
:p_cursor);
END;`,
{
P_PARAMID: {
val: P_PARAMID,
type: oracledb.DB_TYPE_NUMBER
},
P_USERID: {
val: P_USERID,
type: oracledb.DB_TYPE_VARCHAR
},
p_cursor: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
}
}, {
outFormat: oracledb.OUT_FORMAT_OBJECT
}
);
await connection.commit();
let fres = await result.outBinds.p_cursor.getRows();
return fres
} catch (err) {
console.error('Error fetching users: ', err);
throw new Error('Error fetching users');
} finally { }
}
async REACTIVATEPARAMRECORD(P_PARAMID: number, P_USERID: string) {
let connection;
try {
// Connect to the Oracle database using oracledb
connection = await this.oracleDBService.getConnection()
if (!connection) {
throw new Error('No DB Connected')
}
const result = await connection.execute(
`BEGIN
MANAGEPARAMTABLE_PKG.REACTIVATEPARAMRECORD(
:P_PARAMID,
:P_USERID,
:p_cursor);
END;`,
{
P_PARAMID: {
val: P_PARAMID,
type: oracledb.DB_TYPE_NUMBER
},
P_USERID: {
val: P_USERID,
type: oracledb.DB_TYPE_VARCHAR
},
p_cursor: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
}
}, {
outFormat: oracledb.OUT_FORMAT_OBJECT
}
);
await connection.commit();
let fres = await result.outBinds.p_cursor.getRows();
return fres
} catch (err) {
console.error('Error fetching users: ', err);
throw new Error('Error fetching users');
} finally { }
}
}