diff --git a/api.http b/api.http index 62dcf38..9a1ac5e 100644 --- a/api.http +++ b/api.http @@ -98,6 +98,7 @@ Content-Type: application/json { "p_spid": 12345, + "p_defcontactflag":"N", "p_firstname": "John", "p_lastname": "Doe", "p_title": "Mr.", @@ -107,7 +108,7 @@ Content-Type: application/json "p_emailaddress": "john.doe@example.com", "p_user_id": "jdoe" } - + ### //SetSPDefaultcontact @@ -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 +### diff --git a/src/oracle/oracle.controller.ts b/src/oracle/oracle.controller.ts index ffe50a5..dfc3d35 100644 --- a/src/oracle/oracle.controller.ts +++ b/src/oracle/oracle.controller.ts @@ -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,21 +69,21 @@ export class OracleController { ) } - @Get('GetAllServiceproviders') + @Get('/GetAllServiceproviders') getAllServiceproviders() { return this.oarcleService.getAllServiceproviders(); } @Get('/GetSelectedServiceprovider/:id') - getSelectedServiceprovider(@Param('id', ParseIntPipe) id:number) { + getSelectedServiceprovider(@Param('id', ParseIntPipe) id: number) { return this.oarcleService.getServiceproviderByID(id); } - + // SPContacts - + @Post('/InsertSPContacts') - insertSPContacts(@Body() body: InsertSPContactsDTO){ + insertSPContacts(@Body() body: InsertSPContactsDTO) { return this.oarcleService.insertSPContacts( body.p_spid, body.p_defcontactflag, @@ -96,12 +99,12 @@ export class OracleController { } @Post('/SetSPDefaultcontact/:id') - setSPDefaultcontact(@Param('id', ParseIntPipe) id:number){ + setSPDefaultcontact(@Param('id', ParseIntPipe) id: number) { return this.oarcleService.setSPDefaultcontact(id) } - + @Put('/UpdateSPContacts') - updateSPContacts(@Body() body: UpdateSPContactsDTO){ + updateSPContacts(@Body() body: UpdateSPContactsDTO) { return this.oarcleService.updateSPContacts( body.p_spcontactid, body.p_firstname, @@ -116,35 +119,83 @@ export class OracleController { } @Post('/InactivateSPContact/:id') - inactivateSPContact(@Param('id', ParseIntPipe) id:number){ + inactivateSPContact(@Param('id', ParseIntPipe) id: number) { return this.oarcleService.inactivateSPContact(id) } @Get('/GetSPDefaultcontact/:id') - getSPDefaultcontact(@Param('id', ParseIntPipe) id:number){ + getSPDefaultcontact(@Param('id', ParseIntPipe) id: number) { return this.oarcleService.getSPDefaultcontacts(id) } - @Get('/GetAllSPcontacts') - getSPcontacts() { - return this.oarcleService.getSPcontacts(); - } + // @Get('/GetAllSPcontacts') + // getSPcontacts() { + // return this.oarcleService.getSPcontacts(); + // } // Carnet Sequence @Post('/CreateCarnetSequence/') - createCarnetSequence(@Body() body:CreateCarnetSequenceDTO){ + createCarnetSequence(@Body() body: CreateCarnetSequenceDTO) { return this.oarcleService.createCarnetSequence( body.p_spid, body.p_regionid, body.p_startnumber, body.p_endnumber, body.p_carnettype - ) + ) } @Get('/GetCarnetSequence/:id') - getCarnetSequence(@Param('id', ParseIntPipe) id:number){ + 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) + } } diff --git a/src/oracle/oracle.dto.ts b/src/oracle/oracle.dto.ts index 0405f72..80f3b5e 100644 --- a/src/oracle/oracle.dto.ts +++ b/src/oracle/oracle.dto.ts @@ -1,4 +1,4 @@ -import { IsEmail, IsNumber, IsString } from 'class-validator'; +import { IsEmail, IsNumber, IsOptional, IsString } from 'class-validator'; export class InsertRegionsDto { @IsString() @@ -189,4 +189,93 @@ export class CreateCarnetSequenceDTO { p_endnumber: number; @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; } \ No newline at end of file diff --git a/src/oracle/oracle.module.ts b/src/oracle/oracle.module.ts index 720cff1..5fdb030 100644 --- a/src/oracle/oracle.module.ts +++ b/src/oracle/oracle.module.ts @@ -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 {} diff --git a/src/oracle/paramTable.service.ts b/src/oracle/paramTable.service.ts new file mode 100644 index 0000000..12cee54 --- /dev/null +++ b/src/oracle/paramTable.service.ts @@ -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 { } + } +} \ No newline at end of file