diff --git a/src/app.module.ts b/src/app.module.ts index 46adb9a..d32eb85 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -4,7 +4,7 @@ import { OracleModule } from './oracle/oracle.module'; import { AuthModule } from './auth/auth.module'; @Module({ - imports: [ AuthModule, DbModule, OracleModule], + imports: [AuthModule, DbModule, OracleModule], controllers: [], providers: [], }) diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index b867eeb..59ced64 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -5,12 +5,11 @@ import { AuthLoginDTO } from './auth.dto'; @Controller() export class AuthController { + constructor(private readonly authService: AuthService) {} - constructor(private readonly authService:AuthService){} - - @ApiTags('Auth') - @Post('/login') - login(@Body() body:AuthLoginDTO){ - return this.authService.login(body); - } + @ApiTags('Auth') + @Post('/login') + login(@Body() body: AuthLoginDTO) { + return this.authService.login(body); + } } diff --git a/src/auth/auth.dto.ts b/src/auth/auth.dto.ts index 5b1267f..181584e 100644 --- a/src/auth/auth.dto.ts +++ b/src/auth/auth.dto.ts @@ -1,13 +1,12 @@ -import { ApiProperty } from "@nestjs/swagger"; -import { IsString } from "class-validator"; +import { ApiProperty } from '@nestjs/swagger'; +import { IsString } from 'class-validator'; -export class AuthLoginDTO{ - - @ApiProperty({required:true}) - @IsString() - p_emailaddr:string; +export class AuthLoginDTO { + @ApiProperty({ required: true }) + @IsString() + p_emailaddr: string; - @ApiProperty({required:true}) - @IsString() - p_password:string; -} \ No newline at end of file + @ApiProperty({ required: true }) + @IsString() + p_password: string; +} diff --git a/src/auth/auth.module.ts b/src/auth/auth.module.ts index 9ab79c8..5fc5978 100644 --- a/src/auth/auth.module.ts +++ b/src/auth/auth.module.ts @@ -1,12 +1,11 @@ import { Module } from '@nestjs/common'; import { AuthService } from './auth.service'; import { AuthController } from './auth.controller'; -import { OracleDBService } from 'src/db/db.service'; import { DbModule } from 'src/db/db.module'; @Module({ - imports:[DbModule], + imports: [DbModule], providers: [AuthService], - controllers: [AuthController] + controllers: [AuthController], }) export class AuthModule {} diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index c45c953..63649e9 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -1,70 +1,67 @@ import { BadRequestException, Injectable } from '@nestjs/common'; import { OracleDBService } from 'src/db/db.service'; import { AuthLoginDTO } from './auth.dto'; -import * as oracledb from 'oracledb' +import * as oracledb from 'oracledb'; @Injectable() export class AuthService { + constructor(private readonly oracleDBService: OracleDBService) {} - constructor(private readonly oracleDBService: OracleDBService) { } + async login(body: AuthLoginDTO) { + let connection; + let rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - async login(body:AuthLoginDTO) { - let connection; - let rows = []; - let crows:any = []; - try { - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN USERLOGIN_PKG.ValidateUser(:p_emailaddr,:p_password,:p_login_cursor); END;`, - { - p_emailaddr: { - val: body.p_emailaddr, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_password: { - val: body.p_password, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_login_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + p_emailaddr: { + val: body.p_emailaddr, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_password: { + val: body.p_password, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_login_cursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); - if (result.outBinds && result.outBinds.p_login_cursor) { - const cursor = result.outBinds.p_login_cursor; - let rowsBatch; + if (result.outBinds && result.outBinds.p_login_cursor) { + const cursor = result.outBinds.p_login_cursor; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); - rows = rows.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); - } else { - return new BadRequestException({Error:"Error executing request try after some time!"}); - } - - if(rows[0]["ERRORMESG"]){ - return {error:"Invalid username or password!"} - } - return {msg:"Logged in successfully"} - - } catch (err) { - console.error('Error fetching users: ', err.message); - return {error:"Invalid username or password"} - } finally { } + do { + rowsBatch = await cursor.getRows(100); + rows = rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + await cursor.close(); + } else { + return new BadRequestException({ + Error: 'Error executing request try after some time!', + }); + } + if (rows[0]['ERRORMESG']) { + return { error: 'Invalid username or password!' }; + } + return { msg: 'Logged in successfully' }; + } catch (err) { + console.error('Error fetching users: ', err.message); + return { error: 'Invalid username or password' }; } + } } diff --git a/src/db/db.module.ts b/src/db/db.module.ts index 7973daa..b1431ab 100644 --- a/src/db/db.module.ts +++ b/src/db/db.module.ts @@ -3,7 +3,7 @@ import { MssqlDBService, OracleDBService } from './db.service'; @Global() @Module({ - providers: [OracleDBService,MssqlDBService], - exports:[OracleDBService,MssqlDBService] + providers: [OracleDBService, MssqlDBService], + exports: [OracleDBService, MssqlDBService], }) export class DbModule {} diff --git a/src/db/db.service.ts b/src/db/db.service.ts index 142dc9d..0010f5f 100644 --- a/src/db/db.service.ts +++ b/src/db/db.service.ts @@ -1,62 +1,62 @@ -import { MssqlConfig , OracleConfig} from 'ormconfig'; -import { createPool, Pool, Connection as cob, } from 'oracledb'; +import { MssqlConfig, OracleConfig } from 'ormconfig'; +import { createPool, Pool, Connection as cob } from 'oracledb'; import { Connection, ConnectionPool } from 'mssql'; -import { Global, Injectable } from '@nestjs/common'; +import { Injectable } from '@nestjs/common'; @Injectable() export class OracleDBService { - private pool: Pool; + private pool: Pool; - constructor() { - this.initializePool(); - } + constructor() { + this.initializePool(); + } - private async initializePool() { - this.pool = await createPool({ - ...OracleConfig, - poolMin: 1, - poolMax: 10, - poolIncrement: 1, - }); - } + private async initializePool() { + this.pool = await createPool({ + ...OracleConfig, + poolMin: 1, + poolMax: 10, + poolIncrement: 1, + }); + } - async getConnection(): Promise { - const connection = await this.pool.getConnection(); - console.log('Database connection initialized successfully for oracle.'); - return connection; - } + async getConnection(): Promise { + const connection = await this.pool.getConnection(); + console.log('Database connection initialized successfully for oracle.'); + return connection; + } } @Injectable() export class MssqlDBService { - private pool: ConnectionPool; - private readonly config = { - ...MssqlConfig, - server: "localhost", - pool: { - max: 10, - min: 0, - idleTimeoutMillis: 30000, - }, - }; + private pool: ConnectionPool; + private readonly config = { + ...MssqlConfig, + server: 'localhost', + pool: { + max: 10, + min: 0, + idleTimeoutMillis: 30000, + }, + }; - constructor() { - this.initializePool(); - } + constructor() { + this.initializePool(); + } - private async initializePool() { - this.pool = new ConnectionPool(this.config); - } + private initializePool() { + this.pool = new ConnectionPool(this.config); + } - async getConnection(): Promise { - try { - const connection = await this.pool.connect(); - console.log('Database connection initialized successfully for Mssql.'); - // console.log(`Connection established to server: ${this.config.server}`); // Log server info - return connection; - } catch (error) { - console.error('Error getting connection from pool', error.stack); - throw error; // Rethrow the error after logging - } + async getConnection(): Promise { + try { + const connection = await this.pool.connect(); + console.log('Database connection initialized successfully for Mssql.'); + // console.log(`Connection established to server: ${this.config.server}`); // Log server info + return connection; + } catch (error) { + console.error('Error getting connection from pool', error.stack); + throw error; // Rethrow the error after logging } -} \ No newline at end of file + } +} diff --git a/src/main.ts b/src/main.ts index e5a9a93..4401b97 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,17 +1,21 @@ import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; -import { BadRequestException, ValidationError, ValidationPipe } from '@nestjs/common'; +import { + BadRequestException, + ValidationError, + ValidationPipe, +} from '@nestjs/common'; import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; import { SwaggerDocumentOptions } from '@nestjs/swagger'; async function bootstrap() { const app = await NestFactory.create(AppModule, { cors: { - "origin": "*", - "methods": "GET,HEAD,PUT,PATCH,POST,DELETE", - "preflightContinue": false, - "optionsSuccessStatus": 204 - } + origin: '*', + methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', + preflightContinue: false, + optionsSuccessStatus: 204, + }, }); function extractConstraints(validationErrors: ValidationError[]) { @@ -41,39 +45,49 @@ async function bootstrap() { } const customExceptionFactory = (validationErrors: ValidationError[]) => { + const res = extractConstraints(validationErrors); - let res = extractConstraints(validationErrors); + const newResult = res + .map((x) => { + const errorMessage = x[Object.keys(x)[0]]; - let newResult = res.map(x => { - const errorMessage = x[Object.keys(x)[0]]; + return { message: errorMessage }; + }) + .filter(Boolean); - return { message: errorMessage }; - }).filter(Boolean); - - return new BadRequestException({ message: 'Validation failed', errors: newResult }); + return new BadRequestException({ + message: 'Validation failed', + errors: newResult, + }); }; - app.useGlobalPipes(new ValidationPipe({ - transform: true, - exceptionFactory: customExceptionFactory, - whitelist: true, - stopAtFirstError: true, - forbidNonWhitelisted: true, - })); + app.useGlobalPipes( + new ValidationPipe({ + transform: true, + exceptionFactory: customExceptionFactory, + whitelist: true, + stopAtFirstError: true, + forbidNonWhitelisted: true, + }), + ); // app.useGlobalPipes(new ValidationPipe({ exceptionFactory:customExceptionFactory, whitelist: true, forbidNonWhitelisted: true, transform: true })); const config = new DocumentBuilder() .setTitle('API') .setDescription('API description') .setVersion('1.0') - .addServer("http://localhost:3000", "Development Server 1") - .addServer("https://dev.alphaomegainfosys.com/test-api", "Development Server 2") + .addServer('http://localhost:3000', 'Development Server 1') + .addServer( + 'https://dev.alphaomegainfosys.com/test-api', + 'Development Server 2', + ) .build(); const options: SwaggerDocumentOptions = { autoTagControllers: false, }; - const documentFactory = () => SwaggerModule.createDocument(app, config, options); + const documentFactory = () => + SwaggerModule.createDocument(app, config, options); SwaggerModule.setup('api', app, documentFactory); await app.listen(process.env.PORT ?? 3000); diff --git a/src/oracle/home-page/home-page.controller.ts b/src/oracle/home-page/home-page.controller.ts index 9341bff..105d7c1 100644 --- a/src/oracle/home-page/home-page.controller.ts +++ b/src/oracle/home-page/home-page.controller.ts @@ -1,78 +1,81 @@ import { - Get, - Post, - Body, - Param, - Controller, - ParseIntPipe, - BadRequestException + Get, + Post, + Body, + Param, + Controller, + ParseIntPipe, + BadRequestException, } from '@nestjs/common'; import { HomePageService } from './home-page.service'; import { ApiTags } from '@nestjs/swagger'; import { - SaveCarnetApplicationDTO, - TransmitApplicationtoProcessDTO, - GetCarnetDetailsbyCarnetStatusDTO + SaveCarnetApplicationDTO, + TransmitApplicationtoProcessDTO, + GetCarnetDetailsbyCarnetStatusDTO, } from './home-page.dto'; @Controller() export class HomePageController { - constructor( - private readonly homePageService: HomePageService - ) { } + constructor(private readonly homePageService: HomePageService) {} - @ApiTags('HomePage - Oracle') - @Get('/oracle/GetHomePageData/:id') - GetHomePageData(@Param('id', ParseIntPipe) id: number) { - return this.homePageService.GetHomePageData(id); + @ApiTags('HomePage - Oracle') + @Get('/oracle/GetHomePageData/:id') + GetHomePageData(@Param('id', ParseIntPipe) id: number) { + return this.homePageService.GetHomePageData(id); + } + + @ApiTags('HomePage - Oracle') + @Get('/oracle/GetCarnetSummaryData/:userid') + GetCarnetSummaryData(@Param('userid') id: string) { + return this.homePageService.GetCarnetSummaryData(id); + } + + @ApiTags('HomePage - Oracle') + @Get( + '/oracle/GetCarnetDetailsbyCarnetStatus/:p_spid/:p_userid/:p_CarnetStatus', + ) + GetCarnetDetailsbyCarnetStatus( + @Param('p_spid', ParseIntPipe) p_spid: number, + @Param('p_userid') p_userid: string, + @Param('p_CarnetStatus') p_CarnetStatus: string, + ) { + if (!p_spid || !p_userid || !p_CarnetStatus) { + throw new BadRequestException( + 'spid, userid and Carnet Status are required', + ); + } else if (Number(p_userid) || Number(p_CarnetStatus)) { + throw new BadRequestException( + 'Param p_userid and p_CarnetStatus should be string', + ); } + try { + const body: GetCarnetDetailsbyCarnetStatusDTO = { + p_spid: p_spid, + p_userid: p_userid, + p_CarnetStatus: p_CarnetStatus, + }; - @ApiTags('HomePage - Oracle') - @Get('/oracle/GetCarnetSummaryData/:userid') - GetCarnetSummaryData(@Param('userid') id: string) { - return this.homePageService.GetCarnetSummaryData(id); + return this.homePageService.GetCarnetDetailsbyCarnetStatus(body); + } catch (err) { + return new BadRequestException({ + message: 'Validation faileda', + error: err.message, + }); } + } - @ApiTags('HomePage - Oracle') - @Get('/oracle/GetCarnetDetailsbyCarnetStatus/:p_spid/:p_userid/:p_CarnetStatus') - GetCarnetDetailsbyCarnetStatus( - @Param('p_spid', ParseIntPipe) p_spid: number, - @Param('p_userid') p_userid: string, - @Param('p_CarnetStatus') p_CarnetStatus: string - ) { - if (!p_spid || !p_userid || !p_CarnetStatus) { - throw new BadRequestException('spid, userid and Carnet Status are required'); - } - else if (Number(p_userid) || Number(p_CarnetStatus)) { - throw new BadRequestException('Param p_userid and p_CarnetStatus should be string'); - } - try { - const body: GetCarnetDetailsbyCarnetStatusDTO = { - p_spid: p_spid, - p_userid: p_userid, - p_CarnetStatus: p_CarnetStatus - }; + @ApiTags('HomePage - Oracle') + @Post('/oracle/SaveCarnetApplication') + SaveCarnetApplication(@Body() body: SaveCarnetApplicationDTO) { + return this.homePageService.SaveCarnetApplication(body); + } - return this.homePageService.GetCarnetDetailsbyCarnetStatus(body); - } - catch (err) { - return new BadRequestException({ message: 'Validation faileda', error: err.message }) - } - } - - @ApiTags('HomePage - Oracle') - @Post('/oracle/SaveCarnetApplication') - SaveCarnetApplication(@Body() body: SaveCarnetApplicationDTO) { - return this.homePageService.SaveCarnetApplication(body); - } - - @ApiTags('HomePage - Oracle') - @Post('/oracle/TransmitApplicationtoProcess') - TransmitApplicationtoProcess(@Body() body: TransmitApplicationtoProcessDTO) { - return this.homePageService.TransmitApplicationtoProcess(body); - } - - + @ApiTags('HomePage - Oracle') + @Post('/oracle/TransmitApplicationtoProcess') + TransmitApplicationtoProcess(@Body() body: TransmitApplicationtoProcessDTO) { + return this.homePageService.TransmitApplicationtoProcess(body); + } } diff --git a/src/oracle/home-page/home-page.dto.ts b/src/oracle/home-page/home-page.dto.ts index 5713072..c86bf5e 100644 --- a/src/oracle/home-page/home-page.dto.ts +++ b/src/oracle/home-page/home-page.dto.ts @@ -1,293 +1,363 @@ -import { ApiProperty } from "@nestjs/swagger"; -import { Type } from "class-transformer"; -import { IsArray, IsDefined, IsInt, IsNumber, IsOptional, IsString, Length, Max, Min, ValidateNested } from "class-validator"; +import { ApiProperty } from '@nestjs/swagger'; +import { Type } from 'class-transformer'; +import { + IsArray, + IsDefined, + IsInt, + IsNumber, + IsOptional, + IsString, + Length, + Max, + Min, + ValidateNested, +} from 'class-validator'; export class p_gltableDTO { - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property ItemNo must not exceed 999999999" }) - @Min(0, { message: "Property ItemNo must be at least 0 or more" }) - @IsInt() - @IsNumber({}, { message: "Property ItemNo must be a number" }) - @IsDefined({ message: "Property ItemNo is required" }) - ItemNo: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property ItemNo must not exceed 999999999' }) + @Min(0, { message: 'Property ItemNo must be at least 0 or more' }) + @IsInt() + @IsNumber({}, { message: 'Property ItemNo must be a number' }) + @IsDefined({ message: 'Property ItemNo is required' }) + ItemNo: number; - @ApiProperty({ required: true }) - @Length(0, 1000, { message: "Property ItemDescription must be between 1 and 1000 characters" }) - @IsString({ message: "Property ItemDescription should be string" }) - @IsDefined({ message: "Property ItemDescription is required" }) - ItemDescription: string; + @ApiProperty({ required: true }) + @Length(0, 1000, { + message: 'Property ItemDescription must be between 1 and 1000 characters', + }) + @IsString({ message: 'Property ItemDescription should be string' }) + @IsDefined({ message: 'Property ItemDescription is required' }) + ItemDescription: string; - @ApiProperty({ required: true }) - @IsNumber({},{ message: "Property ItemValue should be number" }) - @IsDefined({ message: "Property ItemValue is required" }) - ItemValue: number; + @ApiProperty({ required: true }) + @IsNumber({}, { message: 'Property ItemValue should be number' }) + @IsDefined({ message: 'Property ItemValue is required' }) + ItemValue: number; - @ApiProperty({ required: true }) - @Max(99999999999, { message: "Property Noofpieces must not exceed 99999999999" }) - @Min(0, { message: "Property Noofpieces must be at least 0 or more" }) - @IsInt() - @IsNumber({}, { message: "Property Noofpieces must be a number" }) - @IsDefined({ message: "Property Noofpieces is required" }) - Noofpieces: number; + @ApiProperty({ required: true }) + @Max(99999999999, { + message: 'Property Noofpieces must not exceed 99999999999', + }) + @Min(0, { message: 'Property Noofpieces must be at least 0 or more' }) + @IsInt() + @IsNumber({}, { message: 'Property Noofpieces must be a number' }) + @IsDefined({ message: 'Property Noofpieces is required' }) + Noofpieces: number; - @ApiProperty({ required: false }) - @IsNumber() - @IsOptional() - ItemWeight?: number; + @ApiProperty({ required: false }) + @IsNumber() + @IsOptional() + ItemWeight?: number; - @ApiProperty({ required: false }) - @Length(0, 10, { message: "Property ItemWeightUOM must be between 0 and 10 characters" }) - @IsString() - @IsOptional() - ItemWeightUOM?: string; + @ApiProperty({ required: false }) + @Length(0, 10, { + message: 'Property ItemWeightUOM must be between 0 and 10 characters', + }) + @IsString() + @IsOptional() + ItemWeightUOM?: string; - @ApiProperty({ required: true }) - @Length(0, 2, { message: "Property GoodsOriginCountry must be between 0 and 2 characters" }) - @IsString({ message: "Property GoodsOriginCountry should be string" }) - @IsDefined({ message: "Property name is required" }) - GoodsOriginCountry: string; + @ApiProperty({ required: true }) + @Length(0, 2, { + message: 'Property GoodsOriginCountry must be between 0 and 2 characters', + }) + @IsString({ message: 'Property GoodsOriginCountry should be string' }) + @IsDefined({ message: 'Property name is required' }) + GoodsOriginCountry: string; } export class p_countrytableDTO { - @ApiProperty({ required: true }) - @Length(0, 1, { message: "Property VisitTransitInd must be 0 to 1 characters" }) - @IsString() - @IsDefined({ message: "Property VisitTransitInd is required" }) - VisitTransitInd: string; + @ApiProperty({ required: true }) + @Length(0, 1, { + message: 'Property VisitTransitInd must be 0 to 1 characters', + }) + @IsString() + @IsDefined({ message: 'Property VisitTransitInd is required' }) + VisitTransitInd: string; - @ApiProperty({ required: true }) - @Length(0, 2, { message: "Property CountryCode must be between 0 to 2 characters" }) - @IsString() - @IsDefined({ message: "Property CountryCode is required" }) - CountryCode: string; + @ApiProperty({ required: true }) + @Length(0, 2, { + message: 'Property CountryCode must be between 0 to 2 characters', + }) + @IsString() + @IsDefined({ message: 'Property CountryCode is required' }) + CountryCode: string; - @ApiProperty({ required: true }) - @Max(999, { message: "Property NoOfTimesEntLeave must not exceed 999" }) - @Min(0, { message: "Property NoOfTimesEntLeave must be at least 0 or more" }) - @IsInt() - @IsNumber({}, { message: "Property NoOfTimesEntLeave must be a number" }) - @IsDefined({ message: "Property NoOfTimesEntLeave is required" }) - NoOfTimesEntLeave: number; + @ApiProperty({ required: true }) + @Max(999, { message: 'Property NoOfTimesEntLeave must not exceed 999' }) + @Min(0, { message: 'Property NoOfTimesEntLeave must be at least 0 or more' }) + @IsInt() + @IsNumber({}, { message: 'Property NoOfTimesEntLeave must be a number' }) + @IsDefined({ message: 'Property NoOfTimesEntLeave is required' }) + NoOfTimesEntLeave: number; } export class SaveCarnetApplicationDTO { - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_spid must not exceed 999999999" }) - @Min(0, { message: "Property p_spid must be at least 0 or more" }) - @IsInt() - @IsNumber({}, { message: "Property p_spid must be a number" }) - p_spid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) + @Min(0, { message: 'Property p_spid must be at least 0 or more' }) + @IsInt() + @IsNumber({}, { message: 'Property p_spid must be a number' }) + p_spid: number; - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_clientid must not exceed 999999999" }) - @Min(0, { message: "Property p_clientid must be at least 0 or more" }) - @IsInt() - @IsNumber({}, { message: "Property p_clientid must be a number" }) - p_clientid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_clientid must not exceed 999999999' }) + @Min(0, { message: 'Property p_clientid must be at least 0 or more' }) + @IsInt() + @IsNumber({}, { message: 'Property p_clientid must be a number' }) + p_clientid: number; - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_locationid must not exceed 999999999" }) - @Min(0, { message: "Property p_locationid must be at least 0 or more" }) - @IsInt() - @IsNumber({}, { message: "Property p_locationid must be a number" }) - p_locationid: number; + @ApiProperty({ required: true }) + @Max(999999999, { + message: 'Property p_locationid must not exceed 999999999', + }) + @Min(0, { message: 'Property p_locationid must be at least 0 or more' }) + @IsInt() + @IsNumber({}, { message: 'Property p_locationid must be a number' }) + p_locationid: number; - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property p_userid must be between 0 to 50 characters" }) - @IsString() - p_userid: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property p_userid must be between 0 to 50 characters', + }) + @IsString() + p_userid: string; - @ApiProperty({ required: false }) - @Max(999999999, { message: "Property p_headerid must not exceed 999999999" }) - @Min(0, { message: "Property p_headerid must be at least 0 or more" }) - @IsInt() - @IsNumber({}, { message: "Property p_headerid must be a number" }) - @IsOptional() - p_headerid?: number; + @ApiProperty({ required: false }) + @Max(999999999, { message: 'Property p_headerid must not exceed 999999999' }) + @Min(0, { message: 'Property p_headerid must be at least 0 or more' }) + @IsInt() + @IsNumber({}, { message: 'Property p_headerid must be a number' }) + @IsOptional() + p_headerid?: number; - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property p_applicationname must be between 0 to 50 characters" }) - @IsString() - p_applicationname: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property p_applicationname must be between 0 to 50 characters', + }) + @IsString() + p_applicationname: string; - @ApiProperty({ required: false }) - @Max(999999999, { message: "Property p_holderid must not exceed 999999999" }) - @Min(0, { message: "Property p_holderid must be at least 0 or more" }) - @IsInt() - @IsNumber({}, { message: "Property p_holderid must be a number" }) - @IsOptional() - p_holderid?: number; + @ApiProperty({ required: false }) + @Max(999999999, { message: 'Property p_holderid must not exceed 999999999' }) + @Min(0, { message: 'Property p_holderid must be at least 0 or more' }) + @IsInt() + @IsNumber({}, { message: 'Property p_holderid must be a number' }) + @IsOptional() + p_holderid?: number; - @ApiProperty({ required: false }) - @Length(0, 1, { message: "Property p_commercialsampleflag must be between 0 to 1 characters" }) - @IsString() - @IsOptional() - p_commercialsampleflag?: string; + @ApiProperty({ required: false }) + @Length(0, 1, { + message: + 'Property p_commercialsampleflag must be between 0 to 1 characters', + }) + @IsString() + @IsOptional() + p_commercialsampleflag?: string; - @ApiProperty({ required: false }) - @Length(0, 1, { message: "Property p_profequipmentflag must be between 0 to 1 characters" }) - @IsString() - @IsOptional() - p_profequipmentflag?: string; + @ApiProperty({ required: false }) + @Length(0, 1, { + message: 'Property p_profequipmentflag must be between 0 to 1 characters', + }) + @IsString() + @IsOptional() + p_profequipmentflag?: string; - @ApiProperty({ required: false }) - @Length(0, 1, { message: "Property p_exhibitionsfairflag must be between 0 to 1 characters" }) - @IsString() - @IsOptional() - p_exhibitionsfairflag?: string; + @ApiProperty({ required: false }) + @Length(0, 1, { + message: 'Property p_exhibitionsfairflag must be between 0 to 1 characters', + }) + @IsString() + @IsOptional() + p_exhibitionsfairflag?: string; - @ApiProperty({ required: false }) - @Length(0, 1, { message: "Property p_autoflag must be between 0 to 1 characters" }) - @IsString() - @IsOptional() - p_autoflag?: string; + @ApiProperty({ required: false }) + @Length(0, 1, { + message: 'Property p_autoflag must be between 0 to 1 characters', + }) + @IsString() + @IsOptional() + p_autoflag?: string; - @ApiProperty({ required: false }) - @Length(0, 1, { message: "Property p_horseflag must be between 0 to 1 characters" }) - @IsString() - @IsOptional() - p_horseflag?: string; + @ApiProperty({ required: false }) + @Length(0, 1, { + message: 'Property p_horseflag must be between 0 to 1 characters', + }) + @IsString() + @IsOptional() + p_horseflag?: string; - @ApiProperty({ required: false }) - @Length(0, 200, { message: "Property p_authrep must be between 0 to 200 characters" }) - @IsString() - @IsOptional() - p_authrep?: string; + @ApiProperty({ required: false }) + @Length(0, 200, { + message: 'Property p_authrep must be between 0 to 200 characters', + }) + @IsString() + @IsOptional() + p_authrep?: string; - @ApiProperty({ required: false, type: () => [p_gltableDTO] }) - @Type(() => p_gltableDTO) - @ValidateNested({ each: true }) - @IsArray() - // @ArrayNotEmpty({message:"Property gltable should not be empty"}) - @IsOptional() - p_gltable?: p_gltableDTO[]; + @ApiProperty({ required: false, type: () => [p_gltableDTO] }) + @Type(() => p_gltableDTO) + @ValidateNested({ each: true }) + @IsArray() + // @ArrayNotEmpty({message:"Property gltable should not be empty"}) + @IsOptional() + p_gltable?: p_gltableDTO[]; - @ApiProperty({ required: false }) - @Max(99999, { message: "Property p_ussets must not exceed 99999" }) - @Min(0, { message: "Property p_ussets must be at least 0 or more" }) - @IsInt() - @IsNumber({}, { message: "Property p_ussets must be a number" }) - @IsOptional() - p_ussets?: number; + @ApiProperty({ required: false }) + @Max(99999, { message: 'Property p_ussets must not exceed 99999' }) + @Min(0, { message: 'Property p_ussets must be at least 0 or more' }) + @IsInt() + @IsNumber({}, { message: 'Property p_ussets must be a number' }) + @IsOptional() + p_ussets?: number; - @ApiProperty({ required: false, type: () => [p_countrytableDTO] }) - @ValidateNested({ each: true }) - @IsArray() - @Type(() => p_countrytableDTO) - @IsOptional() - p_countrytable?: p_countrytableDTO[]; + @ApiProperty({ required: false, type: () => [p_countrytableDTO] }) + @ValidateNested({ each: true }) + @IsArray() + @Type(() => p_countrytableDTO) + @IsOptional() + p_countrytable?: p_countrytableDTO[]; - @ApiProperty({ required: false }) - @Length(0, 10, { message: "Property p_shiptotype must be between 0 to 10 characters" }) - @IsString() - @IsOptional() - p_shiptotype?: string; + @ApiProperty({ required: false }) + @Length(0, 10, { + message: 'Property p_shiptotype must be between 0 to 10 characters', + }) + @IsString() + @IsOptional() + p_shiptotype?: string; - @ApiProperty({ required: false }) - @Max(999999999, { message: "Property p_shipaddrid must not exceed 999999999" }) - @Min(0, { message: "Property p_shipaddrid must be at least 0 or more" }) - @IsInt() - @IsNumber({}, { message: "Property p_shipaddrid must be a number" }) - @IsOptional() - p_shipaddrid?: number; + @ApiProperty({ required: false }) + @Max(999999999, { + message: 'Property p_shipaddrid must not exceed 999999999', + }) + @Min(0, { message: 'Property p_shipaddrid must be at least 0 or more' }) + @IsInt() + @IsNumber({}, { message: 'Property p_shipaddrid must be a number' }) + @IsOptional() + p_shipaddrid?: number; - @ApiProperty({ required: false }) - @Length(0, 1, { message: "Property p_formofsecurity must be between 0 to 1 characters" }) - @IsString() - @IsOptional() - p_formofsecurity?: string; + @ApiProperty({ required: false }) + @Length(0, 1, { + message: 'Property p_formofsecurity must be between 0 to 1 characters', + }) + @IsString() + @IsOptional() + p_formofsecurity?: string; - @ApiProperty({ required: false }) - @Length(0, 10, { message: "Property p_insprotection must be between 0 to 10 characters" }) - @IsString() - @IsOptional() - p_insprotection?: string; + @ApiProperty({ required: false }) + @Length(0, 10, { + message: 'Property p_insprotection must be between 0 to 10 characters', + }) + @IsString() + @IsOptional() + p_insprotection?: string; - @ApiProperty({ required: false }) - @Length(0, 10, { message: "Property p_ldiprotection must be between 0 to 10 characters" }) - @IsString() - @IsOptional() - p_ldiprotection?: string; + @ApiProperty({ required: false }) + @Length(0, 10, { + message: 'Property p_ldiprotection must be between 0 to 10 characters', + }) + @IsString() + @IsOptional() + p_ldiprotection?: string; - @ApiProperty({ required: false }) - @Length(0, 10, { message: "Property p_deliverytype must be between 0 to 10 characters" }) - @IsString() - @IsOptional() - p_deliverytype?: string; + @ApiProperty({ required: false }) + @Length(0, 10, { + message: 'Property p_deliverytype must be between 0 to 10 characters', + }) + @IsString() + @IsOptional() + p_deliverytype?: string; - @ApiProperty({ required: false }) - @Length(0, 10, { message: "Property p_deliverymethod must be between 0 to 10 characters" }) - @IsString() - @IsOptional() - p_deliverymethod?: string; + @ApiProperty({ required: false }) + @Length(0, 10, { + message: 'Property p_deliverymethod must be between 0 to 10 characters', + }) + @IsString() + @IsOptional() + p_deliverymethod?: string; - @ApiProperty({ required: false }) - @Length(0, 10, { message: "Property p_paymentmethod must be between 0 to 10 characters" }) - @IsString() - @IsOptional() - p_paymentmethod?: string; + @ApiProperty({ required: false }) + @Length(0, 10, { + message: 'Property p_paymentmethod must be between 0 to 10 characters', + }) + @IsString() + @IsOptional() + p_paymentmethod?: string; - @ApiProperty({ required: false }) - @Length(0, 20, { message: "Property p_custcourierno must be between 0 to 20 characters" }) - @IsString() - @IsOptional() - p_custcourierno?: string; + @ApiProperty({ required: false }) + @Length(0, 20, { + message: 'Property p_custcourierno must be between 0 to 20 characters', + }) + @IsString() + @IsOptional() + p_custcourierno?: string; - @ApiProperty({ required: false }) - @Length(0, 20, { message: "Property p_refno must be between 0 to 20 characters" }) - @IsString() - @IsOptional() - p_refno?: string; + @ApiProperty({ required: false }) + @Length(0, 20, { + message: 'Property p_refno must be between 0 to 20 characters', + }) + @IsString() + @IsOptional() + p_refno?: string; - @ApiProperty({ required: false }) - @Length(0, 2000, { message: "Property p_notes must be between 0 to 2000 characters" }) - @IsString() - @IsOptional() - p_notes?: string; + @ApiProperty({ required: false }) + @Length(0, 2000, { + message: 'Property p_notes must be between 0 to 2000 characters', + }) + @IsString() + @IsOptional() + p_notes?: string; } export class TransmitApplicationtoProcessDTO { - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_spid must not exceed 999999999" }) - @Min(0, { message: "Property p_spid must be at least 0 or more" }) - @IsInt() - @IsNumber({}, { message: "Property p_spid must be a number" }) - @IsDefined({message:"Property p_spid is required"}) - p_spid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) + @Min(0, { message: 'Property p_spid must be at least 0 or more' }) + @IsInt() + @IsNumber({}, { message: 'Property p_spid must be a number' }) + @IsDefined({ message: 'Property p_spid is required' }) + p_spid: number; - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property p_userid must be between 0 to 50 characters" }) - @IsString() - @IsDefined({message:"Property p_userid is required"}) - p_userid: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property p_userid must be between 0 to 50 characters', + }) + @IsString() + @IsDefined({ message: 'Property p_userid is required' }) + p_userid: string; - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_spid must not exceed 999999999" }) - @Min(0, { message: "Property p_spid must be at least 0 or more" }) - @IsInt() - @IsNumber({}, { message: "Property p_headerid must be a number" }) - @IsDefined({message:"Property p_headerid is required"}) - p_headerid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) + @Min(0, { message: 'Property p_spid must be at least 0 or more' }) + @IsInt() + @IsNumber({}, { message: 'Property p_headerid must be a number' }) + @IsDefined({ message: 'Property p_headerid is required' }) + p_headerid: number; } export class GetCarnetDetailsbyCarnetStatusDTO { - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_spid must not exceed 999999999" }) - @Min(0, { message: "Property p_spid must be at least 0 or more" }) - @IsInt() - @IsNumber({}, { message: "Property p_spid must be a number" }) - @IsDefined({message:"Property p_spid is required"}) - p_spid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) + @Min(0, { message: 'Property p_spid must be at least 0 or more' }) + @IsInt() + @IsNumber({}, { message: 'Property p_spid must be a number' }) + @IsDefined({ message: 'Property p_spid is required' }) + p_spid: number; - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property p_userid must be between 0 to 50 characters" }) - @IsString({ message: "Property p_userid must be string" }) - @IsDefined({message:"Property p_userid is required"}) - p_userid: string; - - @ApiProperty({ required: true }) - @Length(0, 20, { message: "Property p_CarnetStatus must be between 0 to 20 characters" }) - @IsString() - @IsDefined({message:"Property p_CarnetStatus is required"}) - p_CarnetStatus: string; -} \ No newline at end of file + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property p_userid must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_userid must be string' }) + @IsDefined({ message: 'Property p_userid is required' }) + p_userid: string; + + @ApiProperty({ required: true }) + @Length(0, 20, { + message: 'Property p_CarnetStatus must be between 0 to 20 characters', + }) + @IsString() + @IsDefined({ message: 'Property p_CarnetStatus is required' }) + p_CarnetStatus: string; +} diff --git a/src/oracle/home-page/home-page.module.ts b/src/oracle/home-page/home-page.module.ts index 7f87b32..c91b122 100644 --- a/src/oracle/home-page/home-page.module.ts +++ b/src/oracle/home-page/home-page.module.ts @@ -4,8 +4,8 @@ import { HomePageController } from './home-page.controller'; import { DbModule } from 'src/db/db.module'; @Module({ - imports:[DbModule], - providers: [ HomePageService], - controllers: [HomePageController] + imports: [DbModule], + providers: [HomePageService], + controllers: [HomePageController], }) -export class HomePageModule {} +export class HomePageModule {} diff --git a/src/oracle/home-page/home-page.service.ts b/src/oracle/home-page/home-page.service.ts index e4a5128..2e76cb3 100644 --- a/src/oracle/home-page/home-page.service.ts +++ b/src/oracle/home-page/home-page.service.ts @@ -1,41 +1,39 @@ -import { Injectable } from "@nestjs/common"; -import { OracleDBService } from "src/db/db.service"; -import * as oracledb from 'oracledb' +import { Injectable } from '@nestjs/common'; +import { OracleDBService } from 'src/db/db.service'; +import * as oracledb from 'oracledb'; import { - p_gltableDTO, - p_countrytableDTO, - SaveCarnetApplicationDTO, - TransmitApplicationtoProcessDTO, - GetCarnetDetailsbyCarnetStatusDTO, -} from "./home-page.dto"; + p_gltableDTO, + SaveCarnetApplicationDTO, + TransmitApplicationtoProcessDTO, + GetCarnetDetailsbyCarnetStatusDTO, +} from './home-page.dto'; @Injectable() export class HomePageService { + constructor(private readonly oracleDBService: OracleDBService) {} - constructor(private readonly oracleDBService: OracleDBService) { } + async GetHomePageData(P_spid: number) { + let connection; + let p_basic_details = []; + let p_contacts = []; + let p_sequence = []; + let p_fees_comm = []; + let p_bf_fee = []; + let p_cf_Fee = []; + let p_cont_sheet_fee = []; + let p_ef_fee = []; + let p_security_deposit = []; + let p_param = []; + let p_region = []; - async GetHomePageData(P_spid: number) { - let connection; - let p_basic_details = []; - let p_contacts = [] - let p_sequence = []; - let p_fees_comm = []; - let p_bf_fee = []; - let p_cf_Fee = []; - let p_cont_sheet_fee = []; - let p_ef_fee = []; - let p_security_deposit = []; - let p_param = []; - let p_region = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - try { - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN USERLOGIN_PKG.GetHomePageData( :P_spid, :p_basic_details_cur, @@ -51,453 +49,482 @@ export class HomePageService { :p_region_cur ); END;`, - { - P_spid: { - val: P_spid, - type: oracledb.DB_TYPE_NUMBER, - }, - p_basic_details_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - }, - p_contacts_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - }, - p_sequence_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - }, - p_fees_comm_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - }, - p_bf_fee_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - }, - p_cf_Fee_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - }, - p_cont_sheet_fee_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - }, - p_ef_fee_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - }, - p_security_deposit_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - }, - p_param_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - }, - p_region_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + P_spid: { + val: P_spid, + type: oracledb.DB_TYPE_NUMBER, + }, + p_basic_details_cur: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + p_contacts_cur: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + p_sequence_cur: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + p_fees_comm_cur: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + p_bf_fee_cur: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + p_cf_Fee_cur: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + p_cont_sheet_fee_cur: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + p_ef_fee_cur: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + p_security_deposit_cur: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + p_param_cur: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + p_region_cur: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); - if (result.outBinds && result.outBinds.p_basic_details_cur) { - const cursor = result.outBinds.p_basic_details_cur; - let rowsBatch; + if (result.outBinds && result.outBinds.p_basic_details_cur) { + const cursor = result.outBinds.p_basic_details_cur; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); - p_basic_details = p_basic_details.concat(rowsBatch); - } while (rowsBatch.length > 0); + do { + rowsBatch = await cursor.getRows(100); + p_basic_details = p_basic_details.concat(rowsBatch); + } while (rowsBatch.length > 0); + await cursor.close(); + } - await cursor.close(); + if (result.outBinds && result.outBinds.p_contacts_cur) { + const cursor = result.outBinds.p_contacts_cur; + let rowsBatch; + + do { + rowsBatch = await cursor.getRows(100); + p_contacts = p_contacts.concat(rowsBatch); + } while (rowsBatch.length > 0); + + await cursor.close(); + } + + if (result.outBinds && result.outBinds.p_sequence_cur) { + const cursor = result.outBinds.p_sequence_cur; + let rowsBatch; + + do { + rowsBatch = await cursor.getRows(100); + p_sequence = p_sequence.concat(rowsBatch); + } while (rowsBatch.length > 0); + + await cursor.close(); + } + + if (result.outBinds && result.outBinds.p_fees_comm_cur) { + const cursor = result.outBinds.p_fees_comm_cur; + let rowsBatch; + + do { + rowsBatch = await cursor.getRows(100); + p_fees_comm = p_fees_comm.concat(rowsBatch); + } while (rowsBatch.length > 0); + + await cursor.close(); + } + + if (result.outBinds && result.outBinds.p_bf_fee_cur) { + const cursor = result.outBinds.p_bf_fee_cur; + let rowsBatch; + + do { + rowsBatch = await cursor.getRows(100); + p_bf_fee = p_bf_fee.concat(rowsBatch); + } while (rowsBatch.length > 0); + + await cursor.close(); + } + + if (result.outBinds && result.outBinds.p_cf_Fee_cur) { + const cursor = result.outBinds.p_cf_Fee_cur; + let rowsBatch; + + do { + rowsBatch = await cursor.getRows(100); + p_cf_Fee = p_cf_Fee.concat(rowsBatch); + } while (rowsBatch.length > 0); + + await cursor.close(); + } + + if (result.outBinds && result.outBinds.p_cont_sheet_fee_cur) { + const cursor = result.outBinds.p_cont_sheet_fee_cur; + let rowsBatch; + + do { + rowsBatch = await cursor.getRows(100); + p_cont_sheet_fee = p_cont_sheet_fee.concat(rowsBatch); + } while (rowsBatch.length > 0); + + await cursor.close(); + } + + if (result.outBinds && result.outBinds.p_ef_fee_cur) { + const cursor = result.outBinds.p_ef_fee_cur; + let rowsBatch; + + do { + rowsBatch = await cursor.getRows(100); + p_ef_fee = p_ef_fee.concat(rowsBatch); + } while (rowsBatch.length > 0); + + await cursor.close(); + } + + if (result.outBinds && result.outBinds.p_security_deposit_cur) { + const cursor = result.outBinds.p_security_deposit_cur; + let rowsBatch; + + do { + rowsBatch = await cursor.getRows(100); + p_security_deposit = p_security_deposit.concat(rowsBatch); + } while (rowsBatch.length > 0); + + await cursor.close(); + } + + if (result.outBinds && result.outBinds.p_param_cur) { + const cursor = result.outBinds.p_param_cur; + let rowsBatch; + + do { + rowsBatch = await cursor.getRows(100); + p_param = p_param.concat(rowsBatch); + } while (rowsBatch.length > 0); + + await cursor.close(); + } + + if (result.outBinds && result.outBinds.p_region_cur) { + const cursor = result.outBinds.p_region_cur; + let rowsBatch; + + do { + rowsBatch = await cursor.getRows(100); + p_region = p_region.concat(rowsBatch); + } while (rowsBatch.length > 0); + + await cursor.close(); + } else { + throw new Error('No cursor returned from the stored procedure'); + } + + const tableData = { + p_basic_details, + p_contacts, + p_sequence, + p_fees_comm, + p_bf_fee, + p_cf_Fee, + p_cont_sheet_fee, + p_ef_fee, + p_security_deposit, + p_param, + p_region, + }; + + const output = {}; + + for (const key in tableData) { + // console.log(key); + + output[key] = tableData[key].map((obj) => { + const newObj = { ...obj }; + for (const innerKey in obj) { + if (key === 'p_fees_comm') { + if (innerKey.includes(' ')) { + // Check if the key has a space + const newKey = innerKey.replace(/ /g, '_').toUpperCase(); // Replace spaces and convert to uppercase + newObj[newKey] = obj[innerKey]; // Add the new key + delete newObj[innerKey]; // Remove the old key + } } + } + return newObj; + }); + } - if (result.outBinds && result.outBinds.p_contacts_cur) { - const cursor = result.outBinds.p_contacts_cur; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_contacts = p_contacts.concat(rowsBatch); - } while (rowsBatch.length > 0); - - - await cursor.close(); - } - - if (result.outBinds && result.outBinds.p_sequence_cur) { - const cursor = result.outBinds.p_sequence_cur; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_sequence = p_sequence.concat(rowsBatch); - } while (rowsBatch.length > 0); - - - await cursor.close(); - } - - if (result.outBinds && result.outBinds.p_fees_comm_cur) { - const cursor = result.outBinds.p_fees_comm_cur; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_fees_comm = p_fees_comm.concat(rowsBatch); - } while (rowsBatch.length > 0); - - - await cursor.close(); - } - - if (result.outBinds && result.outBinds.p_bf_fee_cur) { - const cursor = result.outBinds.p_bf_fee_cur; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_bf_fee = p_bf_fee.concat(rowsBatch); - } while (rowsBatch.length > 0); - - - await cursor.close(); - } - - if (result.outBinds && result.outBinds.p_cf_Fee_cur) { - const cursor = result.outBinds.p_cf_Fee_cur; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_cf_Fee = p_cf_Fee.concat(rowsBatch); - } while (rowsBatch.length > 0); - - - await cursor.close(); - } - - if (result.outBinds && result.outBinds.p_cont_sheet_fee_cur) { - const cursor = result.outBinds.p_cont_sheet_fee_cur; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_cont_sheet_fee = p_cont_sheet_fee.concat(rowsBatch); - } while (rowsBatch.length > 0); - - - await cursor.close(); - } - - if (result.outBinds && result.outBinds.p_ef_fee_cur) { - const cursor = result.outBinds.p_ef_fee_cur; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_ef_fee = p_ef_fee.concat(rowsBatch); - } while (rowsBatch.length > 0); - - - await cursor.close(); - } - - if (result.outBinds && result.outBinds.p_security_deposit_cur) { - const cursor = result.outBinds.p_security_deposit_cur; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_security_deposit = p_security_deposit.concat(rowsBatch); - } while (rowsBatch.length > 0); - - - await cursor.close(); - } - - if (result.outBinds && result.outBinds.p_param_cur) { - const cursor = result.outBinds.p_param_cur; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_param = p_param.concat(rowsBatch); - } while (rowsBatch.length > 0); - - - await cursor.close(); - } - - if (result.outBinds && result.outBinds.p_region_cur) { - const cursor = result.outBinds.p_region_cur; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_region = p_region.concat(rowsBatch); - } while (rowsBatch.length > 0); - - - await cursor.close(); - } - - else { - throw new Error('No cursor returned from the stored procedure'); - } - - let tableData = { - p_basic_details, - p_contacts, - p_sequence, - p_fees_comm, - p_bf_fee, - p_cf_Fee, - p_cont_sheet_fee, - p_ef_fee, - p_security_deposit, - p_param, - p_region, - }; - - let output = {} - - for (const key in tableData) { - // console.log(key); - - output[key] = tableData[key].map(obj => { - const newObj = { ...obj }; - for (const innerKey in obj) { - if (key === 'p_fees_comm') { - if (innerKey.includes(' ')) { // Check if the key has a space - const newKey = innerKey.replace(/ /g, '_').toUpperCase(); // Replace spaces and convert to uppercase - newObj[newKey] = obj[innerKey]; // Add the new key - delete newObj[innerKey]; // Remove the old key - } - } - } - return newObj; - }); - } - - return output; - - } catch (err) { - - return { error: err.message } - } finally { } + return output; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } - async GetCarnetSummaryData(p_emailaddr: string) { + async GetCarnetSummaryData(p_emailaddr: string) { + let connection; + let rows: any = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - let connection; - let rows: any = []; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN USERLOGIN_PKG.GetCarnetSummaryData(:p_emailaddr,:p_cursor); END;`, - { - p_emailaddr: { - val: p_emailaddr, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + p_emailaddr: { + val: p_emailaddr, + 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; - let rowsBatch; + 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); + 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'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } + rows = rows.map((obj) => { + // Create a new object to hold the modified keys + const newObj = {}; - rows = rows.map(obj => { - // Create a new object to hold the modified keys - let newObj = {}; + // Iterate over the keys of the current object + for (const key in obj) { + // Replace spaces with underscores in the key + const newKey = key.replace(/ /g, '_'); + newObj[newKey] = obj[key]; + } - // Iterate over the keys of the current object - for (let key in obj) { - // Replace spaces with underscores in the key - let newKey = key.replace(/ /g, "_"); - newObj[newKey] = obj[key]; - } + return newObj; + }); - return newObj; - }); + rows = rows.reduce((acc, curr) => { + // Find if the current item already exists in the accumulator + const existing = acc.find( + (item) => + item['Service_Provider_Name'] === curr['Service_Provider_Name'] && + item.SPID === curr.SPID, + ); - rows = rows.reduce((acc, curr) => { - // Find if the current item already exists in the accumulator - let existing = acc.find(item => item["Service_Provider_Name"] === curr["Service_Provider_Name"] && item.SPID === curr.SPID); + if (existing) { + // If it exists, push the current "cs" and "c c" values into the arrays + existing.CARNETSTATUS.push(curr.CARNETSTATUS); + existing['Carnet_Count'].push(curr['Carnet_Count']); + } else { + // If it doesn't exist, create a new entry + acc.push({ + Service_Provider_Name: curr['Service_Provider_Name'], + SPID: curr.SPID, + CARNETSTATUS: [curr.CARNETSTATUS], + Carnet_Count: [curr['Carnet_Count']], + }); + } - if (existing) { - // If it exists, push the current "cs" and "c c" values into the arrays - existing.CARNETSTATUS.push(curr.CARNETSTATUS); - existing["Carnet_Count"].push(curr["Carnet_Count"]); - } else { - // If it doesn't exist, create a new entry - acc.push({ - "Service_Provider_Name": curr["Service_Provider_Name"], - SPID: curr.SPID, - CARNETSTATUS: [curr.CARNETSTATUS], - "Carnet_Count": [curr["Carnet_Count"]] - }); - } + return acc; + }, []); - return acc; - }, []); + return rows; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } + } + } - return rows; + async SaveCarnetApplication(body: SaveCarnetApplicationDTO) { + const newBody = { + p_headerid: null, + p_holderid: null, + p_commercialsampleflag: null, + p_profequipmentflag: null, + p_exhibitionsfairflag: null, + p_autoflag: null, + p_horseflag: null, + p_authrep: null, + p_gltable: null, + p_ussets: null, + p_countrytable: null, + p_shiptotype: null, + p_shipaddrid: null, + p_formofsecurity: null, + p_insprotection: null, + p_ldiprotection: null, + p_deliverytype: null, + p_deliverymethod: null, + p_paymentmethod: null, + p_custcourierno: null, + p_refno: null, + p_notes: null, + }; - } catch (err) { - - return { error: err.message } - } finally { } + const reqBody = JSON.parse(JSON.stringify(body)); + function setEmptyStringsToNull(obj) { + Object.keys(obj).forEach((key) => { + if (typeof obj[key] === 'object' && obj[key] !== null) { + setEmptyStringsToNull(obj[key]); + } else if (obj[key] === '') { + obj[key] = null; + } + }); } - async SaveCarnetApplication(body: SaveCarnetApplicationDTO) { + setEmptyStringsToNull(reqBody); - let newBody = { - "p_headerid": null, - "p_holderid": null, - "p_commercialsampleflag": null, - "p_profequipmentflag": null, - "p_exhibitionsfairflag": null, - "p_autoflag": null, - "p_horseflag": null, - "p_authrep": null, - "p_gltable": null, - "p_ussets": null, - "p_countrytable": null, - "p_shiptotype": null, - "p_shipaddrid": null, - "p_formofsecurity": null, - "p_insprotection": null, - "p_ldiprotection": null, - "p_deliverytype": null, - "p_deliverymethod": null, - "p_paymentmethod": null, - "p_custcourierno": null, - "p_refno": null, - "p_notes": null - } + const finalBody = { ...newBody, ...reqBody }; - let reqBody = JSON.parse(JSON.stringify(body)); + let connection; + let rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - function setEmptyStringsToNull(obj) { - Object.keys(obj).forEach(key => { - if (typeof obj[key] === 'object' && obj[key] !== null) { - setEmptyStringsToNull(obj[key]); - } else if (obj[key] === "") { - obj[key] = null; - } - }); - } + console.log('here ------------ 1'); - setEmptyStringsToNull(reqBody); + // const res = await connection.execute(`SELECT CARNETSYS.GLARRAY(1, 'Description for itemno 1', 2500, 20, 12, 'LBS', 'US') FROM dual`); - const finalBody = { ...newBody, ...reqBody }; + async function createGLArrayInstance( + connection, + itemNo, + itemDescription, + itemValue, + noOfPieces, + itemWeight, + itemWeightUOM, + goodsOriginCountry, + ) { + const result = await connection.execute( + `SELECT CARNETSYS.GLARRAY(:itemNo, :itemDescription, :itemValue, :noOfPieces, :itemWeight, :itemWeightUOM, :goodsOriginCountry) FROM dual`, + { + itemNo, + itemDescription, + itemValue, + noOfPieces, + itemWeight, + itemWeightUOM, + goodsOriginCountry, + }, + ); + return result.rows[0][0]; // Access the first row and first column to get the GLARRAY instance + } - let connection; - let rows = []; - try { + async function createCarnetCountryArrayInstance( + connection, + visitTransitInd, + countryCode, + noOfTimesEntLeave, + ) { + const result = await connection.execute( + `SELECT CARNETSYS.CARNETCOUNTRYARRAY(:visitTransitInd, :countryCode, :noOfTimesEntLeave) FROM dual`, + { + visitTransitInd, + countryCode, + noOfTimesEntLeave, + }, + ); + return result.rows[0][0]; // Access the first row and first column to get the CARNETCOUNTRYARRAY instance + } - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } + // let res = await connection.execute(`SELECT owner, type_name FROM all_types WHERE type_name IN ('GLARRAY', 'GLTABLE')`) - console.log("here ------------ 1"); + // let GLARRAY = await connection.getDbObjectClass('CARNETSYS.GLARRAY'); + const GLTABLE = await connection.getDbObjectClass('CARNETSYS.GLTABLE'); + // const CARNETCOUNTRYARRAY = await connection.getDbObjectClass('CARNETSYS.CARNETCOUNTRYARRAY'); + const CARNETCOUNTRYTABLE = await connection.getDbObjectClass( + 'CARNETSYS.CARNETCOUNTRYTABLE', + ); - // const res = await connection.execute(`SELECT CARNETSYS.GLARRAY(1, 'Description for itemno 1', 2500, 20, 12, 'LBS', 'US') FROM dual`); + // Check if GLTABLE is a constructor + if (typeof GLTABLE !== 'function') { + throw new Error('GLTABLE is not a constructor'); + } - async function createGLArrayInstance(connection, itemNo, itemDescription, itemValue, noOfPieces, itemWeight, itemWeightUOM, goodsOriginCountry) { - const result = await connection.execute( - `SELECT CARNETSYS.GLARRAY(:itemNo, :itemDescription, :itemValue, :noOfPieces, :itemWeight, :itemWeightUOM, :goodsOriginCountry) FROM dual`, - { - itemNo, - itemDescription, - itemValue, - noOfPieces, - itemWeight, - itemWeightUOM, - goodsOriginCountry - } - ); - return result.rows[0][0]; // Access the first row and first column to get the GLARRAY instance - } + if (typeof CARNETCOUNTRYTABLE !== 'function') { + throw new Error('CARNETCOUNTRYTABLE is not a constructor'); + } - async function createCarnetCountryArrayInstance(connection, visitTransitInd, countryCode, noOfTimesEntLeave) { - const result = await connection.execute( - `SELECT CARNETSYS.CARNETCOUNTRYARRAY(:visitTransitInd, :countryCode, :noOfTimesEntLeave) FROM dual`, - { - visitTransitInd, - countryCode, - noOfTimesEntLeave - } - ); - return result.rows[0][0]; // Access the first row and first column to get the CARNETCOUNTRYARRAY instance - } + const GLTABLE_ARRAY = finalBody.p_gltable + ? await Promise.all( + finalBody.p_gltable.map(async (x: p_gltableDTO) => { + return await createGLArrayInstance( + connection, + x.ItemNo, + x.ItemDescription, + x.ItemValue, + x.Noofpieces, + x.ItemWeight, + x.ItemWeightUOM, + x.GoodsOriginCountry, + ); + }), + ) + : []; + const CARNETCOUNTRYTABLE_ARRAY = finalBody.p_countrytable + ? await Promise.all( + finalBody.p_countrytable.map(async (x) => { + return await createCarnetCountryArrayInstance( + connection, + x.VisitTransitInd, + x.CountryCode, + x.NoOfTimesEntLeave, + ); + }), + ) + : []; - // let res = await connection.execute(`SELECT owner, type_name FROM all_types WHERE type_name IN ('GLARRAY', 'GLTABLE')`) + const GLTABLE_INSTANCE = new GLTABLE(GLTABLE_ARRAY); + const CARNETCOUNTRYTABLE_INSTANCE = new CARNETCOUNTRYTABLE( + CARNETCOUNTRYTABLE_ARRAY, + ); - // let GLARRAY = await connection.getDbObjectClass('CARNETSYS.GLARRAY'); - const GLTABLE = await connection.getDbObjectClass('CARNETSYS.GLTABLE'); - // const CARNETCOUNTRYARRAY = await connection.getDbObjectClass('CARNETSYS.CARNETCOUNTRYARRAY'); - const CARNETCOUNTRYTABLE = await connection.getDbObjectClass('CARNETSYS.CARNETCOUNTRYTABLE'); - - // Check if GLTABLE is a constructor - if (typeof GLTABLE !== 'function') { - throw new Error('GLTABLE is not a constructor'); - } - - if (typeof CARNETCOUNTRYTABLE !== 'function') { - throw new Error('CARNETCOUNTRYTABLE is not a constructor'); - } - - const GLTABLE_ARRAY = finalBody.p_gltable ? await Promise.all(finalBody.p_gltable.map(async (x:p_gltableDTO) => { - return await createGLArrayInstance(connection, x.ItemNo, x.ItemDescription, x.ItemValue, x.Noofpieces, x.ItemWeight, x.ItemWeightUOM, x.GoodsOriginCountry); - })) : []; - - const CARNETCOUNTRYTABLE_ARRAY = finalBody.p_countrytable ? await Promise.all(finalBody.p_countrytable.map(async (x) => { - return await createCarnetCountryArrayInstance(connection, x.VisitTransitInd, x.CountryCode, x.NoOfTimesEntLeave); - })) : []; - - const GLTABLE_INSTANCE = new GLTABLE(GLTABLE_ARRAY); - const CARNETCOUNTRYTABLE_INSTANCE = new CARNETCOUNTRYTABLE(CARNETCOUNTRYTABLE_ARRAY); - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN CARNETAPPLICATION_PKG.SaveCarnetApplication( :p_spid, :p_clientid, @@ -529,162 +556,170 @@ export class HomePageService { :P_cursor ); END;`, - { - p_spid: { - val: finalBody.p_spid ? finalBody.p_spid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_clientid: { - val: finalBody.p_clientid ? finalBody.p_clientid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_locationid: { - val: finalBody.p_locationid ? finalBody.p_locationid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_userid: { - val: finalBody.p_userid ? finalBody.p_userid : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_headerid: { - val: finalBody.p_headerid ? finalBody.p_headerid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_applicationname: { - val: finalBody.p_applicationname ? finalBody.p_applicationname : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_holderid: { - val: finalBody.p_holderid ? finalBody.p_holderid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_commercialsampleflag: { - val: finalBody.p_commercialsampleflag ? finalBody.p_commercialsampleflag : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_profequipmentflag: { - val: finalBody.p_profequipmentflag ? finalBody.p_profequipmentflag : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_exhibitionsfairflag: { - val: finalBody.p_exhibitionsfairflag ? finalBody.p_exhibitionsfairflag : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_autoflag: { - val: finalBody.p_autoflag ? finalBody.p_autoflag : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_horseflag: { - val: finalBody.p_horseflag ? finalBody.p_horseflag : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_authrep: { - val: finalBody.p_authrep ? finalBody.p_authrep : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_gltable: { - val: GLTABLE_INSTANCE, - type: oracledb.DB_TYPE_OBJECT - }, - p_ussets: { - val: finalBody.p_ussets ? finalBody.p_ussets : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_countrytable: { - val: CARNETCOUNTRYTABLE_INSTANCE, - type: oracledb.DB_TYPE_OBJECT - }, - p_shiptotype: { - val: finalBody.p_shiptotype ? finalBody.p_shiptotype : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_shipaddrid: { - val: finalBody.p_shipaddrid ? finalBody.p_shipaddrid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_formofsecurity: { - val: finalBody.p_formofsecurity ? finalBody.p_formofsecurity : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_insprotection: { - val: finalBody.p_insprotection ? finalBody.p_insprotection : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_ldiprotection: { - val: finalBody.p_ldiprotection ? finalBody.p_ldiprotection : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_deliverytype: { - val: finalBody.p_deliverytype ? finalBody.p_deliverytype : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_deliverymethod: { - val: finalBody.p_deliverymethod ? finalBody.p_deliverymethod : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_paymentmethod: { - val: finalBody.p_paymentmethod ? finalBody.p_paymentmethod : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_custcourierno: { - val: finalBody.p_custcourierno ? finalBody.p_custcourierno : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_refno: { - val: finalBody.p_refno ? finalBody.p_refno : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_notes: { - val: finalBody.p_notes ? finalBody.p_notes : null, - type: oracledb.DB_TYPE_NVARCHAR - }, + { + p_spid: { + val: finalBody.p_spid ? finalBody.p_spid : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_clientid: { + val: finalBody.p_clientid ? finalBody.p_clientid : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_locationid: { + val: finalBody.p_locationid ? finalBody.p_locationid : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_userid: { + val: finalBody.p_userid ? finalBody.p_userid : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_headerid: { + val: finalBody.p_headerid ? finalBody.p_headerid : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_applicationname: { + val: finalBody.p_applicationname + ? finalBody.p_applicationname + : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_holderid: { + val: finalBody.p_holderid ? finalBody.p_holderid : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_commercialsampleflag: { + val: finalBody.p_commercialsampleflag + ? finalBody.p_commercialsampleflag + : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_profequipmentflag: { + val: finalBody.p_profequipmentflag + ? finalBody.p_profequipmentflag + : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_exhibitionsfairflag: { + val: finalBody.p_exhibitionsfairflag + ? finalBody.p_exhibitionsfairflag + : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_autoflag: { + val: finalBody.p_autoflag ? finalBody.p_autoflag : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_horseflag: { + val: finalBody.p_horseflag ? finalBody.p_horseflag : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_authrep: { + val: finalBody.p_authrep ? finalBody.p_authrep : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_gltable: { + val: GLTABLE_INSTANCE, + type: oracledb.DB_TYPE_OBJECT, + }, + p_ussets: { + val: finalBody.p_ussets ? finalBody.p_ussets : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_countrytable: { + val: CARNETCOUNTRYTABLE_INSTANCE, + type: oracledb.DB_TYPE_OBJECT, + }, + p_shiptotype: { + val: finalBody.p_shiptotype ? finalBody.p_shiptotype : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_shipaddrid: { + val: finalBody.p_shipaddrid ? finalBody.p_shipaddrid : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_formofsecurity: { + val: finalBody.p_formofsecurity ? finalBody.p_formofsecurity : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_insprotection: { + val: finalBody.p_insprotection ? finalBody.p_insprotection : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_ldiprotection: { + val: finalBody.p_ldiprotection ? finalBody.p_ldiprotection : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_deliverytype: { + val: finalBody.p_deliverytype ? finalBody.p_deliverytype : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_deliverymethod: { + val: finalBody.p_deliverymethod ? finalBody.p_deliverymethod : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_paymentmethod: { + val: finalBody.p_paymentmethod ? finalBody.p_paymentmethod : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_custcourierno: { + val: finalBody.p_custcourierno ? finalBody.p_custcourierno : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_refno: { + val: finalBody.p_refno ? finalBody.p_refno : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_notes: { + val: finalBody.p_notes ? finalBody.p_notes : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, - P_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); - await connection.commit(); + P_cursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + await connection.commit(); - if (result.outBinds && result.outBinds.P_cursor) { - const cursor = result.outBinds.P_cursor; - let rowsBatch; + 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); + 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'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } - - return rows; - - } catch (err) { - - return { error: err.message } - } finally { } + return rows; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } - async TransmitApplicationtoProcess(body: TransmitApplicationtoProcessDTO) { + async TransmitApplicationtoProcess(body: TransmitApplicationtoProcessDTO) { + let connection; + let rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - let connection; - let rows = []; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN CARNETAPPLICATION_PKG.TransmitApplicationtoProcess( :p_spid, :p_userid, @@ -692,113 +727,115 @@ export class HomePageService { :P_cursor ); END;`, - { - p_spid: { - val: body.p_spid, - type: oracledb.DB_TYPE_NUMBER - }, - p_userid: { - val: body.p_userid, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_headerid: { - val: body.p_headerid, - type: oracledb.DB_TYPE_NUMBER - }, - P_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); - await connection.commit(); + { + p_spid: { + val: body.p_spid, + type: oracledb.DB_TYPE_NUMBER, + }, + p_userid: { + val: body.p_userid, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_headerid: { + val: body.p_headerid, + type: oracledb.DB_TYPE_NUMBER, + }, + P_cursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + await connection.commit(); - if (result.outBinds && result.outBinds.P_cursor) { - const cursor = result.outBinds.P_cursor; - let rowsBatch; + 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); + 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'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } - - return rows; - - // return fres - - } catch (err) { - - return { error: err.message } - } finally { } - + return rows; + // return fres + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } - async GetCarnetDetailsbyCarnetStatus(body: GetCarnetDetailsbyCarnetStatusDTO) { - let connection; - let rows: any = []; - try { + async GetCarnetDetailsbyCarnetStatus( + body: GetCarnetDetailsbyCarnetStatusDTO, + ) { + let connection; + let rows: any = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN CARNETCONTROLCENTER_PKG.GetCarnetDetails(:p_spid,:p_userid,:p_CarnetStattus,:P_cursor); END;`, - { - p_spid: { - val: body.p_spid, - type: oracledb.DB_TYPE_NUMBER, - }, - p_userid: { - val: body.p_userid, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_CarnetStattus: { - val: body.p_CarnetStatus, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + p_spid: { + val: body.p_spid, + type: oracledb.DB_TYPE_NUMBER, + }, + p_userid: { + val: body.p_userid, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_CarnetStattus: { + val: body.p_CarnetStatus, + 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; - let rowsBatch; + 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); + 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'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } - - return rows; - - } catch (err) { - - return { error: err.message } - } finally { } + return rows; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } } diff --git a/src/oracle/manage-clients/manage-clients.controller.ts b/src/oracle/manage-clients/manage-clients.controller.ts index d1d3c7b..4319f89 100644 --- a/src/oracle/manage-clients/manage-clients.controller.ts +++ b/src/oracle/manage-clients/manage-clients.controller.ts @@ -1,70 +1,84 @@ import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common'; import { ManageClientsService } from './manage-clients.service'; -import { CreateAdditionalClientContactsDTO, CreateAdditionalClientLocationsDTO, CreateClientDataDTO, GetPreparerByClientidContactsByClientidLocByClientidDTO, GetPreparersDTO, UpdateClientContactsDTO, UpdateClientDTO, UpdateClientLocationsDTO } from './manage-clients.dto'; +import { + CreateAdditionalClientContactsDTO, + CreateAdditionalClientLocationsDTO, + CreateClientDataDTO, + GetPreparerByClientidContactsByClientidLocByClientidDTO, + GetPreparersDTO, + UpdateClientContactsDTO, + UpdateClientDTO, + UpdateClientLocationsDTO, +} from './manage-clients.dto'; import { ApiTags } from '@nestjs/swagger'; @Controller('oracle') export class ManageClientsController { + constructor(private readonly manageClientsService: ManageClientsService) {} - constructor(private readonly manageClientsService:ManageClientsService){} + @ApiTags('Manage Clients - Oracle') + @Post('CreateNewClients') + async CreateClientData(@Body() body: CreateClientDataDTO) { + return this.manageClientsService.CreateClientData(body); + } - @ApiTags('Manage Clients - Oracle') - @Post('CreateNewClients') - async CreateClientData(@Body() body:CreateClientDataDTO){ - return this.manageClientsService.CreateClientData(body); - } + @ApiTags('Manage Clients - Oracle') + @Put('UpdateClient') + async UpdateClient(@Body() body: UpdateClientDTO) { + return this.manageClientsService.UpdateClient(body); + } - @ApiTags('Manage Clients - Oracle') - @Put('UpdateClient') - async UpdateClient(@Body() body:UpdateClientDTO){ - return this.manageClientsService.UpdateClient(body); - } + @ApiTags('Manage Clients - Oracle') + @Put('UpdateClientContacts') + UpdateClientContacts(@Body() body: UpdateClientContactsDTO) { + return this.manageClientsService.UpdateClientContacts(body); + } - @ApiTags('Manage Clients - Oracle') - @Put('UpdateClientContacts') - UpdateClientContacts(@Body() body:UpdateClientContactsDTO){ - return this.manageClientsService.UpdateClientContacts(body); - } + @ApiTags('Manage Clients - Oracle') + @Put('UpdateClientLocations') + UpdateClientLocations(@Body() body: UpdateClientLocationsDTO) { + return this.manageClientsService.UpdateClientLocations(body); + } - @ApiTags('Manage Clients - Oracle') - @Put('UpdateClientLocations') - UpdateClientLocations(@Body() body:UpdateClientLocationsDTO){ - return this.manageClientsService.UpdateClientLocations(body); - } + @ApiTags('Manage Clients - Oracle') + @Post('CreateAdditionalClientContacts') + CreateClientContact(@Body() body: CreateAdditionalClientContactsDTO) { + return this.manageClientsService.CreateClientContact(body); + } - @ApiTags('Manage Clients - Oracle') - @Post('CreateAdditionalClientContacts') - CreateClientContact(@Body() body:CreateAdditionalClientContactsDTO){ - return this.manageClientsService.CreateClientContact(body); - } + @ApiTags('Manage Clients - Oracle') + @Post('CreateAdditionalClientLocations') + CreateClientLocation(@Body() body: CreateAdditionalClientLocationsDTO) { + return this.manageClientsService.CreateClientLocation(body); + } - @ApiTags('Manage Clients - Oracle') - @Post('CreateAdditionalClientLocations') - CreateClientLocation(@Body() body:CreateAdditionalClientLocationsDTO){ - return this.manageClientsService.CreateClientLocation(body); - } + @ApiTags('Manage Clients - Oracle') + @Get('GetPreparers') + async GetPreparers(@Query() query: GetPreparersDTO) { + return await this.manageClientsService.GetPreparers(query); + } - @ApiTags('Manage Clients - Oracle') - @Get('GetPreparers') - async GetPreparers(@Query() query:GetPreparersDTO) { - return await this.manageClientsService.GetPreparers(query) - } + @ApiTags('Manage Clients - Oracle') + @Get('GetPreparerByClientid') + GetPreparerByClientid( + @Query() body: GetPreparerByClientidContactsByClientidLocByClientidDTO, + ) { + return this.manageClientsService.GetPreparerByClientid(body); + } - @ApiTags('Manage Clients - Oracle') - @Get('GetPreparerByClientid') - GetPreparerByClientid(@Query() body:GetPreparerByClientidContactsByClientidLocByClientidDTO){ - return this.manageClientsService.GetPreparerByClientid(body); - } + @ApiTags('Manage Clients - Oracle') + @Get('GetPreparerContactsByClientid') + GetPreparerContactsByClientid( + @Query() body: GetPreparerByClientidContactsByClientidLocByClientidDTO, + ) { + return body; + } - @ApiTags('Manage Clients - Oracle') - @Get('GetPreparerContactsByClientid') - GetPreparerContactsByClientid(@Query() body:GetPreparerByClientidContactsByClientidLocByClientidDTO){ - return body; - } - - @ApiTags('Manage Clients - Oracle') - @Get('GetPreparerLocByClientid') - GetPreparerLocByClientid(@Query() body:GetPreparerByClientidContactsByClientidLocByClientidDTO){ - return body; - } + @ApiTags('Manage Clients - Oracle') + @Get('GetPreparerLocByClientid') + GetPreparerLocByClientid( + @Query() body: GetPreparerByClientidContactsByClientidLocByClientidDTO, + ) { + return body; + } } diff --git a/src/oracle/manage-clients/manage-clients.dto.ts b/src/oracle/manage-clients/manage-clients.dto.ts index 27d3279..b311148 100644 --- a/src/oracle/manage-clients/manage-clients.dto.ts +++ b/src/oracle/manage-clients/manage-clients.dto.ts @@ -1,489 +1,613 @@ import { ApiProperty } from '@nestjs/swagger'; -import { IsDefined, IsInt, IsNumber, IsOptional, IsString, Length, Max, Min, ValidateNested, IsArray, IsEmail } from 'class-validator'; +import { + IsDefined, + IsInt, + IsNumber, + IsOptional, + IsString, + Length, + Max, + Min, + ValidateNested, + IsArray, + IsEmail, +} from 'class-validator'; import { Transform, Type } from 'class-transformer'; import { p_contactstableDTO } from '../manage-holders/manage-holders.dto'; - export class p_clientlocaddresstableDTO { - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property Nameof must be between 0 to 50 characters" }) - @IsString({ message: "Property Nameof must be a string" }) - @IsDefined({ message: "Property Nameof is required" }) - Nameof: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property Nameof must be between 0 to 50 characters', + }) + @IsString({ message: 'Property Nameof must be a string' }) + @IsDefined({ message: 'Property Nameof is required' }) + Nameof: string; - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property Address1 must be between 0 to 50 characters" }) - @IsString({ message: "Property Address1 must be a string" }) - @IsDefined({ message: "Property Address1 is required" }) - Address1: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property Address1 must be between 0 to 50 characters', + }) + @IsString({ message: 'Property Address1 must be a string' }) + @IsDefined({ message: 'Property Address1 is required' }) + Address1: string; - @ApiProperty({ required: false }) - @Length(0, 50, { message: "Property Address2 must be between 0 to 50 characters" }) - @IsString({ message: "Property Address2 must be a string" }) - @IsOptional() - Address2?: string; + @ApiProperty({ required: false }) + @Length(0, 50, { + message: 'Property Address2 must be between 0 to 50 characters', + }) + @IsString({ message: 'Property Address2 must be a string' }) + @IsOptional() + Address2?: string; - @ApiProperty({ required: true }) - @Length(0, 30, { message: "Property City must be between 0 to 30 characters" }) - @IsString({ message: "Property City must be a string" }) - @IsDefined({ message: "Property City is required" }) - City: string; + @ApiProperty({ required: true }) + @Length(0, 30, { + message: 'Property City must be between 0 to 30 characters', + }) + @IsString({ message: 'Property City must be a string' }) + @IsDefined({ message: 'Property City is required' }) + City: string; - @ApiProperty({ required: true }) - @Length(0, 2, { message: "Property State must be between 0 to 2 characters" }) - @IsString({ message: "Property State must be a string" }) - @IsDefined({ message: "Property State is required" }) - State: string; + @ApiProperty({ required: true }) + @Length(0, 2, { message: 'Property State must be between 0 to 2 characters' }) + @IsString({ message: 'Property State must be a string' }) + @IsDefined({ message: 'Property State is required' }) + State: string; - @ApiProperty({ required: true }) - @Length(0, 10, { message: "Property Zip must be between 0 to 10 characters" }) - @IsString({ message: "Property Zip must be a string" }) - @IsDefined({ message: "Property Zip is required" }) - Zip: string; + @ApiProperty({ required: true }) + @Length(0, 10, { message: 'Property Zip must be between 0 to 10 characters' }) + @IsString({ message: 'Property Zip must be a string' }) + @IsDefined({ message: 'Property Zip is required' }) + Zip: string; - @ApiProperty({ required: true }) - @Length(0, 2, { message: "Property Country must be between 0 to 2 characters" }) - @IsString({ message: "Property Country must be a string" }) - @IsDefined({ message: "Property Country is required" }) - Country: string; + @ApiProperty({ required: true }) + @Length(0, 2, { + message: 'Property Country must be between 0 to 2 characters', + }) + @IsString({ message: 'Property Country must be a string' }) + @IsDefined({ message: 'Property Country is required' }) + Country: string; } export class CreateClientDataDTO { - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_spid must not exceed 999999999" }) - @Min(0, { message: "Property p_spid must be at least 0 or more" }) - @IsInt({ message: "Property p_spid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_spid must be a number" }) - @IsDefined({ message: "Property p_spid is required" }) - p_spid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) + @Min(0, { message: 'Property p_spid must be at least 0 or more' }) + @IsInt({ message: 'Property p_spid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_spid must be a number' }) + @IsDefined({ message: 'Property p_spid is required' }) + p_spid: number; - @ApiProperty({ required: true }) - // @Max(999999999, { message: "Property p_clientname must not exceed 999999999" }) - // @Min(0, { message: "Property p_clientname must be at least 0 or more" }) - // @IsInt({ message: "Property p_clientname allows only whole numbers" }) - // @IsNumber({}, { message: "Property p_clientname must be a number" }) - // @IsDefined({ message: "Property p_clientname is required" }) - @Length(0, 50, { message: "Property p_clientname must be between 0 to 50 characters" }) - @IsString({ message: "Property p_clientname must be a string" }) - @IsDefined({ message: "Property p_clientname is required" }) - p_clientname: string; + @ApiProperty({ required: true }) + // @Max(999999999, { message: "Property p_clientname must not exceed 999999999" }) + // @Min(0, { message: "Property p_clientname must be at least 0 or more" }) + // @IsInt({ message: "Property p_clientname allows only whole numbers" }) + // @IsNumber({}, { message: "Property p_clientname must be a number" }) + // @IsDefined({ message: "Property p_clientname is required" }) + @Length(0, 50, { + message: 'Property p_clientname must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_clientname must be a string' }) + @IsDefined({ message: 'Property p_clientname is required' }) + p_clientname: string; - @ApiProperty({ required: true }) - @Length(0, 20, { message: "Property p_lookupcode must be between 0 to 20 characters" }) - @IsString({ message: "Property p_lookupcode must be a string" }) - @IsDefined({ message: "Property p_lookupcode is required" }) - p_lookupcode: string; + @ApiProperty({ required: true }) + @Length(0, 20, { + message: 'Property p_lookupcode must be between 0 to 20 characters', + }) + @IsString({ message: 'Property p_lookupcode must be a string' }) + @IsDefined({ message: 'Property p_lookupcode is required' }) + p_lookupcode: string; - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property p_address1 must be between 0 to 50 characters" }) - @IsString({ message: "Property p_address1 must be a string" }) - @IsDefined({ message: "Property p_address1 is required" }) - p_address1: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property p_address1 must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_address1 must be a string' }) + @IsDefined({ message: 'Property p_address1 is required' }) + p_address1: string; - @ApiProperty({ required: false }) - @Length(0, 50, { message: "Property p_address2 must be between 0 to 50 characters" }) - @IsString({ message: "Property p_address2 must be a string" }) - @IsOptional() - p_address2?: string; + @ApiProperty({ required: false }) + @Length(0, 50, { + message: 'Property p_address2 must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_address2 must be a string' }) + @IsOptional() + p_address2?: string; - @ApiProperty({ required: true }) - @Length(0, 30, { message: "Property p_city must be between 0 to 30 characters" }) - @IsString({ message: "Property p_city must be a string" }) - @IsDefined({ message: "Property p_city is required" }) - p_city: string; + @ApiProperty({ required: true }) + @Length(0, 30, { + message: 'Property p_city must be between 0 to 30 characters', + }) + @IsString({ message: 'Property p_city must be a string' }) + @IsDefined({ message: 'Property p_city is required' }) + p_city: string; - @ApiProperty({ required: true }) - @Length(0, 2, { message: "Property p_state must be between 0 to 2 characters" }) - @IsString({ message: "Property p_state must be a string" }) - @IsDefined({ message: "Property p_state is required" }) - p_state: string; + @ApiProperty({ required: true }) + @Length(0, 2, { + message: 'Property p_state must be between 0 to 2 characters', + }) + @IsString({ message: 'Property p_state must be a string' }) + @IsDefined({ message: 'Property p_state is required' }) + p_state: string; - @ApiProperty({ required: false }) - @Length(0, 10, { message: "Property p_zip must be between 0 to 10 characters" }) - @IsString({ message: "Property p_zip must be a string" }) - @IsOptional() - p_zip?: string; + @ApiProperty({ required: false }) + @Length(0, 10, { + message: 'Property p_zip must be between 0 to 10 characters', + }) + @IsString({ message: 'Property p_zip must be a string' }) + @IsOptional() + p_zip?: string; - @ApiProperty({ required: false }) - @Length(0, 2, { message: "Property p_country must be between 0 to 2 characters" }) - @IsString({ message: "Property p_country must be a string" }) - @IsOptional() - p_country?: string; + @ApiProperty({ required: false }) + @Length(0, 2, { + message: 'Property p_country must be between 0 to 2 characters', + }) + @IsString({ message: 'Property p_country must be a string' }) + @IsOptional() + p_country?: string; - @ApiProperty({ required: true }) - @Length(0, 2, { message: "Property p_issuingregion must be between 0 to 2 characters" }) - @IsString({ message: "Property p_issuingregion must be a string" }) - @IsDefined({ message: "Property p_issuingregion is required" }) - p_issuingregion: string; + @ApiProperty({ required: true }) + @Length(0, 2, { + message: 'Property p_issuingregion must be between 0 to 2 characters', + }) + @IsString({ message: 'Property p_issuingregion must be a string' }) + @IsDefined({ message: 'Property p_issuingregion is required' }) + p_issuingregion: string; - @ApiProperty({ required: true }) - @Length(0, 2, { message: "Property p_revenuelocation must be between 0 to 2 characters" }) - @IsString({ message: "Property p_revenuelocation must be a string" }) - @IsDefined({ message: "Property p_revenuelocation is required" }) - p_revenuelocation: string; + @ApiProperty({ required: true }) + @Length(0, 2, { + message: 'Property p_revenuelocation must be between 0 to 2 characters', + }) + @IsString({ message: 'Property p_revenuelocation must be a string' }) + @IsDefined({ message: 'Property p_revenuelocation is required' }) + p_revenuelocation: string; - @ApiProperty({ required: true }) - @Length(0, 100, { message: "Property p_userid must be between 0 to 100 characters" }) - @IsString({ message: "Property p_userid must be a string" }) - @IsDefined({ message: "Property p_userid is required" }) - p_userid: string; + @ApiProperty({ required: true }) + @Length(0, 100, { + message: 'Property p_userid must be between 0 to 100 characters', + }) + @IsString({ message: 'Property p_userid must be a string' }) + @IsDefined({ message: 'Property p_userid is required' }) + p_userid: string; - @ApiProperty({ required: true, type: () => [p_contactstableDTO] }) - @Type(() => p_contactstableDTO) - @ValidateNested({ each: true }) - @IsArray({ message: "Property p_contactstable allows only array type" }) - @IsDefined({ message: "Property p_contactstable is required" }) - p_contactstable: p_contactstableDTO[]; + @ApiProperty({ required: true, type: () => [p_contactstableDTO] }) + @Type(() => p_contactstableDTO) + @ValidateNested({ each: true }) + @IsArray({ message: 'Property p_contactstable allows only array type' }) + @IsDefined({ message: 'Property p_contactstable is required' }) + p_contactstable: p_contactstableDTO[]; - @ApiProperty({ required: true, type: () => [p_clientlocaddresstableDTO] }) - @Type(() => p_clientlocaddresstableDTO) - @ValidateNested({ each: true }) - @IsArray({ message: "Property p_clientlocaddresstable allows only array type" }) - @IsDefined({ message: "Property p_clientlocaddresstable is required" }) - p_clientlocaddresstable: p_clientlocaddresstableDTO[]; + @ApiProperty({ required: true, type: () => [p_clientlocaddresstableDTO] }) + @Type(() => p_clientlocaddresstableDTO) + @ValidateNested({ each: true }) + @IsArray({ + message: 'Property p_clientlocaddresstable allows only array type', + }) + @IsDefined({ message: 'Property p_clientlocaddresstable is required' }) + p_clientlocaddresstable: p_clientlocaddresstableDTO[]; } export class UpdateClientDTO { - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_spid must not exceed 999999999" }) - @Min(0, { message: "Property p_spid must be at least 0 or more" }) - @IsInt({ message: "Property p_spid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_spid must be a number" }) - @IsDefined({ message: "Property p_spid is required" }) - p_spid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) + @Min(0, { message: 'Property p_spid must be at least 0 or more' }) + @IsInt({ message: 'Property p_spid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_spid must be a number' }) + @IsDefined({ message: 'Property p_spid is required' }) + p_spid: number; - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_clientid must not exceed 999999999" }) - @Min(0, { message: "Property p_clientid must be at least 0 or more" }) - @IsInt({ message: "Property p_clientid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_clientid must be a number" }) - @IsDefined({ message: "Property p_clientid is required" }) - p_clientid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_clientid must not exceed 999999999' }) + @Min(0, { message: 'Property p_clientid must be at least 0 or more' }) + @IsInt({ message: 'Property p_clientid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_clientid must be a number' }) + @IsDefined({ message: 'Property p_clientid is required' }) + p_clientid: number; - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property p_preparername must be between 0 to 50 characters" }) - @IsString({ message: "Property p_preparername must be a string" }) - @IsDefined({ message: "Property p_preparername is required" }) - p_preparername: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property p_preparername must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_preparername must be a string' }) + @IsDefined({ message: 'Property p_preparername is required' }) + p_preparername: string; - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property p_address1 must be between 0 to 50 characters" }) - @IsString({ message: "Property p_address1 must be a string" }) - @IsDefined({ message: "Property p_address1 is required" }) - p_address1: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property p_address1 must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_address1 must be a string' }) + @IsDefined({ message: 'Property p_address1 is required' }) + p_address1: string; - @ApiProperty({ required: false }) - @Length(0, 50, { message: "Property p_address2 must be between 0 to 50 characters" }) - @IsString({ message: "Property p_address2 must be a string" }) - @IsOptional() - p_address2?: string; + @ApiProperty({ required: false }) + @Length(0, 50, { + message: 'Property p_address2 must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_address2 must be a string' }) + @IsOptional() + p_address2?: string; - @ApiProperty({ required: true }) - @Length(0, 30, { message: "Property p_city must be between 0 to 30 characters" }) - @IsString({ message: "Property p_city must be a string" }) - @IsDefined({ message: "Property p_city is required" }) - p_city: string; + @ApiProperty({ required: true }) + @Length(0, 30, { + message: 'Property p_city must be between 0 to 30 characters', + }) + @IsString({ message: 'Property p_city must be a string' }) + @IsDefined({ message: 'Property p_city is required' }) + p_city: string; - @ApiProperty({ required: true }) - @Length(0, 2, { message: "Property p_state must be between 0 to 2 characters" }) - @IsString({ message: "Property p_state must be a string" }) - @IsDefined({ message: "Property p_state is required" }) - p_state: string; + @ApiProperty({ required: true }) + @Length(0, 2, { + message: 'Property p_state must be between 0 to 2 characters', + }) + @IsString({ message: 'Property p_state must be a string' }) + @IsDefined({ message: 'Property p_state is required' }) + p_state: string; - @ApiProperty({ required: true }) - @Length(0, 10, { message: "Property p_zip must be between 0 to 10 characters" }) - @IsString({ message: "Property p_zip must be a string" }) - @IsDefined({ message: "Property p_zip is required" }) - p_zip: string; + @ApiProperty({ required: true }) + @Length(0, 10, { + message: 'Property p_zip must be between 0 to 10 characters', + }) + @IsString({ message: 'Property p_zip must be a string' }) + @IsDefined({ message: 'Property p_zip is required' }) + p_zip: string; - @ApiProperty({ required: true }) - @Length(0, 2, { message: "Property p_country must be between 0 to 2 characters" }) - @IsString({ message: "Property p_country must be a string" }) - @IsDefined({ message: "Property p_country is required" }) - p_country: string; + @ApiProperty({ required: true }) + @Length(0, 2, { + message: 'Property p_country must be between 0 to 2 characters', + }) + @IsString({ message: 'Property p_country must be a string' }) + @IsDefined({ message: 'Property p_country is required' }) + p_country: string; - @ApiProperty({ required: true }) - @Length(0, 2, { message: "Property p_revenuelocation must be between 0 to 2 characters" }) - @IsString({ message: "Property p_revenuelocation must be a string" }) - @IsDefined({ message: "Property p_revenuelocation is required" }) - p_revenuelocation: string; + @ApiProperty({ required: true }) + @Length(0, 2, { + message: 'Property p_revenuelocation must be between 0 to 2 characters', + }) + @IsString({ message: 'Property p_revenuelocation must be a string' }) + @IsDefined({ message: 'Property p_revenuelocation is required' }) + p_revenuelocation: string; - @ApiProperty({ required: true }) - @Length(0, 100, { message: "Property p_userid must be between 0 to 100 characters" }) - @IsString({ message: "Property p_userid must be a string" }) - @IsDefined({ message: "Property p_userid is required" }) - p_userid: string; + @ApiProperty({ required: true }) + @Length(0, 100, { + message: 'Property p_userid must be between 0 to 100 characters', + }) + @IsString({ message: 'Property p_userid must be a string' }) + @IsDefined({ message: 'Property p_userid is required' }) + p_userid: string; } export class UpdateClientContactsDTO { - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_spid must not exceed 999999999" }) - @Min(0, { message: "Property p_spid must be at least 0 or more" }) - @IsInt({ message: "Property p_spid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_spid must be a number" }) - @IsDefined({ message: "Property p_spid is required" }) - p_spid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) + @Min(0, { message: 'Property p_spid must be at least 0 or more' }) + @IsInt({ message: 'Property p_spid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_spid must be a number' }) + @IsDefined({ message: 'Property p_spid is required' }) + p_spid: number; - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_clientcontactid must not exceed 999999999" }) - @Min(0, { message: "Property p_clientcontactid must be at least 0 or more" }) - @IsInt({ message: "Property p_clientcontactid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_clientcontactid must be a number" }) - @IsDefined({ message: "Property p_clientcontactid is required" }) - p_clientcontactid: number; + @ApiProperty({ required: true }) + @Max(999999999, { + message: 'Property p_clientcontactid must not exceed 999999999', + }) + @Min(0, { message: 'Property p_clientcontactid must be at least 0 or more' }) + @IsInt({ message: 'Property p_clientcontactid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_clientcontactid must be a number' }) + @IsDefined({ message: 'Property p_clientcontactid is required' }) + p_clientcontactid: number; - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property p_firstname must be between 0 to 50 characters" }) - @IsString({ message: "Property p_firstname must be a string" }) - @IsDefined({ message: "Property p_firstname is required" }) - p_firstname: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property p_firstname must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_firstname must be a string' }) + @IsDefined({ message: 'Property p_firstname is required' }) + p_firstname: string; - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property p_lastname must be between 0 to 50 characters" }) - @IsString({ message: "Property p_lastname must be a string" }) - @IsDefined({ message: "Property p_lastname is required" }) - p_lastname: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property p_lastname must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_lastname must be a string' }) + @IsDefined({ message: 'Property p_lastname is required' }) + p_lastname: string; - @ApiProperty({ required: false }) - @Length(0, 3, { message: "Property p_middleinitial must be between 0 to 3 characters" }) - @IsString({ message: "Property p_middleinitial must be a string" }) - @IsOptional() - p_middleinitial?: string; + @ApiProperty({ required: false }) + @Length(0, 3, { + message: 'Property p_middleinitial must be between 0 to 3 characters', + }) + @IsString({ message: 'Property p_middleinitial must be a string' }) + @IsOptional() + p_middleinitial?: string; - @ApiProperty({ required: false }) - @Length(0, 50, { message: "Property p_title must be between 0 to 50 characters" }) - @IsString({ message: "Property p_title must be a string" }) - @IsOptional() - p_title?: string; + @ApiProperty({ required: false }) + @Length(0, 50, { + message: 'Property p_title must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_title must be a string' }) + @IsOptional() + p_title?: string; - @ApiProperty({ required: true }) - @Length(0, 20, { message: "Property p_phone must be between 0 to 20 characters" }) - @IsString({ message: "Property p_phone must be a string" }) - @IsDefined({ message: "Property p_phone is required" }) - p_phone: string; + @ApiProperty({ required: true }) + @Length(0, 20, { + message: 'Property p_phone must be between 0 to 20 characters', + }) + @IsString({ message: 'Property p_phone must be a string' }) + @IsDefined({ message: 'Property p_phone is required' }) + p_phone: string; - @ApiProperty({ required: true }) - @Length(0, 20, { message: "Property p_fax must be between 0 to 20 characters" }) - @IsString({ message: "Property p_fax must be a string" }) - @IsDefined({ message: "Property p_fax is required" }) - p_fax: string; + @ApiProperty({ required: true }) + @Length(0, 20, { + message: 'Property p_fax must be between 0 to 20 characters', + }) + @IsString({ message: 'Property p_fax must be a string' }) + @IsDefined({ message: 'Property p_fax is required' }) + p_fax: string; - @ApiProperty({ required: false }) - @Length(0, 20, { message: "Property p_mobileno must be between 0 to 20 characters" }) - @IsString({ message: "Property p_mobileno must be a string" }) - @IsOptional() - p_mobileno?: string; + @ApiProperty({ required: false }) + @Length(0, 20, { + message: 'Property p_mobileno must be between 0 to 20 characters', + }) + @IsString({ message: 'Property p_mobileno must be a string' }) + @IsOptional() + p_mobileno?: string; - @ApiProperty({ required: true }) - @Length(0, 100, { message: "Property p_emailaddress must be between 0 to 100 characters" }) - @IsEmail({}, { message: "Property p_emailaddress must be a valid email address" }) - @IsDefined({ message: "Property p_emailaddress is required" }) - p_emailaddress: string; + @ApiProperty({ required: true }) + @Length(0, 100, { + message: 'Property p_emailaddress must be between 0 to 100 characters', + }) + @IsEmail( + {}, + { message: 'Property p_emailaddress must be a valid email address' }, + ) + @IsDefined({ message: 'Property p_emailaddress is required' }) + p_emailaddress: string; - @ApiProperty({ required: true }) - @Length(0, 100, { message: "Property p_userid must be between 0 to 100 characters" }) - @IsString({ message: "Property p_userid must be a string" }) - @IsDefined({ message: "Property p_userid is required" }) - p_userid: string; + @ApiProperty({ required: true }) + @Length(0, 100, { + message: 'Property p_userid must be between 0 to 100 characters', + }) + @IsString({ message: 'Property p_userid must be a string' }) + @IsDefined({ message: 'Property p_userid is required' }) + p_userid: string; } export class GetPreparersDTO { - @ApiProperty({ required: true }) - @Transform(({ value }) => Number(value)) - @Max(999999999, { message: "Property p_spid must not exceed 999999999" }) - @Min(0, { message: "Property p_spid must be at least 0 or more" }) - @IsInt({ message: "Property p_spid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_spid must be a number" }) - @IsDefined({ message: "Property p_spid is required" }) - p_spid: number; + @ApiProperty({ required: true }) + @Transform(({ value }) => Number(value)) + @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) + @Min(0, { message: 'Property p_spid must be at least 0 or more' }) + @IsInt({ message: 'Property p_spid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_spid must be a number' }) + @IsDefined({ message: 'Property p_spid is required' }) + p_spid: number; - @ApiProperty({ required: false }) - @Length(0, 50, { message: "Property p_name must be between 0 to 50 characters" }) - @IsString({ message: "Property p_name must be a string" }) - @IsOptional() - p_name?: string; + @ApiProperty({ required: false }) + @Length(0, 50, { + message: 'Property p_name must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_name must be a string' }) + @IsOptional() + p_name?: string; - @ApiProperty({ required: false }) - @Length(0, 30, { message: "Property p_lookupcode must be between 0 to 30 characters" }) - @IsString({ message: "Property p_lookupcode must be a string" }) - @IsOptional() - p_lookupcode?: string; + @ApiProperty({ required: false }) + @Length(0, 30, { + message: 'Property p_lookupcode must be between 0 to 30 characters', + }) + @IsString({ message: 'Property p_lookupcode must be a string' }) + @IsOptional() + p_lookupcode?: string; - @ApiProperty({ required: false }) - @Length(0, 20, { message: "Property p_city must be between 0 to 20 characters" }) - @IsString({ message: "Property p_city must be a string" }) - @IsOptional() - p_city?: string; + @ApiProperty({ required: false }) + @Length(0, 20, { + message: 'Property p_city must be between 0 to 20 characters', + }) + @IsString({ message: 'Property p_city must be a string' }) + @IsOptional() + p_city?: string; - @ApiProperty({ required: false }) - @Length(0, 2, { message: "Property p_state must be between 0 to 2 characters" }) - @IsString({ message: "Property p_state must be a string" }) - @IsOptional() - p_state?: string; + @ApiProperty({ required: false }) + @Length(0, 2, { + message: 'Property p_state must be between 0 to 2 characters', + }) + @IsString({ message: 'Property p_state must be a string' }) + @IsOptional() + p_state?: string; - @ApiProperty({ required: true }) - @Length(0, 10, { message: "Property p_status must be between 0 to 10 characters" }) - @IsString({ message: "Property p_status must be a string" }) - @IsDefined({ message: "Property p_status is required" }) - p_status: string; + @ApiProperty({ required: true }) + @Length(0, 10, { + message: 'Property p_status must be between 0 to 10 characters', + }) + @IsString({ message: 'Property p_status must be a string' }) + @IsDefined({ message: 'Property p_status is required' }) + p_status: string; } export class UpdateClientLocationsDTO { - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_spid must not exceed 999999999" }) - @Min(0, { message: "Property p_spid must be at least 0 or more" }) - @IsInt({ message: "Property p_spid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_spid must be a number" }) - @IsDefined({ message: "Property p_spid is required" }) - p_spid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) + @Min(0, { message: 'Property p_spid must be at least 0 or more' }) + @IsInt({ message: 'Property p_spid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_spid must be a number' }) + @IsDefined({ message: 'Property p_spid is required' }) + p_spid: number; - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_clientlocationid must not exceed 999999999" }) - @Min(0, { message: "Property p_clientlocationid must be at least 0 or more" }) - @IsInt({ message: "Property p_clientlocationid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_clientlocationid must be a number" }) - @IsDefined({ message: "Property p_clientlocationid is required" }) - p_clientlocationid: number; + @ApiProperty({ required: true }) + @Max(999999999, { + message: 'Property p_clientlocationid must not exceed 999999999', + }) + @Min(0, { message: 'Property p_clientlocationid must be at least 0 or more' }) + @IsInt({ message: 'Property p_clientlocationid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_clientlocationid must be a number' }) + @IsDefined({ message: 'Property p_clientlocationid is required' }) + p_clientlocationid: number; - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property p_lcoationname must be between 0 to 50 characters" }) - @IsString({ message: "Property p_lcoationname must be a string" }) - @IsDefined({ message: "Property p_lcoationname is required" }) - p_lcoationname: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property p_lcoationname must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_lcoationname must be a string' }) + @IsDefined({ message: 'Property p_lcoationname is required' }) + p_lcoationname: string; - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property p_address1 must be between 0 to 50 characters" }) - @IsString({ message: "Property p_address1 must be a string" }) - @IsDefined({ message: "Property p_address1 is required" }) - p_address1: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property p_address1 must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_address1 must be a string' }) + @IsDefined({ message: 'Property p_address1 is required' }) + p_address1: string; - @ApiProperty({ required: false }) - @Length(0, 50, { message: "Property p_address2 must be between 0 to 50 characters" }) - @IsString({ message: "Property p_address2 must be a string" }) - @IsOptional() - p_address2?: string; + @ApiProperty({ required: false }) + @Length(0, 50, { + message: 'Property p_address2 must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_address2 must be a string' }) + @IsOptional() + p_address2?: string; - @ApiProperty({ required: false }) - @Length(0, 30, { message: "Property p_city must be between 0 to 30 characters" }) - @IsString({ message: "Property p_city must be a string" }) - @IsOptional() - p_city?: string; + @ApiProperty({ required: false }) + @Length(0, 30, { + message: 'Property p_city must be between 0 to 30 characters', + }) + @IsString({ message: 'Property p_city must be a string' }) + @IsOptional() + p_city?: string; - @ApiProperty({ required: true }) - @Length(0, 2, { message: "Property p_state must be between 0 to 2 characters" }) - @IsString({ message: "Property p_state must be a string" }) - @IsDefined({ message: "Property p_state is required" }) - p_state: string; + @ApiProperty({ required: true }) + @Length(0, 2, { + message: 'Property p_state must be between 0 to 2 characters', + }) + @IsString({ message: 'Property p_state must be a string' }) + @IsDefined({ message: 'Property p_state is required' }) + p_state: string; - @ApiProperty({ required: true }) - @Length(0, 10, { message: "Property p_zip must be between 0 to 10 characters" }) - @IsString({ message: "Property p_zip must be a string" }) - @IsDefined({ message: "Property p_zip is required" }) - p_zip: string; + @ApiProperty({ required: true }) + @Length(0, 10, { + message: 'Property p_zip must be between 0 to 10 characters', + }) + @IsString({ message: 'Property p_zip must be a string' }) + @IsDefined({ message: 'Property p_zip is required' }) + p_zip: string; - @ApiProperty({ required: true }) - @Length(0, 2, { message: "Property p_country must be between 0 to 2 characters" }) - @IsString({ message: "Property p_country must be a string" }) - @IsDefined({ message: "Property p_country is required" }) - p_country: string; + @ApiProperty({ required: true }) + @Length(0, 2, { + message: 'Property p_country must be between 0 to 2 characters', + }) + @IsString({ message: 'Property p_country must be a string' }) + @IsDefined({ message: 'Property p_country is required' }) + p_country: string; - @ApiProperty({ required: true }) - @Length(0, 100, { message: "Property p_userid must be between 0 to 100 characters" }) - @IsString({ message: "Property p_userid must be a string" }) - @IsDefined({ message: "Property p_userid is required" }) - p_userid: string; + @ApiProperty({ required: true }) + @Length(0, 100, { + message: 'Property p_userid must be between 0 to 100 characters', + }) + @IsString({ message: 'Property p_userid must be a string' }) + @IsDefined({ message: 'Property p_userid is required' }) + p_userid: string; } export class CreateAdditionalClientContactsDTO { - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_spid must not exceed 999999999" }) - @Min(0, { message: "Property p_spid must be at least 0 or more" }) - @IsInt({ message: "Property p_spid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_spid must be a number" }) - @IsDefined({ message: "Property p_spid is required" }) - p_spid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) + @Min(0, { message: 'Property p_spid must be at least 0 or more' }) + @IsInt({ message: 'Property p_spid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_spid must be a number' }) + @IsDefined({ message: 'Property p_spid is required' }) + p_spid: number; - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_clientid must not exceed 999999999" }) - @Min(0, { message: "Property p_clientid must be at least 0 or more" }) - @IsInt({ message: "Property p_clientid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_clientid must be a number" }) - @IsDefined({ message: "Property p_clientid is required" }) - p_clientid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_clientid must not exceed 999999999' }) + @Min(0, { message: 'Property p_clientid must be at least 0 or more' }) + @IsInt({ message: 'Property p_clientid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_clientid must be a number' }) + @IsDefined({ message: 'Property p_clientid is required' }) + p_clientid: number; - @ApiProperty({ required: true, type: () => [p_contactstableDTO] }) - @Type(() => p_contactstableDTO) - @ValidateNested({ each: true }) - @IsArray({ message: "Property p_contactstable allows only array type" }) - @IsDefined({ message: "Property p_contactstable is required" }) - p_contactstable: p_contactstableDTO[]; + @ApiProperty({ required: true, type: () => [p_contactstableDTO] }) + @Type(() => p_contactstableDTO) + @ValidateNested({ each: true }) + @IsArray({ message: 'Property p_contactstable allows only array type' }) + @IsDefined({ message: 'Property p_contactstable is required' }) + p_contactstable: p_contactstableDTO[]; - @ApiProperty({ required: true }) - @Length(0, 1, { message: "Property p_defcontactflag must be exactly 1 character" }) - @IsString({ message: "Property p_defcontactflag must be a string" }) - @IsDefined({ message: "Property p_defcontactflag is required" }) - p_defcontactflag: string; + @ApiProperty({ required: true }) + @Length(0, 1, { + message: 'Property p_defcontactflag must be exactly 1 character', + }) + @IsString({ message: 'Property p_defcontactflag must be a string' }) + @IsDefined({ message: 'Property p_defcontactflag is required' }) + p_defcontactflag: string; - @ApiProperty({ required: true }) - @Length(0, 100, { message: "Property p_userid must be between 0 to 100 characters" }) - @IsString({ message: "Property p_userid must be a string" }) - @IsDefined({ message: "Property p_userid is required" }) - p_userid: string; + @ApiProperty({ required: true }) + @Length(0, 100, { + message: 'Property p_userid must be between 0 to 100 characters', + }) + @IsString({ message: 'Property p_userid must be a string' }) + @IsDefined({ message: 'Property p_userid is required' }) + p_userid: string; } export class CreateAdditionalClientLocationsDTO { - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_spid must not exceed 999999999" }) - @Min(0, { message: "Property p_spid must be at least 0 or more" }) - @IsInt({ message: "Property p_spid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_spid must be a number" }) - @IsDefined({ message: "Property p_spid is required" }) - p_spid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) + @Min(0, { message: 'Property p_spid must be at least 0 or more' }) + @IsInt({ message: 'Property p_spid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_spid must be a number' }) + @IsDefined({ message: 'Property p_spid is required' }) + p_spid: number; - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_clientid must not exceed 999999999" }) - @Min(0, { message: "Property p_clientid must be at least 0 or more" }) - @IsInt({ message: "Property p_clientid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_clientid must be a number" }) - @IsDefined({ message: "Property p_clientid is required" }) - p_clientid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_clientid must not exceed 999999999' }) + @Min(0, { message: 'Property p_clientid must be at least 0 or more' }) + @IsInt({ message: 'Property p_clientid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_clientid must be a number' }) + @IsDefined({ message: 'Property p_clientid is required' }) + p_clientid: number; - @ApiProperty({ required: true, type: () => [p_clientlocaddresstableDTO] }) - @Type(() => p_clientlocaddresstableDTO) - @ValidateNested({ each: true }) - @IsArray({ message: "Property p_clientlocaddresstable allows only array type" }) - @IsDefined({ message: "Property p_clientlocaddresstable is required" }) - p_clientlocaddresstable: p_clientlocaddresstableDTO[]; + @ApiProperty({ required: true, type: () => [p_clientlocaddresstableDTO] }) + @Type(() => p_clientlocaddresstableDTO) + @ValidateNested({ each: true }) + @IsArray({ + message: 'Property p_clientlocaddresstable allows only array type', + }) + @IsDefined({ message: 'Property p_clientlocaddresstable is required' }) + p_clientlocaddresstable: p_clientlocaddresstableDTO[]; - @ApiProperty({ required: true }) - @Length(0, 1, { message: "Property p_defcontactflag must be exactly 1 character" }) - @IsString({ message: "Property p_defcontactflag must be a string" }) - @IsDefined({ message: "Property p_defcontactflag is required" }) - p_defcontactflag: string; + @ApiProperty({ required: true }) + @Length(0, 1, { + message: 'Property p_defcontactflag must be exactly 1 character', + }) + @IsString({ message: 'Property p_defcontactflag must be a string' }) + @IsDefined({ message: 'Property p_defcontactflag is required' }) + p_defcontactflag: string; - @ApiProperty({ required: true }) - @Length(0, 100, { message: "Property p_userid must be between 0 to 100 characters" }) - @IsString({ message: "Property p_userid must be a string" }) - @IsDefined({ message: "Property p_userid is required" }) - p_userid: string; + @ApiProperty({ required: true }) + @Length(0, 100, { + message: 'Property p_userid must be between 0 to 100 characters', + }) + @IsString({ message: 'Property p_userid must be a string' }) + @IsDefined({ message: 'Property p_userid is required' }) + p_userid: string; } export class GetPreparerByClientidContactsByClientidLocByClientidDTO { - @ApiProperty({ required: true }) - @Transform(({ value }) => Number(value)) - @Max(999999999, { message: "Property p_spid must not exceed 999999999" }) - @Min(0, { message: "Property p_spid must be at least 0 or more" }) - @IsInt({ message: "Property p_spid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_spid must be a number" }) - @IsDefined({ message: "Property p_spid is required" }) - p_spid: number; + @ApiProperty({ required: true }) + @Transform(({ value }) => Number(value)) + @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) + @Min(0, { message: 'Property p_spid must be at least 0 or more' }) + @IsInt({ message: 'Property p_spid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_spid must be a number' }) + @IsDefined({ message: 'Property p_spid is required' }) + p_spid: number; - @ApiProperty({ required: true }) - @Transform(({ value }) => Number(value)) - @Max(999999999, { message: "Property p_clientid must not exceed 999999999" }) - @Min(0, { message: "Property p_clientid must be at least 0 or more" }) - @IsInt({ message: "Property p_clientid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_clientid must be a number" }) - @IsDefined({ message: "Property p_clientid is required" }) - p_clientid: number; + @ApiProperty({ required: true }) + @Transform(({ value }) => Number(value)) + @Max(999999999, { message: 'Property p_clientid must not exceed 999999999' }) + @Min(0, { message: 'Property p_clientid must be at least 0 or more' }) + @IsInt({ message: 'Property p_clientid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_clientid must be a number' }) + @IsDefined({ message: 'Property p_clientid is required' }) + p_clientid: number; } diff --git a/src/oracle/manage-clients/manage-clients.module.ts b/src/oracle/manage-clients/manage-clients.module.ts index 72b2df6..ebcf121 100644 --- a/src/oracle/manage-clients/manage-clients.module.ts +++ b/src/oracle/manage-clients/manage-clients.module.ts @@ -4,6 +4,6 @@ import { ManageClientsService } from './manage-clients.service'; @Module({ controllers: [ManageClientsController], - providers: [ManageClientsService] + providers: [ManageClientsService], }) export class ManageClientsModule {} diff --git a/src/oracle/manage-clients/manage-clients.service.ts b/src/oracle/manage-clients/manage-clients.service.ts index db9bc5e..1018cbc 100644 --- a/src/oracle/manage-clients/manage-clients.service.ts +++ b/src/oracle/manage-clients/manage-clients.service.ts @@ -1,128 +1,190 @@ import { Injectable } from '@nestjs/common'; import { OracleDBService } from 'src/db/db.service'; -import { CreateAdditionalClientContactsDTO, CreateAdditionalClientLocationsDTO, CreateClientDataDTO, GetPreparerByClientidContactsByClientidLocByClientidDTO, GetPreparersDTO, p_clientlocaddresstableDTO, UpdateClientContactsDTO, UpdateClientDTO, UpdateClientLocationsDTO } from './manage-clients.dto'; +import { + CreateAdditionalClientContactsDTO, + CreateAdditionalClientLocationsDTO, + CreateClientDataDTO, + GetPreparerByClientidContactsByClientidLocByClientidDTO, + GetPreparersDTO, + p_clientlocaddresstableDTO, + UpdateClientContactsDTO, + UpdateClientDTO, + UpdateClientLocationsDTO, +} from './manage-clients.dto'; import { p_contactstableDTO } from '../manage-holders/manage-holders.dto'; -import * as oracledb from 'oracledb' +import * as oracledb from 'oracledb'; @Injectable() export class ManageClientsService { - constructor(private readonly oracleDBService: OracleDBService) { } + constructor(private readonly oracleDBService: OracleDBService) {} - CreateClientData = async (body: CreateClientDataDTO) => { + CreateClientData = async (body: CreateClientDataDTO) => { + const newBody = { + p_spid: null, + p_clientname: null, + p_lookupcode: null, + p_address1: null, + p_address2: null, + p_city: null, + p_state: null, + p_zip: null, + p_country: null, + p_issuingregion: null, + p_revenuelocation: null, + p_userid: null, + p_contactstable: null, + p_clientlocaddresstable: null, + }; - let newBody = { - "p_spid": null, - "p_clientname": null, - "p_lookupcode": null, - "p_address1": null, - "p_address2": null, - "p_city": null, - "p_state": null, - "p_zip": null, - "p_country": null, - "p_issuingregion": null, - "p_revenuelocation": null, - "p_userid": null, - "p_contactstable": null, - "p_clientlocaddresstable": null + const reqBody = JSON.parse(JSON.stringify(body)); + + function setEmptyStringsToNull(obj) { + Object.keys(obj).forEach((key) => { + if (typeof obj[key] === 'object' && obj[key] !== null) { + setEmptyStringsToNull(obj[key]); + } else if (obj[key] === '') { + obj[key] = null; } + }); + } - let reqBody = JSON.parse(JSON.stringify(body)); + setEmptyStringsToNull(reqBody); - function setEmptyStringsToNull(obj) { - Object.keys(obj).forEach(key => { - if (typeof obj[key] === 'object' && obj[key] !== null) { - setEmptyStringsToNull(obj[key]); - } else if (obj[key] === "") { - obj[key] = null; - } - }); - } + const finalBody: CreateClientDataDTO = { ...newBody, ...reqBody }; - setEmptyStringsToNull(reqBody); + let connection; + let p_clientcursor_rows = []; + let p_clientcontactcursor_rows = []; + let p_clientloccursor_rows = []; - const finalBody: CreateClientDataDTO = { ...newBody, ...reqBody }; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - let connection; - let p_clientcursor_rows = []; - let p_clientcontactcursor_rows = []; - let p_clientloccursor_rows = []; + // let res = await connection.execute(`SELECT owner, type_name FROM all_types WHERE type_name LIKE '%CLIENT%'`); - try { + // return { res:res.rows }; - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } + // const CONTACTSARRAY = await connection.getDbObjectClass('CARNETSYS.CONTACTSARRAY'); + const CONTACTSTABLE = await connection.getDbObjectClass( + 'CARNETSYS.CONTACTSTABLE', + ); + // const CLIENTLOCADDRESSARRAY = await connection.getDbObjectClass('CARNETSYS.CLIENTLOCADDRESSARRAY'); + const CLIENTLOCADDRESSTABLE = await connection.getDbObjectClass( + 'CARNETSYS.CLIENTLOCADDRESSTABLE', + ); - // let res = await connection.execute(`SELECT owner, type_name FROM all_types WHERE type_name LIKE '%CLIENT%'`); + // Check if CONTACTSTABLE is a constructor + if (typeof CONTACTSTABLE !== 'function') { + throw new Error('CONTACTSTABLE is not a constructor'); + } - // return { res:res.rows }; + // Check if CLIENTLOCADDRESSTABLE is a constructor + if (typeof CLIENTLOCADDRESSTABLE !== 'function') { + throw new Error('CLIENTLOCADDRESSTABLE is not a constructor'); + } - // const CONTACTSARRAY = await connection.getDbObjectClass('CARNETSYS.CONTACTSARRAY'); - const CONTACTSTABLE = await connection.getDbObjectClass('CARNETSYS.CONTACTSTABLE'); - // const CLIENTLOCADDRESSARRAY = await connection.getDbObjectClass('CARNETSYS.CLIENTLOCADDRESSARRAY'); - const CLIENTLOCADDRESSTABLE = await connection.getDbObjectClass('CARNETSYS.CLIENTLOCADDRESSTABLE'); + async function CREATECONTACTSTABLE_INSTANCE( + connection, + FirstName, + LastName, + MiddleInitial, + Title, + EmailAddress, + PhoneNo, + MobileNo, + FaxNo, + ) { + const result = await connection.execute( + `SELECT CARNETSYS.CONTACTSARRAY(:FirstName, :LastName, :MiddleInitial, :Title, :EmailAddress, :PhoneNo, :MobileNo, :FaxNo) FROM dual`, + { + FirstName, + LastName, + MiddleInitial, + Title, + EmailAddress, + PhoneNo, + MobileNo, + FaxNo, + }, + ); + return result.rows[0][0]; + } - // Check if CONTACTSTABLE is a constructor - if (typeof CONTACTSTABLE !== 'function') { - throw new Error('CONTACTSTABLE is not a constructor'); - } + async function CREATECLIENTLOCADDRESSTABLE_INSTANCE( + connection, + Nameof, + Address1, + Address2, + City, + State, + Zip, + Country, + ) { + const result = await connection.execute( + `SELECT CARNETSYS.CLIENTLOCADDRESSARRAY(:Nameof, :Address1, :Address2, :City, :State, :Zip, :Country) FROM dual`, + { + Nameof, + Address1, + Address2, + City, + State, + Zip, + Country, + }, + ); + return result.rows[0][0]; + } - // Check if CLIENTLOCADDRESSTABLE is a constructor - if (typeof CLIENTLOCADDRESSTABLE !== 'function') { - throw new Error('CLIENTLOCADDRESSTABLE is not a constructor'); - } + const CONTACTSARRAY = finalBody.p_contactstable + ? await Promise.all( + finalBody.p_contactstable.map(async (x: p_contactstableDTO) => { + return await CREATECONTACTSTABLE_INSTANCE( + connection, + x.FirstName, + x.LastName, + x.MiddleInitial, + x.Title, + x.EmailAddress, + x.PhoneNo, + x.MobileNo, + x.FaxNo, + ); + }), + ) + : []; - async function CREATECONTACTSTABLE_INSTANCE(connection, FirstName, LastName, MiddleInitial, Title, EmailAddress, PhoneNo, MobileNo, FaxNo) { - const result = await connection.execute( - `SELECT CARNETSYS.CONTACTSARRAY(:FirstName, :LastName, :MiddleInitial, :Title, :EmailAddress, :PhoneNo, :MobileNo, :FaxNo) FROM dual`, - { - FirstName, - LastName, - MiddleInitial, - Title, - EmailAddress, - PhoneNo, - MobileNo, - FaxNo - } + const CLIENTLOCADDRESSARRAY = finalBody.p_clientlocaddresstable + ? await Promise.all( + finalBody.p_clientlocaddresstable.map( + async (x: p_clientlocaddresstableDTO) => { + return await CREATECLIENTLOCADDRESSTABLE_INSTANCE( + connection, + x.Nameof, + x.Address1, + x.Address2, + x.City, + x.State, + x.Zip, + x.Country, ); - return result.rows[0][0]; - } + }, + ), + ) + : []; - async function CREATECLIENTLOCADDRESSTABLE_INSTANCE(connection, Nameof, Address1, Address2, City, State, Zip, Country) { - const result = await connection.execute( - `SELECT CARNETSYS.CLIENTLOCADDRESSARRAY(:Nameof, :Address1, :Address2, :City, :State, :Zip, :Country) FROM dual`, - { - Nameof, - Address1, - Address2, - City, - State, - Zip, - Country - } - ); - return result.rows[0][0]; - } + // Create an instance of GLTABLE + const CONTACTSTABLE_INSTANCE = new CONTACTSTABLE(CONTACTSARRAY); + const CLIENTLOCADDRESSTABLE_INSTANCE = new CLIENTLOCADDRESSTABLE( + CLIENTLOCADDRESSARRAY, + ); - const CONTACTSARRAY = finalBody.p_contactstable ? await Promise.all(finalBody.p_contactstable.map(async (x: p_contactstableDTO) => { - return await CREATECONTACTSTABLE_INSTANCE(connection, x.FirstName, x.LastName, x.MiddleInitial, x.Title, x.EmailAddress, x.PhoneNo, x.MobileNo, x.FaxNo); - })) : []; + // return {CONTACTSTABLE_INSTANCE, CLIENTLOCADDRESSTABLE_INSTANCE} - const CLIENTLOCADDRESSARRAY = finalBody.p_clientlocaddresstable ? await Promise.all(finalBody.p_clientlocaddresstable.map(async (x: p_clientlocaddresstableDTO) => { - return await CREATECLIENTLOCADDRESSTABLE_INSTANCE(connection, x.Nameof, x.Address1, x.Address2, x.City, x.State, x.Zip, x.Country); - })) : []; - - // Create an instance of GLTABLE - const CONTACTSTABLE_INSTANCE = new CONTACTSTABLE(CONTACTSARRAY); - const CLIENTLOCADDRESSTABLE_INSTANCE = new CLIENTLOCADDRESSTABLE(CLIENTLOCADDRESSARRAY); - - // return {CONTACTSTABLE_INSTANCE, CLIENTLOCADDRESSTABLE_INSTANCE} - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEPREPARER_PKG.CreateClientData( :p_spid, :p_clientname, @@ -143,180 +205,183 @@ export class ManageClientsService { :p_clientloccursor ); END;`, - { - p_spid: { - val: finalBody.p_spid ? finalBody.p_spid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_clientname: { - val: finalBody.p_clientname ? finalBody.p_clientname : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_lookupcode: { - val: finalBody.p_lookupcode ? finalBody.p_lookupcode : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_address1: { - val: finalBody.p_address1 ? finalBody.p_address1 : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_address2: { - val: finalBody.p_address2 ? finalBody.p_address2 : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_city: { - val: finalBody.p_city ? finalBody.p_city : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_state: { - val: finalBody.p_state ? finalBody.p_state : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_zip: { - val: finalBody.p_zip ? finalBody.p_zip : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_country: { - val: finalBody.p_country ? finalBody.p_country : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_issuingregion: { - val: finalBody.p_issuingregion ? finalBody.p_issuingregion : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_revenuelocation: { - val: finalBody.p_revenuelocation ? finalBody.p_revenuelocation : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_userid: { - val: finalBody.p_userid ? finalBody.p_userid : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_contactstable: { - val: CONTACTSTABLE_INSTANCE, - type: oracledb.DB_TYPE_OBJECT - }, - p_clientlocaddresstable: { - val: CLIENTLOCADDRESSTABLE_INSTANCE, - type: oracledb.DB_TYPE_OBJECT - }, - p_clientcursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - }, - p_clientcontactcursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - }, - p_clientloccursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + p_spid: { + val: finalBody.p_spid ? finalBody.p_spid : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_clientname: { + val: finalBody.p_clientname ? finalBody.p_clientname : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_lookupcode: { + val: finalBody.p_lookupcode ? finalBody.p_lookupcode : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_address1: { + val: finalBody.p_address1 ? finalBody.p_address1 : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_address2: { + val: finalBody.p_address2 ? finalBody.p_address2 : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_city: { + val: finalBody.p_city ? finalBody.p_city : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_state: { + val: finalBody.p_state ? finalBody.p_state : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_zip: { + val: finalBody.p_zip ? finalBody.p_zip : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_country: { + val: finalBody.p_country ? finalBody.p_country : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_issuingregion: { + val: finalBody.p_issuingregion ? finalBody.p_issuingregion : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_revenuelocation: { + val: finalBody.p_revenuelocation + ? finalBody.p_revenuelocation + : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_userid: { + val: finalBody.p_userid ? finalBody.p_userid : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_contactstable: { + val: CONTACTSTABLE_INSTANCE, + type: oracledb.DB_TYPE_OBJECT, + }, + p_clientlocaddresstable: { + val: CLIENTLOCADDRESSTABLE_INSTANCE, + type: oracledb.DB_TYPE_OBJECT, + }, + p_clientcursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + p_clientcontactcursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + p_clientloccursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); - await connection.commit(); + await connection.commit(); - if (result.outBinds && result.outBinds.p_clientcursor) { - const cursor = result.outBinds.p_clientcursor; - let rowsBatch; + if (result.outBinds && result.outBinds.p_clientcursor) { + const cursor = result.outBinds.p_clientcursor; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); - p_clientcursor_rows = p_clientcursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + do { + rowsBatch = await cursor.getRows(100); + p_clientcursor_rows = p_clientcursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + await cursor.close(); + } else { + throw new Error('No cursor returned from the stored procedure'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } + if (result.outBinds && result.outBinds.p_clientcontactcursor) { + const cursor = result.outBinds.p_clientcontactcursor; + let rowsBatch; - if (result.outBinds && result.outBinds.p_clientcontactcursor) { - const cursor = result.outBinds.p_clientcontactcursor; - let rowsBatch; + do { + rowsBatch = await cursor.getRows(100); + p_clientcontactcursor_rows = + p_clientcontactcursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); - do { - rowsBatch = await cursor.getRows(100); - p_clientcontactcursor_rows = p_clientcontactcursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + await cursor.close(); + } else { + throw new Error('No cursor returned from the stored procedure'); + } + if (result.outBinds && result.outBinds.p_clientloccursor) { + const cursor = result.outBinds.p_clientloccursor; + let rowsBatch; - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } + do { + rowsBatch = await cursor.getRows(100); + p_clientloccursor_rows = p_clientloccursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); - if (result.outBinds && result.outBinds.p_clientloccursor) { - const cursor = result.outBinds.p_clientloccursor; - let rowsBatch; + await cursor.close(); + } else { + throw new Error('No cursor returned from the stored procedure'); + } - do { - rowsBatch = await cursor.getRows(100); - p_clientloccursor_rows = p_clientloccursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + return { + p_clientcursor: p_clientcursor_rows, + p_clientcontactcursor: p_clientcontactcursor_rows, + p_clientloccursor: p_clientloccursor_rows, + }; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } + } + }; + UpdateClient = async (body: UpdateClientDTO) => { + const newBody = { + p_spid: null, + p_clientid: null, + p_preparername: null, + p_address1: null, + p_address2: null, + p_city: null, + p_state: null, + p_zip: null, + p_country: null, + p_revenuelocation: null, + p_userid: null, + }; - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } - - return { p_clientcursor: p_clientcursor_rows, p_clientcontactcursor: p_clientcontactcursor_rows, p_clientloccursor: p_clientloccursor_rows }; - - - } catch (err) { - - return { error: err.message } - } finally { } + const reqBody = JSON.parse(JSON.stringify(body)); + function setEmptyStringsToNull(obj) { + Object.keys(obj).forEach((key) => { + if (typeof obj[key] === 'object' && obj[key] !== null) { + setEmptyStringsToNull(obj[key]); + } else if (obj[key] === '') { + obj[key] = null; + } + }); } - UpdateClient = async (body: UpdateClientDTO) => { + setEmptyStringsToNull(reqBody); - let newBody = { - "p_spid": null, - "p_clientid": null, - "p_preparername": null, - "p_address1": null, - "p_address2": null, - "p_city": null, - "p_state": null, - "p_zip": null, - "p_country": null, - "p_revenuelocation": null, - "p_userid": null - } + const finalBody: UpdateClientDTO = { ...newBody, ...reqBody }; - let reqBody = JSON.parse(JSON.stringify(body)); + let connection; + let p_cursor_rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - function setEmptyStringsToNull(obj) { - Object.keys(obj).forEach(key => { - if (typeof obj[key] === 'object' && obj[key] !== null) { - setEmptyStringsToNull(obj[key]); - } else if (obj[key] === "") { - obj[key] = null; - } - }); - } - - setEmptyStringsToNull(reqBody); - - const finalBody: UpdateClientDTO = { ...newBody, ...reqBody }; - - let connection; - let p_cursor_rows = []; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEPREPARER_PKG.UpdateClient( :p_spid, :p_clientid, @@ -332,127 +397,129 @@ export class ManageClientsService { :p_cursor ); END;`, - { - p_spid: { - val: finalBody.p_spid ? finalBody.p_spid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_clientid: { - val: finalBody.p_clientid ? finalBody.p_clientid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_preparername: { - val: finalBody.p_preparername ? finalBody.p_preparername : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_address1: { - val: finalBody.p_address1 ? finalBody.p_address1 : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_address2: { - val: finalBody.p_address2 ? finalBody.p_address2 : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_city: { - val: finalBody.p_city ? finalBody.p_city : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_state: { - val: finalBody.p_state ? finalBody.p_state : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_zip: { - val: finalBody.p_zip ? finalBody.p_zip : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_country: { - val: finalBody.p_country ? finalBody.p_country : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_revenuelocation: { - val: finalBody.p_revenuelocation ? finalBody.p_revenuelocation : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_userid: { - val: finalBody.p_userid ? finalBody.p_userid : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); - await connection.commit(); + { + p_spid: { + val: finalBody.p_spid ? finalBody.p_spid : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_clientid: { + val: finalBody.p_clientid ? finalBody.p_clientid : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_preparername: { + val: finalBody.p_preparername ? finalBody.p_preparername : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_address1: { + val: finalBody.p_address1 ? finalBody.p_address1 : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_address2: { + val: finalBody.p_address2 ? finalBody.p_address2 : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_city: { + val: finalBody.p_city ? finalBody.p_city : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_state: { + val: finalBody.p_state ? finalBody.p_state : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_zip: { + val: finalBody.p_zip ? finalBody.p_zip : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_country: { + val: finalBody.p_country ? finalBody.p_country : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_revenuelocation: { + val: finalBody.p_revenuelocation + ? finalBody.p_revenuelocation + : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_userid: { + val: finalBody.p_userid ? finalBody.p_userid : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_cursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + await connection.commit(); - if (result.outBinds && result.outBinds.p_cursor) { - const cursor = result.outBinds.p_cursor; - let rowsBatch; + if (result.outBinds && result.outBinds.p_cursor) { + const cursor = result.outBinds.p_cursor; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); - p_cursor_rows = p_cursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + do { + rowsBatch = await cursor.getRows(100); + p_cursor_rows = p_cursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + await cursor.close(); + } else { + throw new Error('No cursor returned from the stored procedure'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } + return { p_cursor: p_cursor_rows }; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } + } + }; - return { p_cursor: p_cursor_rows }; + UpdateClientContacts = async (body: UpdateClientContactsDTO) => { + const newBody = { + p_spid: null, + p_clientcontactid: null, + p_firstname: null, + p_lastname: null, + p_middleinitial: null, + p_title: null, + p_phone: null, + p_fax: null, + p_mobileno: null, + p_emailaddress: null, + p_userid: null, + }; - } catch (err) { - - return { error: err.message } - } finally { } + const reqBody = JSON.parse(JSON.stringify(body)); + + function setEmptyStringsToNull(obj) { + Object.keys(obj).forEach((key) => { + if (typeof obj[key] === 'object' && obj[key] !== null) { + setEmptyStringsToNull(obj[key]); + } else if (obj[key] === '') { + obj[key] = null; + } + }); } - UpdateClientContacts = async (body: UpdateClientContactsDTO) => { + setEmptyStringsToNull(reqBody); - let newBody = { - "p_spid": null, - "p_clientcontactid": null, - "p_firstname": null, - "p_lastname": null, - "p_middleinitial": null, - "p_title": null, - "p_phone": null, - "p_fax": null, - "p_mobileno": null, - "p_emailaddress": null, - "p_userid": null - } + const finalBody: UpdateClientContactsDTO = { ...newBody, ...reqBody }; - let reqBody = JSON.parse(JSON.stringify(body)); + let connection; + let P_cursor_rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - function setEmptyStringsToNull(obj) { - Object.keys(obj).forEach(key => { - if (typeof obj[key] === 'object' && obj[key] !== null) { - setEmptyStringsToNull(obj[key]); - } else if (obj[key] === "") { - obj[key] = null; - } - }); - } - - setEmptyStringsToNull(reqBody); - - const finalBody: UpdateClientContactsDTO = { ...newBody, ...reqBody }; - - let connection; - let P_cursor_rows = []; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEPREPARER_PKG.UpdateClientContacts( :p_spid, :p_clientcontactid, @@ -468,127 +535,128 @@ export class ManageClientsService { :P_cursor ); END;`, - { - p_spid: { - val: finalBody.p_spid ? finalBody.p_spid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_clientcontactid: { - val: finalBody.p_clientcontactid ? finalBody.p_clientcontactid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_firstname: { - val: finalBody.p_firstname ? finalBody.p_firstname : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_lastname: { - val: finalBody.p_lastname ? finalBody.p_lastname : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_middleinitial: { - val: finalBody.p_middleinitial ? finalBody.p_middleinitial : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_title: { - val: finalBody.p_title ? finalBody.p_title : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_phone: { - val: finalBody.p_phone ? finalBody.p_phone : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_fax: { - val: finalBody.p_fax ? finalBody.p_fax : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_mobileno: { - val: finalBody.p_mobileno ? finalBody.p_mobileno : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_emailaddress: { - val: finalBody.p_emailaddress ? finalBody.p_emailaddress : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_userid: { - val: finalBody.p_userid ? finalBody.p_userid : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - P_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); - await connection.commit(); + { + p_spid: { + val: finalBody.p_spid ? finalBody.p_spid : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_clientcontactid: { + val: finalBody.p_clientcontactid + ? finalBody.p_clientcontactid + : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_firstname: { + val: finalBody.p_firstname ? finalBody.p_firstname : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_lastname: { + val: finalBody.p_lastname ? finalBody.p_lastname : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_middleinitial: { + val: finalBody.p_middleinitial ? finalBody.p_middleinitial : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_title: { + val: finalBody.p_title ? finalBody.p_title : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_phone: { + val: finalBody.p_phone ? finalBody.p_phone : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_fax: { + val: finalBody.p_fax ? finalBody.p_fax : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_mobileno: { + val: finalBody.p_mobileno ? finalBody.p_mobileno : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_emailaddress: { + val: finalBody.p_emailaddress ? finalBody.p_emailaddress : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_userid: { + val: finalBody.p_userid ? finalBody.p_userid : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_cursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + await connection.commit(); - if (result.outBinds && result.outBinds.P_cursor) { - const cursor = result.outBinds.P_cursor; - let rowsBatch; + if (result.outBinds && result.outBinds.P_cursor) { + const cursor = result.outBinds.P_cursor; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); - P_cursor_rows = P_cursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + do { + rowsBatch = await cursor.getRows(100); + P_cursor_rows = P_cursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + await cursor.close(); + } else { + throw new Error('No cursor returned from the stored procedure'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } + return { P_cursor: P_cursor_rows }; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } + } + }; - return { P_cursor: P_cursor_rows }; + UpdateClientLocations = async (body: UpdateClientLocationsDTO) => { + const newBody = { + p_spid: null, + p_clientlocationid: null, + p_lcoationname: null, + p_address1: null, + p_address2: null, + p_city: null, + p_state: null, + p_zip: null, + p_country: null, + p_userid: null, + }; - } catch (err) { - - return { error: err.message } - } finally { } + const reqBody = JSON.parse(JSON.stringify(body)); + function setEmptyStringsToNull(obj) { + Object.keys(obj).forEach((key) => { + if (typeof obj[key] === 'object' && obj[key] !== null) { + setEmptyStringsToNull(obj[key]); + } else if (obj[key] === '') { + obj[key] = null; + } + }); } - UpdateClientLocations = async (body: UpdateClientLocationsDTO) => { + setEmptyStringsToNull(reqBody); - let newBody = { - "p_spid": null, - "p_clientlocationid": null, - "p_lcoationname": null, - "p_address1": null, - "p_address2": null, - "p_city": null, - "p_state": null, - "p_zip": null, - "p_country": null, - "p_userid": null - } + const finalBody: UpdateClientLocationsDTO = { ...newBody, ...reqBody }; - let reqBody = JSON.parse(JSON.stringify(body)); + let connection; + let p_cursor_rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - function setEmptyStringsToNull(obj) { - Object.keys(obj).forEach(key => { - if (typeof obj[key] === 'object' && obj[key] !== null) { - setEmptyStringsToNull(obj[key]); - } else if (obj[key] === "") { - obj[key] = null; - } - }); - } - - setEmptyStringsToNull(reqBody); - - const finalBody: UpdateClientLocationsDTO = { ...newBody, ...reqBody }; - - let connection; - let p_cursor_rows = []; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEPREPARER_PKG.UpdateClientLocations( :p_spid, :p_clientlocationid, @@ -603,149 +671,180 @@ export class ManageClientsService { :p_cursor ); END;`, - { - p_spid: { - val: finalBody.p_spid ? finalBody.p_spid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_clientlocationid: { - val: finalBody.p_clientlocationid ? finalBody.p_clientlocationid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_lcoationname: { - val: finalBody.p_lcoationname ? finalBody.p_lcoationname : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_address1: { - val: finalBody.p_address1 ? finalBody.p_address1 : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_address2: { - val: finalBody.p_address2 ? finalBody.p_address2 : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_city: { - val: finalBody.p_city ? finalBody.p_city : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_state: { - val: finalBody.p_state ? finalBody.p_state : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_zip: { - val: finalBody.p_zip ? finalBody.p_zip : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_country: { - val: finalBody.p_country ? finalBody.p_country : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_userid: { - val: finalBody.p_userid ? finalBody.p_userid : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); - await connection.commit(); + { + p_spid: { + val: finalBody.p_spid ? finalBody.p_spid : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_clientlocationid: { + val: finalBody.p_clientlocationid + ? finalBody.p_clientlocationid + : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_lcoationname: { + val: finalBody.p_lcoationname ? finalBody.p_lcoationname : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_address1: { + val: finalBody.p_address1 ? finalBody.p_address1 : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_address2: { + val: finalBody.p_address2 ? finalBody.p_address2 : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_city: { + val: finalBody.p_city ? finalBody.p_city : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_state: { + val: finalBody.p_state ? finalBody.p_state : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_zip: { + val: finalBody.p_zip ? finalBody.p_zip : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_country: { + val: finalBody.p_country ? finalBody.p_country : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_userid: { + val: finalBody.p_userid ? finalBody.p_userid : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_cursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + await connection.commit(); - if (result.outBinds && result.outBinds.p_cursor) { - const cursor = result.outBinds.p_cursor; - let rowsBatch; + if (result.outBinds && result.outBinds.p_cursor) { + const cursor = result.outBinds.p_cursor; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); - p_cursor_rows = p_cursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + do { + rowsBatch = await cursor.getRows(100); + p_cursor_rows = p_cursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + await cursor.close(); + } else { + throw new Error('No cursor returned from the stored procedure'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } + return { p_cursor: p_cursor_rows }; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } + } + }; - return { p_cursor: p_cursor_rows }; + CreateClientContact = async (body: CreateAdditionalClientContactsDTO) => { + const newBody = { + p_spid: null, + p_clientid: null, + p_contactstable: null, + p_defcontactflag: null, + p_userid: null, + }; - } catch (err) { - - return { error: err.message } - } finally { } + const reqBody = JSON.parse(JSON.stringify(body)); + + function setEmptyStringsToNull(obj) { + Object.keys(obj).forEach((key) => { + if (typeof obj[key] === 'object' && obj[key] !== null) { + setEmptyStringsToNull(obj[key]); + } else if (obj[key] === '') { + obj[key] = null; + } + }); } - CreateClientContact = async (body: CreateAdditionalClientContactsDTO) => { + setEmptyStringsToNull(reqBody); - let newBody = { - "p_spid": null, - "p_clientid": null, - "p_contactstable": null, - "p_defcontactflag": null, - "p_userid": null - } + const finalBody: CreateAdditionalClientContactsDTO = { + ...newBody, + ...reqBody, + }; - let reqBody = JSON.parse(JSON.stringify(body)); + let connection; + let p_cursor_rows = []; - function setEmptyStringsToNull(obj) { - Object.keys(obj).forEach(key => { - if (typeof obj[key] === 'object' && obj[key] !== null) { - setEmptyStringsToNull(obj[key]); - } else if (obj[key] === "") { - obj[key] = null; - } - }); - } + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - setEmptyStringsToNull(reqBody); + const CONTACTSTABLE = await connection.getDbObjectClass( + 'CARNETSYS.CONTACTSTABLE', + ); - const finalBody: CreateAdditionalClientContactsDTO = { ...newBody, ...reqBody }; + // Check if CONTACTSTABLE is a constructor + if (typeof CONTACTSTABLE !== 'function') { + throw new Error('CONTACTSTABLE is not a constructor'); + } - let connection; - let p_cursor_rows = []; + async function CREATECONTACTSTABLE_INSTANCE( + connection, + FirstName, + LastName, + MiddleInitial, + Title, + EmailAddress, + PhoneNo, + MobileNo, + FaxNo, + ) { + const result = await connection.execute( + `SELECT CARNETSYS.CONTACTSARRAY(:FirstName, :LastName, :MiddleInitial, :Title, :EmailAddress, :PhoneNo, :MobileNo, :FaxNo) FROM dual`, + { + FirstName, + LastName, + MiddleInitial, + Title, + EmailAddress, + PhoneNo, + MobileNo, + FaxNo, + }, + ); + return result.rows[0][0]; + } - try { + const CONTACTSARRAY = finalBody.p_contactstable + ? await Promise.all( + finalBody.p_contactstable.map(async (x: p_contactstableDTO) => { + return await CREATECONTACTSTABLE_INSTANCE( + connection, + x.FirstName, + x.LastName, + x.MiddleInitial, + x.Title, + x.EmailAddress, + x.PhoneNo, + x.MobileNo, + x.FaxNo, + ); + }), + ) + : []; - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } + // Create an instance of GLTABLE + const CONTACTSTABLE_INSTANCE = new CONTACTSTABLE(CONTACTSARRAY); - const CONTACTSTABLE = await connection.getDbObjectClass('CARNETSYS.CONTACTSTABLE'); - - // Check if CONTACTSTABLE is a constructor - if (typeof CONTACTSTABLE !== 'function') { - throw new Error('CONTACTSTABLE is not a constructor'); - } - - async function CREATECONTACTSTABLE_INSTANCE(connection, FirstName, LastName, MiddleInitial, Title, EmailAddress, PhoneNo, MobileNo, FaxNo) { - const result = await connection.execute( - `SELECT CARNETSYS.CONTACTSARRAY(:FirstName, :LastName, :MiddleInitial, :Title, :EmailAddress, :PhoneNo, :MobileNo, :FaxNo) FROM dual`, - { - FirstName, - LastName, - MiddleInitial, - Title, - EmailAddress, - PhoneNo, - MobileNo, - FaxNo - } - ); - return result.rows[0][0]; - } - - const CONTACTSARRAY = finalBody.p_contactstable ? await Promise.all(finalBody.p_contactstable.map(async (x: p_contactstableDTO) => { - return await CREATECONTACTSTABLE_INSTANCE(connection, x.FirstName, x.LastName, x.MiddleInitial, x.Title, x.EmailAddress, x.PhoneNo, x.MobileNo, x.FaxNo); - })) : []; - - // Create an instance of GLTABLE - const CONTACTSTABLE_INSTANCE = new CONTACTSTABLE(CONTACTSARRAY); - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEPREPARER_PKG.CreateClientContact( :p_spid, :p_clientid, @@ -755,127 +854,158 @@ export class ManageClientsService { :p_cursor ); END;`, - { - p_spid: { - val: finalBody.p_spid ? finalBody.p_spid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_clientid: { - val: finalBody.p_clientid ? finalBody.p_clientid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_contactstable: { - val: CONTACTSTABLE_INSTANCE, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_defcontactflag: { - val: finalBody.p_defcontactflag ? finalBody.p_defcontactflag : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_userid: { - val: finalBody.p_userid ? finalBody.p_userid : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + p_spid: { + val: finalBody.p_spid ? finalBody.p_spid : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_clientid: { + val: finalBody.p_clientid ? finalBody.p_clientid : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_contactstable: { + val: CONTACTSTABLE_INSTANCE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_defcontactflag: { + val: finalBody.p_defcontactflag ? finalBody.p_defcontactflag : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_userid: { + val: finalBody.p_userid ? finalBody.p_userid : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_cursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); - await connection.commit(); + await connection.commit(); - if (result.outBinds && result.outBinds.p_cursor) { - const cursor = result.outBinds.p_cursor; - let rowsBatch; + if (result.outBinds && result.outBinds.p_cursor) { + const cursor = result.outBinds.p_cursor; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); - p_cursor_rows = p_cursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + do { + rowsBatch = await cursor.getRows(100); + p_cursor_rows = p_cursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + await cursor.close(); + } else { + throw new Error('No cursor returned from the stored procedure'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } + return { p_cursor: p_cursor_rows }; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } + } + }; - return { p_cursor: p_cursor_rows }; + CreateClientLocation = async (body: CreateAdditionalClientLocationsDTO) => { + const newBody = { + p_spid: null, + p_clientid: null, + p_clientlocaddresstable: null, + p_defcontactflag: null, + p_userid: null, + }; + const reqBody = JSON.parse(JSON.stringify(body)); - } catch (err) { - - return { error: err.message } - } finally { } + function setEmptyStringsToNull(obj) { + Object.keys(obj).forEach((key) => { + if (typeof obj[key] === 'object' && obj[key] !== null) { + setEmptyStringsToNull(obj[key]); + } else if (obj[key] === '') { + obj[key] = null; + } + }); } - CreateClientLocation = async (body: CreateAdditionalClientLocationsDTO) => { - let newBody = { - "p_spid": null, - "p_clientid": null, - "p_clientlocaddresstable": null, - "p_defcontactflag": null, - "p_userid": null - } + setEmptyStringsToNull(reqBody); - let reqBody = JSON.parse(JSON.stringify(body)); + const finalBody: CreateAdditionalClientLocationsDTO = { + ...newBody, + ...reqBody, + }; - function setEmptyStringsToNull(obj) { - Object.keys(obj).forEach(key => { - if (typeof obj[key] === 'object' && obj[key] !== null) { - setEmptyStringsToNull(obj[key]); - } else if (obj[key] === "") { - obj[key] = null; - } - }); - } + let connection; + let p_cursor_rows = []; - setEmptyStringsToNull(reqBody); + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - const finalBody: CreateAdditionalClientLocationsDTO = { ...newBody, ...reqBody }; + const CLIENTLOCADDRESSTABLE = await connection.getDbObjectClass( + 'CARNETSYS.CLIENTLOCADDRESSTABLE', + ); - let connection; - let p_cursor_rows = []; + if (typeof CLIENTLOCADDRESSTABLE !== 'function') { + throw new Error('CLIENTLOCADDRESSTABLE is not a constructor'); + } - try { + async function CREATECLIENTLOCADDRESSTABLE_INSTANCE( + connection, + Nameof, + Address1, + Address2, + City, + State, + Zip, + Country, + ) { + const result = await connection.execute( + `SELECT CARNETSYS.CLIENTLOCADDRESSARRAY(:Nameof, :Address1, :Address2, :City, :State, :Zip, :Country) FROM dual`, + { + Nameof, + Address1, + Address2, + City, + State, + Zip, + Country, + }, + ); + return result.rows[0][0]; + } - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const CLIENTLOCADDRESSTABLE = await connection.getDbObjectClass('CARNETSYS.CLIENTLOCADDRESSTABLE'); - - if (typeof CLIENTLOCADDRESSTABLE !== 'function') { - throw new Error('CLIENTLOCADDRESSTABLE is not a constructor'); - } - - async function CREATECLIENTLOCADDRESSTABLE_INSTANCE(connection, Nameof, Address1, Address2, City, State, Zip, Country) { - const result = await connection.execute( - `SELECT CARNETSYS.CLIENTLOCADDRESSARRAY(:Nameof, :Address1, :Address2, :City, :State, :Zip, :Country) FROM dual`, - { - Nameof, - Address1, - Address2, - City, - State, - Zip, - Country - } + const CLIENTLOCADDRESSARRAY = finalBody.p_clientlocaddresstable + ? await Promise.all( + finalBody.p_clientlocaddresstable.map( + async (x: p_clientlocaddresstableDTO) => { + return await CREATECLIENTLOCADDRESSTABLE_INSTANCE( + connection, + x.Nameof, + x.Address1, + x.Address2, + x.City, + x.State, + x.Zip, + x.Country, ); - return result.rows[0][0]; - } + }, + ), + ) + : []; - const CLIENTLOCADDRESSARRAY = finalBody.p_clientlocaddresstable ? await Promise.all(finalBody.p_clientlocaddresstable.map(async (x: p_clientlocaddresstableDTO) => { - return await CREATECLIENTLOCADDRESSTABLE_INSTANCE(connection, x.Nameof, x.Address1, x.Address2, x.City, x.State, x.Zip, x.Country); - })) : []; + const CLIENTLOCADDRESSTABLE_INSTANCE = new CLIENTLOCADDRESSTABLE( + CLIENTLOCADDRESSARRAY, + ); - const CLIENTLOCADDRESSTABLE_INSTANCE = new CLIENTLOCADDRESSTABLE(CLIENTLOCADDRESSARRAY); - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEPREPARER_PKG.CreateClientLocation( :p_spid, :p_clientid, @@ -884,77 +1014,77 @@ export class ManageClientsService { :p_userid ); END;`, - { - p_spid: { - val: finalBody.p_spid ? finalBody.p_spid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_clientid: { - val: finalBody.p_clientid ? finalBody.p_clientid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_clientlocaddresstable: { - val: CLIENTLOCADDRESSTABLE_INSTANCE, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_defcontactflag: { - val: finalBody.p_defcontactflag ? finalBody.p_defcontactflag : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_userid: { - val: finalBody.p_userid ? finalBody.p_userid : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + p_spid: { + val: finalBody.p_spid ? finalBody.p_spid : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_clientid: { + val: finalBody.p_clientid ? finalBody.p_clientid : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_clientlocaddresstable: { + val: CLIENTLOCADDRESSTABLE_INSTANCE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_defcontactflag: { + val: finalBody.p_defcontactflag ? finalBody.p_defcontactflag : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_userid: { + val: finalBody.p_userid ? finalBody.p_userid : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_cursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); - await connection.commit(); + await connection.commit(); - if (result.outBinds && result.outBinds.p_cursor) { - const cursor = result.outBinds.p_cursor; - let rowsBatch; + if (result.outBinds && result.outBinds.p_cursor) { + const cursor = result.outBinds.p_cursor; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); - p_cursor_rows = p_cursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + do { + rowsBatch = await cursor.getRows(100); + p_cursor_rows = p_cursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + await cursor.close(); + } else { + throw new Error('No cursor returned from the stored procedure'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } - - return { p_cursor: p_cursor_rows }; - - - } catch (err) { - - return { error: err.message } - } finally { } + return { p_cursor: p_cursor_rows }; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + }; - GetPreparers = async (body: GetPreparersDTO) => { + GetPreparers = async (body: GetPreparersDTO) => { + let connection; + let p_maincursor_rows = []; + let p_contactscursor_rows = []; + let p_locationcursor_rows = []; - let connection; - let p_maincursor_rows = []; - let p_contactscursor_rows = []; - let p_locationcursor_rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - try { - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEPREPARER_PKG.GetPreparers( :p_spid, :p_name, @@ -967,268 +1097,278 @@ export class ManageClientsService { :p_locationcursor ); END;`, - { - p_spid: { - val: body.p_spid, - type: oracledb.DB_TYPE_NUMBER, - }, - p_name: { - val: body.p_name, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_lookupcode: { - val: body.p_lookupcode, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_city: { - val: body.p_city, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_state: { - val: body.p_state, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_status: { - val: body.p_status, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_maincursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - }, - p_contactscursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - }, - p_locationcursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + p_spid: { + val: body.p_spid, + type: oracledb.DB_TYPE_NUMBER, + }, + p_name: { + val: body.p_name, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_lookupcode: { + val: body.p_lookupcode, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_city: { + val: body.p_city, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_state: { + val: body.p_state, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_status: { + val: body.p_status, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_maincursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + p_contactscursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + p_locationcursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); - if (result.outBinds && result.outBinds.p_maincursor) { - const cursor = result.outBinds.p_maincursor; - let rowsBatch; + if (result.outBinds && result.outBinds.p_maincursor) { + const cursor = result.outBinds.p_maincursor; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); - p_maincursor_rows = p_maincursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + do { + rowsBatch = await cursor.getRows(100); + p_maincursor_rows = p_maincursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + await cursor.close(); + } - await cursor.close(); - } + if (result.outBinds && result.outBinds.p_contactscursor) { + const cursor = result.outBinds.p_contactscursor; + let rowsBatch; - if (result.outBinds && result.outBinds.p_contactscursor) { - const cursor = result.outBinds.p_contactscursor; - let rowsBatch; + do { + rowsBatch = await cursor.getRows(100); + p_contactscursor_rows = p_contactscursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); - do { - rowsBatch = await cursor.getRows(100); - p_contactscursor_rows = p_contactscursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + await cursor.close(); + } + if (result.outBinds && result.outBinds.p_locationcursor) { + const cursor = result.outBinds.p_locationcursor; + let rowsBatch; - await cursor.close(); - } + do { + rowsBatch = await cursor.getRows(100); + p_locationcursor_rows = p_locationcursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); - if (result.outBinds && result.outBinds.p_locationcursor) { - const cursor = result.outBinds.p_locationcursor; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_locationcursor_rows = p_locationcursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); - - - await cursor.close(); - } - return { p_maincursor: p_maincursor_rows, p_contactscursor: p_contactscursor_rows, p_locationcursor: p_locationcursor_rows }; - - } catch (err) { - - return { error: err.message } - } finally { } + await cursor.close(); + } + return { + p_maincursor: p_maincursor_rows, + p_contactscursor: p_contactscursor_rows, + p_locationcursor: p_locationcursor_rows, + }; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + }; - GetPreparerByClientid = async (body: GetPreparerByClientidContactsByClientidLocByClientidDTO) => { + GetPreparerByClientid = async ( + body: GetPreparerByClientidContactsByClientidLocByClientidDTO, + ) => { + let connection; + let p_cursor_rows = []; - let connection; - let p_cursor_rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - try { - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEPREPARER_PKG.GetPreparerByClientid( :p_spid, :p_clientid, :p_cursor ); END;`, - { - p_spid: { - val: body.p_spid, - type: oracledb.DB_TYPE_NUMBER, - }, - p_clientid: { - val: body.p_clientid, - type: oracledb.DB_TYPE_NUMBER, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + p_spid: { + val: body.p_spid, + type: oracledb.DB_TYPE_NUMBER, + }, + p_clientid: { + val: body.p_clientid, + 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; + if (result.outBinds && result.outBinds.p_cursor) { + const cursor = result.outBinds.p_cursor; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); - p_cursor_rows = p_cursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + do { + rowsBatch = await cursor.getRows(100); + p_cursor_rows = p_cursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + await cursor.close(); + } - await cursor.close(); - } - - return { p_cursor: p_cursor_rows }; - - } catch (err) { - - return { error: err.message } - } finally { } - + return { p_cursor: p_cursor_rows }; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + }; - GetPreparerContactsByClientid = async (body: GetPreparerByClientidContactsByClientidLocByClientidDTO) => { - let connection; - let p_cursor_rows = []; + GetPreparerContactsByClientid = async ( + body: GetPreparerByClientidContactsByClientidLocByClientidDTO, + ) => { + let connection; + let p_cursor_rows = []; - try { - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEPREPARER_PKG.GetPreparerContactsByClientid( :p_spid, :p_clientid, :p_cursor ); END;`, - { - p_spid: { - val: body.p_spid, - type: oracledb.DB_TYPE_NUMBER, - }, - p_clientid: { - val: body.p_clientid, - type: oracledb.DB_TYPE_NUMBER, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + p_spid: { + val: body.p_spid, + type: oracledb.DB_TYPE_NUMBER, + }, + p_clientid: { + val: body.p_clientid, + 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; + if (result.outBinds && result.outBinds.p_cursor) { + const cursor = result.outBinds.p_cursor; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); - p_cursor_rows = p_cursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + do { + rowsBatch = await cursor.getRows(100); + p_cursor_rows = p_cursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + await cursor.close(); + } - await cursor.close(); - } - - return { p_cursor: p_cursor_rows }; - - } catch (err) { - - return { error: err.message } - } finally { } + return { p_cursor: p_cursor_rows }; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + }; - GetPreparerLocByClientid = async (body: GetPreparerByClientidContactsByClientidLocByClientidDTO) => { - let connection; - let p_cursor_rows = []; + GetPreparerLocByClientid = async ( + body: GetPreparerByClientidContactsByClientidLocByClientidDTO, + ) => { + let connection; + let p_cursor_rows = []; - try { - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEPREPARER_PKG.GetPreparerLocByClientid( :p_spid, :p_clientid, :p_cursor ); END;`, - { - p_spid: { - val: body.p_spid, - type: oracledb.DB_TYPE_NUMBER, - }, - p_clientid: { - val: body.p_clientid, - type: oracledb.DB_TYPE_NUMBER, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + p_spid: { + val: body.p_spid, + type: oracledb.DB_TYPE_NUMBER, + }, + p_clientid: { + val: body.p_clientid, + 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; + if (result.outBinds && result.outBinds.p_cursor) { + const cursor = result.outBinds.p_cursor; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); - p_cursor_rows = p_cursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + do { + rowsBatch = await cursor.getRows(100); + p_cursor_rows = p_cursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + await cursor.close(); + } - await cursor.close(); - } - - return { p_cursor: p_cursor_rows }; - - } catch (err) { - - return { error: err.message } - } finally { } + return { p_cursor: p_cursor_rows }; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + }; } diff --git a/src/oracle/manage-fee/manage-fee.controller.ts b/src/oracle/manage-fee/manage-fee.controller.ts index 0286ffa..e598770 100644 --- a/src/oracle/manage-fee/manage-fee.controller.ts +++ b/src/oracle/manage-fee/manage-fee.controller.ts @@ -1,152 +1,151 @@ -import { Body, Controller, Get, Param, ParseIntPipe, Patch, Post, Query } from '@nestjs/common'; +import { Body, Controller, Get, Patch, Post, Query } from '@nestjs/common'; import { ManageFeeService } from './manage-fee.service'; import { ApiTags } from '@nestjs/swagger'; import { - CreateBasicFeeDTO, - CreateBondRateDTO, - CreateCargoRateDTO, - CreateCfFeeDTO, - CreateCsFeeDTO, - CreateEfFeeDTO, - CreateFeeCommDTO, - GetFeeGeneralDTO, - UpdateBasicFeeDTO, - UpdateBondRateDTO, - UpdateCargoRateDTO, - UpdateCfFeeDTO, - UpdateCsFeeDTO, - UpdateEfFeeDTO, - UpdateFeeCommBodyDTO + CreateBasicFeeDTO, + CreateBondRateDTO, + CreateCargoRateDTO, + CreateCfFeeDTO, + CreateCsFeeDTO, + CreateEfFeeDTO, + CreateFeeCommDTO, + GetFeeGeneralDTO, + UpdateBasicFeeDTO, + UpdateBondRateDTO, + UpdateCargoRateDTO, + UpdateCfFeeDTO, + UpdateCsFeeDTO, + UpdateEfFeeDTO, + UpdateFeeCommBodyDTO, } from './manage-fee.dto'; @Controller('manage-fee') export class ManageFeeController { - constructor(private readonly manageFeeService: ManageFeeService) { } + constructor(private readonly manageFeeService: ManageFeeService) {} + @ApiTags('Manage Fee - Oracle') + @Get('/GetBasicFeeRates') + GetBasicFeeRates(@Query() body: GetFeeGeneralDTO) { + return this.manageFeeService.GETBASICFEERATES(body); + } - @ApiTags('Manage Fee - Oracle') - @Get('/GetBasicFeeRates') - GetBasicFeeRates(@Query() body: GetFeeGeneralDTO) { - return this.manageFeeService.GETBASICFEERATES(body) - } + @ApiTags('Manage Fee - Oracle') + @Get('/GetBondRates') + GetBondRates(@Query() body: GetFeeGeneralDTO) { + return this.manageFeeService.GETBONDRATES(body); + } - @ApiTags('Manage Fee - Oracle') - @Get('/GetBondRates') - GetBondRates(@Query() body: GetFeeGeneralDTO) { - return this.manageFeeService.GETBONDRATES(body) - } + @ApiTags('Manage Fee - Oracle') + @Get('/GetCargoRates') + GetCargoRates(@Query() body: GetFeeGeneralDTO) { + return this.manageFeeService.GETCARGORATES(body); + } - @ApiTags('Manage Fee - Oracle') - @Get('/GetCargoRates') - GetCargoRates(@Query() body: GetFeeGeneralDTO) { - return this.manageFeeService.GETCARGORATES(body) - } + @ApiTags('Manage Fee - Oracle') + @Get('/GetCfFeeRates') + GetCfFeeRates(@Query() body: GetFeeGeneralDTO) { + return this.manageFeeService.GETCFFEERATES(body); + } - @ApiTags('Manage Fee - Oracle') - @Get('/GetCfFeeRates') - GetCfFeeRates(@Query() body: GetFeeGeneralDTO) { - return this.manageFeeService.GETCFFEERATES(body) - } + @ApiTags('Manage Fee - Oracle') + @Get('/GetCsFeeRates') + GetCsFeeRates(@Query() body: GetFeeGeneralDTO) { + return this.manageFeeService.GETCSFEERATES(body); + } - @ApiTags('Manage Fee - Oracle') - @Get('/GetCsFeeRates') - GetCsFeeRates(@Query() body: GetFeeGeneralDTO) { - return this.manageFeeService.GETCSFEERATES(body) - } + @ApiTags('Manage Fee - Oracle') + @Get('/GetEfFeeRates') + GetEfFeeRates(@Query() body: GetFeeGeneralDTO) { + return this.manageFeeService.GETEFFEERATES(body); + } - @ApiTags('Manage Fee - Oracle') - @Get('/GetEfFeeRates') - GetEfFeeRates(@Query() body: GetFeeGeneralDTO) { - return this.manageFeeService.GETEFFEERATES(body) - } + @ApiTags('Manage Fee - Oracle') + @Get('/GetFeeComm') + GetFeeComm(@Query() body: GetFeeGeneralDTO) { + return this.manageFeeService.GETFEECOMM(body); + } - @ApiTags('Manage Fee - Oracle') - @Get('/GetFeeComm') - GetFeeComm(@Query() body: GetFeeGeneralDTO) { - return this.manageFeeService.GETFEECOMM(body) - } + @ApiTags('Manage Fee - Oracle') + @Post('/CreateBasicFee') + CreateBasicFee(@Body() body: CreateBasicFeeDTO) { + return this.manageFeeService.CREATEBASICFEE(body); + } - @ApiTags('Manage Fee - Oracle') - @Post('/CreateBasicFee') - CreateBasicFee(@Body() body: CreateBasicFeeDTO) { - return this.manageFeeService.CREATEBASICFEE(body) - } + @ApiTags('Manage Fee - Oracle') + @Post('/CreateBondRate') + CreateBondRate(@Body() body: CreateBondRateDTO) { + return this.manageFeeService.CREATEBONDRATE(body); + } - @ApiTags('Manage Fee - Oracle') - @Post('/CreateBondRate') - CreateBondRate(@Body() body: CreateBondRateDTO) { - return this.manageFeeService.CREATEBONDRATE(body) - } + @ApiTags('Manage Fee - Oracle') + @Post('/CreateCargoRate') + CreateCargoRate(@Body() body: CreateCargoRateDTO) { + return this.manageFeeService.CREATECARGORATE(body); + } - @ApiTags('Manage Fee - Oracle') - @Post('/CreateCargoRate') - CreateCargoRate(@Body() body: CreateCargoRateDTO) { - return this.manageFeeService.CREATECARGORATE(body) - } + @ApiTags('Manage Fee - Oracle') + @Post('/CreateCfFee') + CreateCfFee(@Body() body: CreateCfFeeDTO) { + return this.manageFeeService.CREATECFFEE(body); + } - @ApiTags('Manage Fee - Oracle') - @Post('/CreateCfFee') - CreateCfFee(@Body() body: CreateCfFeeDTO) { - return this.manageFeeService.CREATECFFEE(body) - } + @ApiTags('Manage Fee - Oracle') + @Post('/CreateCsFee') + CreateCsFee(@Body() body: CreateCsFeeDTO) { + return this.manageFeeService.CREATECSFEE(body); + } - @ApiTags('Manage Fee - Oracle') - @Post('/CreateCsFee') - CreateCsFee(@Body() body: CreateCsFeeDTO) { - return this.manageFeeService.CREATECSFEE(body) - } + @ApiTags('Manage Fee - Oracle') + @Post('/CreateEfFee') + CreateEeFee(@Body() body: CreateEfFeeDTO) { + return this.manageFeeService.CREATEEFFEE(body); + } - @ApiTags('Manage Fee - Oracle') - @Post('/CreateEfFee') - CreateEeFee(@Body() body: CreateEfFeeDTO) { - return this.manageFeeService.CREATEEFFEE(body) - } + @ApiTags('Manage Fee - Oracle') + @Post('/CreateFeeComm') + CreateFeeComm(@Body() body: CreateFeeCommDTO) { + return this.manageFeeService.CREATEFEECOMM(body); + } - @ApiTags('Manage Fee - Oracle') - @Post('/CreateFeeComm') - CreateFeeComm(@Body() body: CreateFeeCommDTO) { - return this.manageFeeService.CREATEFEECOMM(body) - } + @ApiTags('Manage Fee - Oracle') + @Patch('/UpdateBasicFee') + UpdateBasicFee(@Body() body: UpdateBasicFeeDTO) { + return this.manageFeeService.UPDATEBASICFEE(body); + } - @ApiTags('Manage Fee - Oracle') - @Patch('/UpdateBasicFee') - UpdateBasicFee(@Body() body: UpdateBasicFeeDTO) { - return this.manageFeeService.UPDATEBASICFEE(body) - } + @ApiTags('Manage Fee - Oracle') + @Patch('/UpdateBondRate') + UpdateBondRate(@Body() body: UpdateBondRateDTO) { + return this.manageFeeService.UPDATEBONDRATE(body); + } - @ApiTags('Manage Fee - Oracle') - @Patch('/UpdateBondRate') - UpdateBondRate(@Body() body: UpdateBondRateDTO) { - return this.manageFeeService.UPDATEBONDRATE(body) - } + @ApiTags('Manage Fee - Oracle') + @Patch('/UpdateCargoRate') + UpdateCargoRate(@Body() body: UpdateCargoRateDTO) { + return this.manageFeeService.UPDATECARGORATE(body); + } - @ApiTags('Manage Fee - Oracle') - @Patch('/UpdateCargoRate') - UpdateCargoRate(@Body() body: UpdateCargoRateDTO) { - return this.manageFeeService.UPDATECARGORATE(body) - } + @ApiTags('Manage Fee - Oracle') + @Patch('/UpdateCfFee') + UpdateCfFee(@Body() body: UpdateCfFeeDTO) { + return this.manageFeeService.UPDATECFFEE(body); + } - @ApiTags('Manage Fee - Oracle') - @Patch('/UpdateCfFee') - UpdateCfFee(@Body() body: UpdateCfFeeDTO) { - return this.manageFeeService.UPDATECFFEE(body) - } + @ApiTags('Manage Fee - Oracle') + @Patch('/UpdateCsFee') + UpdateCsFee(@Body() body: UpdateCsFeeDTO) { + return this.manageFeeService.UPDATECSFEE(body); + } - @ApiTags('Manage Fee - Oracle') - @Patch('/UpdateCsFee') - UpdateCsFee(@Body() body: UpdateCsFeeDTO) { - return this.manageFeeService.UPDATECSFEE(body) - } + @ApiTags('Manage Fee - Oracle') + @Patch('/UpdateEfFee') + UpdateEfFee(@Body() body: UpdateEfFeeDTO) { + return this.manageFeeService.UPDATEEFFEE(body); + } - @ApiTags('Manage Fee - Oracle') - @Patch('/UpdateEfFee') - UpdateEfFee(@Body() body: UpdateEfFeeDTO) { - return this.manageFeeService.UPDATEEFFEE(body) - } - - @ApiTags('Manage Fee - Oracle') - @Patch('/UpdateFeeComm') - UpdateFeeComm(@Body() body: UpdateFeeCommBodyDTO) { - return this.manageFeeService.UPDATEFEECOMM(body) - } + @ApiTags('Manage Fee - Oracle') + @Patch('/UpdateFeeComm') + UpdateFeeComm(@Body() body: UpdateFeeCommBodyDTO) { + return this.manageFeeService.UPDATEFEECOMM(body); + } } diff --git a/src/oracle/manage-fee/manage-fee.dto.ts b/src/oracle/manage-fee/manage-fee.dto.ts index cb721d3..a3bed95 100644 --- a/src/oracle/manage-fee/manage-fee.dto.ts +++ b/src/oracle/manage-fee/manage-fee.dto.ts @@ -1,360 +1,359 @@ -import { ApiProperty } from "@nestjs/swagger"; -import { Transform } from "class-transformer"; -import { IsDefined, IsInt, IsNumber, IsString, Min } from "class-validator"; +import { ApiProperty } from '@nestjs/swagger'; +import { Transform } from 'class-transformer'; +import { IsDefined, IsInt, IsNumber, IsString, Min } from 'class-validator'; export class GetFeeGeneralDTO { - @ApiProperty({ required: true }) - @Transform(({ value }) => Number(value)) - @Min(0, { message: "Property P_SPID must be at least 0" }) - @IsInt({ message: "Property P_SPID must be a whole number" }) - @IsNumber({}, { message: "Property P_SPID must be a number" }) - @IsDefined({ message: "Property P_SPID is required" }) - P_SPID: number; + @ApiProperty({ required: true }) + @Transform(({ value }) => Number(value)) + @Min(0, { message: 'Property P_SPID must be at least 0' }) + @IsInt({ message: 'Property P_SPID must be a whole number' }) + @IsNumber({}, { message: 'Property P_SPID must be a number' }) + @IsDefined({ message: 'Property P_SPID is required' }) + P_SPID: number; - @ApiProperty({ required: true }) - @IsString({ message: "Property P_ACTIVE_INACTIVE must be a string" }) - @IsDefined({ message: "Property P_ACTIVE_INACTIVE is required" }) - P_ACTIVE_INACTIVE: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property P_ACTIVE_INACTIVE must be a string' }) + @IsDefined({ message: 'Property P_ACTIVE_INACTIVE is required' }) + P_ACTIVE_INACTIVE: string; } export class CreateBasicFeeDTO { - @ApiProperty({ required: true }) - @IsNumber() - P_SPID: number; + @ApiProperty({ required: true }) + @IsNumber() + P_SPID: number; - @ApiProperty({ required: true }) - @IsNumber() - P_STARTCARNETVALUE: number; + @ApiProperty({ required: true }) + @IsNumber() + P_STARTCARNETVALUE: number; - @ApiProperty({ required: true }) - @IsNumber() - P_ENDCARNETVALUE: number; + @ApiProperty({ required: true }) + @IsNumber() + P_ENDCARNETVALUE: number; - @ApiProperty({ required: true }) - @IsString() - P_EFFDATE: string; + @ApiProperty({ required: true }) + @IsString() + P_EFFDATE: string; - @ApiProperty({ required: true }) - @IsNumber() - P_FEES: number; + @ApiProperty({ required: true }) + @IsNumber() + P_FEES: number; - @ApiProperty({ required: true }) - @IsString() - P_USERID: string; + @ApiProperty({ required: true }) + @IsString() + P_USERID: string; } export class CreateBondRateDTO { - @ApiProperty({ required: true }) - @IsNumber() - P_SPID: number; + @ApiProperty({ required: true }) + @IsNumber() + P_SPID: number; - @ApiProperty({ required: true }) - @IsString() - P_HOLDERTYPE: string; + @ApiProperty({ required: true }) + @IsString() + P_HOLDERTYPE: string; - @ApiProperty({ required: true }) - @IsString() - P_USCIBMEMBERFLAG: string; + @ApiProperty({ required: true }) + @IsString() + P_USCIBMEMBERFLAG: string; - @ApiProperty({ required: true }) - @IsString() - P_SPCLCOMMODITY: string; + @ApiProperty({ required: true }) + @IsString() + P_SPCLCOMMODITY: string; - @ApiProperty({ required: true }) - @IsString() - P_SPCLCOUNTRY: string; + @ApiProperty({ required: true }) + @IsString() + P_SPCLCOUNTRY: string; - @ApiProperty({ required: true }) - @IsString() - P_EFFDATE: string; + @ApiProperty({ required: true }) + @IsString() + P_EFFDATE: string; - @ApiProperty({ required: true }) - @IsNumber() - P_RATE: number; + @ApiProperty({ required: true }) + @IsNumber() + P_RATE: number; - @ApiProperty({ required: true }) - @IsString() - P_USERID: string; + @ApiProperty({ required: true }) + @IsString() + P_USERID: string; } export class CreateCargoRateDTO { - @ApiProperty({ required: true }) - @IsNumber() - P_SPID: number; + @ApiProperty({ required: true }) + @IsNumber() + P_SPID: number; - @ApiProperty({ required: true }) - @IsString() - P_CARNETTYPE: string; + @ApiProperty({ required: true }) + @IsString() + P_CARNETTYPE: string; - @ApiProperty({ required: true }) - @IsNumber() - P_STARTSETS: number; + @ApiProperty({ required: true }) + @IsNumber() + P_STARTSETS: number; - @ApiProperty({ required: true }) - @IsNumber() - P_ENDSETS: number; + @ApiProperty({ required: true }) + @IsNumber() + P_ENDSETS: number; - @ApiProperty({ required: true }) - @IsString() - P_EFFDATE: string; + @ApiProperty({ required: true }) + @IsString() + P_EFFDATE: string; - @ApiProperty({ required: true }) - @IsNumber() - P_RATE: number; + @ApiProperty({ required: true }) + @IsNumber() + P_RATE: number; - @ApiProperty({ required: true }) - @IsString() - P_USERID: string; + @ApiProperty({ required: true }) + @IsString() + P_USERID: string; } export class CreateCfFeeDTO { - @ApiProperty({ required: true }) - @IsNumber() - P_SPID: number; + @ApiProperty({ required: true }) + @IsNumber() + P_SPID: number; - @ApiProperty({ required: true }) - @IsNumber() - P_STARTSETS: number; + @ApiProperty({ required: true }) + @IsNumber() + P_STARTSETS: number; - @ApiProperty({ required: true }) - @IsNumber() - P_ENDSETS: number; + @ApiProperty({ required: true }) + @IsNumber() + P_ENDSETS: number; - @ApiProperty({ required: true }) - @IsString() - P_EFFDATE: string; + @ApiProperty({ required: true }) + @IsString() + P_EFFDATE: string; - @ApiProperty({ required: true }) - @IsString() - P_CUSTOMERTYPE: string; + @ApiProperty({ required: true }) + @IsString() + P_CUSTOMERTYPE: string; - @ApiProperty({ required: true }) - @IsString() - P_CARNETTYPE: string; + @ApiProperty({ required: true }) + @IsString() + P_CARNETTYPE: string; - @ApiProperty({ required: true }) - @IsNumber() - P_RATE: number; + @ApiProperty({ required: true }) + @IsNumber() + P_RATE: number; - @ApiProperty({ required: true }) - @IsString() - P_USERID: string; + @ApiProperty({ required: true }) + @IsString() + P_USERID: string; } export class CreateCsFeeDTO { - @ApiProperty({ required: true }) - @IsNumber() - P_SPID: number; + @ApiProperty({ required: true }) + @IsNumber() + P_SPID: number; - @ApiProperty({ required: true }) - @IsString() - P_CUSTOMERTYPE: string; + @ApiProperty({ required: true }) + @IsString() + P_CUSTOMERTYPE: string; - @ApiProperty({ required: true }) - @IsString() - P_CARNETTYPE: string; + @ApiProperty({ required: true }) + @IsString() + P_CARNETTYPE: string; - @ApiProperty({ required: true }) - @IsString() - P_EFFDATE: string; + @ApiProperty({ required: true }) + @IsString() + P_EFFDATE: string; - @ApiProperty({ required: true }) - @IsNumber() - P_RATE: number; + @ApiProperty({ required: true }) + @IsNumber() + P_RATE: number; - @ApiProperty({ required: true }) - @IsString() - P_USERID: string; + @ApiProperty({ required: true }) + @IsString() + P_USERID: string; } export class CreateEfFeeDTO { - @ApiProperty({ required: true }) - @IsNumber() - P_SPID: number; + @ApiProperty({ required: true }) + @IsNumber() + P_SPID: number; - @ApiProperty({ required: true }) - @IsString() - P_CUSTOMERTYPE: string; + @ApiProperty({ required: true }) + @IsString() + P_CUSTOMERTYPE: string; - @ApiProperty({ required: true }) - @IsString() - P_DELIVERYTYPE: string; + @ApiProperty({ required: true }) + @IsString() + P_DELIVERYTYPE: string; - @ApiProperty({ required: true }) - @IsNumber() - P_STARTTIME: number; + @ApiProperty({ required: true }) + @IsNumber() + P_STARTTIME: number; - @ApiProperty({ required: true }) - @IsNumber() - P_ENDTIME: number; + @ApiProperty({ required: true }) + @IsNumber() + P_ENDTIME: number; - @ApiProperty({ required: true }) - @IsString() - P_TIMEZONE: string; + @ApiProperty({ required: true }) + @IsString() + P_TIMEZONE: string; - @ApiProperty({ required: true }) - @IsString() - P_EFFDATE: string; + @ApiProperty({ required: true }) + @IsString() + P_EFFDATE: string; - @ApiProperty({ required: true }) - @IsNumber() - P_FEES: number; + @ApiProperty({ required: true }) + @IsNumber() + P_FEES: number; - @ApiProperty({ required: true }) - @IsString() - P_USERID: string; + @ApiProperty({ required: true }) + @IsString() + P_USERID: string; } export class CreateFeeCommDTO { - @ApiProperty({ required: true }) - @IsNumber() - P_SPID: number; + @ApiProperty({ required: true }) + @IsNumber() + P_SPID: number; - @ApiProperty({ required: true }) - @IsNumber() - P_PARAMID: number; + @ApiProperty({ required: true }) + @IsNumber() + P_PARAMID: number; - @ApiProperty({ required: true }) - @IsNumber() - P_COMMRATE: number; + @ApiProperty({ required: true }) + @IsNumber() + P_COMMRATE: number; - @ApiProperty({ required: true }) - @IsString() - P_EFFDATE: string; + @ApiProperty({ required: true }) + @IsString() + P_EFFDATE: string; - @ApiProperty({ required: true }) - @IsString() - P_USERID: string; + @ApiProperty({ required: true }) + @IsString() + P_USERID: string; } export class UpdateBasicFeeDTO { - @ApiProperty({ required: true }) - @IsNumber() - P_BASICFEESETUPID: number; + @ApiProperty({ required: true }) + @IsNumber() + P_BASICFEESETUPID: number; - @ApiProperty({ required: true }) - @IsNumber() - P_FEES: number; + @ApiProperty({ required: true }) + @IsNumber() + P_FEES: number; - @ApiProperty({ required: true }) - @IsString() - P_EFFDATE: string; + @ApiProperty({ required: true }) + @IsString() + P_EFFDATE: string; - @ApiProperty({ required: true }) - @IsString() - P_USERID: string; + @ApiProperty({ required: true }) + @IsString() + P_USERID: string; } export class UpdateBondRateDTO { - @ApiProperty({ required: true }) - @IsNumber() - P_BONDRATESETUPID: number; + @ApiProperty({ required: true }) + @IsNumber() + P_BONDRATESETUPID: number; - @ApiProperty({ required: true }) - @IsNumber() - P_RATE: number; + @ApiProperty({ required: true }) + @IsNumber() + P_RATE: number; - @ApiProperty({ required: true }) - @IsString() - P_EFFDATE: string; + @ApiProperty({ required: true }) + @IsString() + P_EFFDATE: string; - @ApiProperty({ required: true }) - @IsString() - P_USERID: string; + @ApiProperty({ required: true }) + @IsString() + P_USERID: string; } export class UpdateCargoRateDTO { - @ApiProperty({ required: true }) - @IsNumber() - P_CARGORATESETUPID: number; + @ApiProperty({ required: true }) + @IsNumber() + P_CARGORATESETUPID: number; - @ApiProperty({ required: true }) - @IsNumber() - P_RATE: number; + @ApiProperty({ required: true }) + @IsNumber() + P_RATE: number; - @ApiProperty({ required: true }) - @IsString() - P_EFFDATE: string; + @ApiProperty({ required: true }) + @IsString() + P_EFFDATE: string; - @ApiProperty({ required: true }) - @IsString() - P_USERID: string; + @ApiProperty({ required: true }) + @IsString() + P_USERID: string; } export class UpdateCfFeeDTO { - @ApiProperty({ required: true }) - @IsNumber() - P_CFFEESETUPID: number; + @ApiProperty({ required: true }) + @IsNumber() + P_CFFEESETUPID: number; - @ApiProperty({ required: true }) - @IsNumber() - P_RATE: number; + @ApiProperty({ required: true }) + @IsNumber() + P_RATE: number; - @ApiProperty({ required: true }) - @IsString() - P_EFFDATE: string; + @ApiProperty({ required: true }) + @IsString() + P_EFFDATE: string; - @ApiProperty({ required: true }) - @IsString() - P_USERID: string; + @ApiProperty({ required: true }) + @IsString() + P_USERID: string; } export class UpdateCsFeeDTO { - @ApiProperty({ required: true }) - @IsNumber() - P_CSFEESETUPID: number; + @ApiProperty({ required: true }) + @IsNumber() + P_CSFEESETUPID: number; - @ApiProperty({ required: true }) - @IsNumber() - P_RATE: number; + @ApiProperty({ required: true }) + @IsNumber() + P_RATE: number; - @ApiProperty({ required: true }) - @IsString() - P_EFFDATE: string; + @ApiProperty({ required: true }) + @IsString() + P_EFFDATE: string; - @ApiProperty({ required: true }) - @IsString() - P_USERID: string; + @ApiProperty({ required: true }) + @IsString() + P_USERID: string; } export class UpdateEfFeeDTO { - @ApiProperty({ required: true }) - @IsNumber() - P_EFFEESETUPID: number; + @ApiProperty({ required: true }) + @IsNumber() + P_EFFEESETUPID: number; - @ApiProperty({ required: true }) - @IsNumber() - P_FEES: number; + @ApiProperty({ required: true }) + @IsNumber() + P_FEES: number; - @ApiProperty({ required: true }) - @IsString() - P_EFFDATE: string; + @ApiProperty({ required: true }) + @IsString() + P_EFFDATE: string; - @ApiProperty({ required: true }) - @IsString() - P_USERID: string; + @ApiProperty({ required: true }) + @IsString() + P_USERID: string; } export class UpdateFeeCommDTO { + @ApiProperty({ required: true }) + @IsNumber() + P_FEECOMMID: number; - @ApiProperty({ required: true }) - @IsNumber() - P_FEECOMMID: number; + @ApiProperty({ required: true }) + @IsNumber() + P_RATE: number; - @ApiProperty({ required: true }) - @IsNumber() - P_RATE: number; + @ApiProperty({ required: true }) + @IsString() + P_EFFDATE: string; - @ApiProperty({ required: true }) - @IsString() - P_EFFDATE: string; - - @ApiProperty({ required: true }) - @IsString() - P_USERID: string; + @ApiProperty({ required: true }) + @IsString() + P_USERID: string; } export class UpdateFeeCommBodyDTO { - @ApiProperty({ type: UpdateFeeCommDTO, required: true }) // Correctly reference UpdateFeeCommDTO - p_fees_comm: UpdateFeeCommDTO; // No need for @IsObject() -} \ No newline at end of file + @ApiProperty({ type: UpdateFeeCommDTO, required: true }) // Correctly reference UpdateFeeCommDTO + p_fees_comm: UpdateFeeCommDTO; // No need for @IsObject() +} diff --git a/src/oracle/manage-fee/manage-fee.module.ts b/src/oracle/manage-fee/manage-fee.module.ts index a92b621..9cba161 100644 --- a/src/oracle/manage-fee/manage-fee.module.ts +++ b/src/oracle/manage-fee/manage-fee.module.ts @@ -4,6 +4,6 @@ import { ManageFeeService } from './manage-fee.service'; @Module({ controllers: [ManageFeeController], - providers: [ManageFeeService] + providers: [ManageFeeService], }) export class ManageFeeModule {} diff --git a/src/oracle/manage-fee/manage-fee.service.ts b/src/oracle/manage-fee/manage-fee.service.ts index d29df9c..df6ca6a 100644 --- a/src/oracle/manage-fee/manage-fee.service.ts +++ b/src/oracle/manage-fee/manage-fee.service.ts @@ -1,431 +1,429 @@ import { Injectable } from '@nestjs/common'; -import * as oracledb from 'oracledb' +import * as oracledb from 'oracledb'; import { OracleDBService } from 'src/db/db.service'; import { - CreateBasicFeeDTO, - CreateBondRateDTO, - CreateCargoRateDTO, - CreateCfFeeDTO, - CreateCsFeeDTO, - CreateEfFeeDTO, - CreateFeeCommDTO, - GetFeeGeneralDTO, - UpdateBasicFeeDTO, - UpdateBondRateDTO, - UpdateCargoRateDTO, - UpdateCfFeeDTO, - UpdateCsFeeDTO, - UpdateEfFeeDTO, - UpdateFeeCommBodyDTO + CreateBasicFeeDTO, + CreateBondRateDTO, + CreateCargoRateDTO, + CreateCfFeeDTO, + CreateCsFeeDTO, + CreateEfFeeDTO, + CreateFeeCommDTO, + GetFeeGeneralDTO, + UpdateBasicFeeDTO, + UpdateBondRateDTO, + UpdateCargoRateDTO, + UpdateCfFeeDTO, + UpdateCsFeeDTO, + UpdateEfFeeDTO, + UpdateFeeCommBodyDTO, } from './manage-fee.dto'; @Injectable() export class ManageFeeService { - constructor(private readonly oracleDBService: OracleDBService) { } + constructor(private readonly oracleDBService: OracleDBService) {} - // get + // get - async GETBASICFEERATES(body: GetFeeGeneralDTO) { - let connection; - let rows = []; - try { + async GETBASICFEERATES(body: GetFeeGeneralDTO) { + let connection; + let rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEFEE_SETUP_PKG.GETBASICFEERATES(:P_SPID,:P_ACTIVE_INACTIVE,:p_cursor); END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, + { + P_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, - P_ACTIVE_INACTIVE: { - val: body.P_ACTIVE_INACTIVE, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + P_ACTIVE_INACTIVE: { + val: body.P_ACTIVE_INACTIVE, + 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; - let rowsBatch; + 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); + 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'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } - - return rows; - - } catch (err) { - - return { error: err.message } - } finally { } + return rows; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - async GETBONDRATES(body: GetFeeGeneralDTO) { - let connection; - let rows = []; - try { + } + async GETBONDRATES(body: GetFeeGeneralDTO) { + let connection; + let rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEFEE_SETUP_PKG.GETBONDRATES(:P_SPID,:P_ACTIVE_INACTIVE,:p_cursor); END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_ACTIVE_INACTIVE: { - val: body.P_ACTIVE_INACTIVE, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + P_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_ACTIVE_INACTIVE: { + val: body.P_ACTIVE_INACTIVE, + 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; - let rowsBatch; + 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); + 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'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } - - return rows; - - } catch (err) { - - return { error: err.message } - } finally { } + return rows; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - async GETCARGORATES(body: GetFeeGeneralDTO) { - let connection; - let rows = []; - try { + } + async GETCARGORATES(body: GetFeeGeneralDTO) { + let connection; + let rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEFEE_SETUP_PKG.GETCARGORATES(:P_SPID,:P_ACTIVE_INACTIVE,:p_cursor); END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_ACTIVE_INACTIVE: { - val: body.P_ACTIVE_INACTIVE, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + P_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_ACTIVE_INACTIVE: { + val: body.P_ACTIVE_INACTIVE, + 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; - let rowsBatch; + 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); + 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'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } - - return rows; - - } catch (err) { - - return { error: err.message } - } finally { } + return rows; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - async GETCFFEERATES(body: GetFeeGeneralDTO) { - let connection; - let rows = []; - try { + } + async GETCFFEERATES(body: GetFeeGeneralDTO) { + let connection; + let rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEFEE_SETUP_PKG.GETCFFEERATES(:P_SPID,:P_ACTIVE_INACTIVE,:p_cursor); END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_ACTIVE_INACTIVE: { - val: body.P_ACTIVE_INACTIVE, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + P_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_ACTIVE_INACTIVE: { + val: body.P_ACTIVE_INACTIVE, + 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; - let rowsBatch; + 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); + 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'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } - - return rows; - - } catch (err) { - - return { error: err.message } - } finally { } + return rows; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - async GETCSFEERATES(body: GetFeeGeneralDTO) { - let connection; - let rows = []; - try { + } + async GETCSFEERATES(body: GetFeeGeneralDTO) { + let connection; + let rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEFEE_SETUP_PKG.GETCSFEERATES(:P_SPID,:P_ACTIVE_INACTIVE,:p_cursor); END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_ACTIVE_INACTIVE: { - val: body.P_ACTIVE_INACTIVE, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + P_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_ACTIVE_INACTIVE: { + val: body.P_ACTIVE_INACTIVE, + 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; - let rowsBatch; + 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); + 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'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } - - return rows; - - } catch (err) { - - return { error: err.message } - } finally { } + return rows; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - async GETEFFEERATES(body: GetFeeGeneralDTO) { - let connection; - let rows = []; - try { + } + async GETEFFEERATES(body: GetFeeGeneralDTO) { + let connection; + let rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEFEE_SETUP_PKG.GETEFFEERATES(:P_SPID,:P_ACTIVE_INACTIVE,:p_cursor); END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_ACTIVE_INACTIVE: { - val: body.P_ACTIVE_INACTIVE, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + P_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_ACTIVE_INACTIVE: { + val: body.P_ACTIVE_INACTIVE, + 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; - let rowsBatch; + 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); + 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'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } - - return rows; - - } catch (err) { - - return { error: err.message } - } finally { } + return rows; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - async GETFEECOMM(body: GetFeeGeneralDTO) { - let connection; - let rows = []; - try { + } + async GETFEECOMM(body: GetFeeGeneralDTO) { + let connection; + let rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEFEE_SETUP_PKG.GETFEECOMM(:P_SPID,:P_ACTIVE_INACTIVE,:p_cursor); END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_ACTIVE_INACTIVE: { - val: body.P_ACTIVE_INACTIVE, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + P_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_ACTIVE_INACTIVE: { + val: body.P_ACTIVE_INACTIVE, + 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; - let rowsBatch; + 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); + 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'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } - - return rows; - - } catch (err) { - - return { error: err.message } - } finally { } + return rows; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } - // post + // post - async CREATEBASICFEE(body: CreateBasicFeeDTO) { + async CREATEBASICFEE(body: CreateBasicFeeDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - let connection; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEFEE_SETUP_PKG.CREATEBASICFEE( :P_SPID, :P_STARTCARNETVALUE, @@ -435,63 +433,64 @@ export class ManageFeeService { :P_USERID, :P_CURSOR); END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER - }, - P_STARTCARNETVALUE: { - val: body.P_STARTCARNETVALUE, - type: oracledb.DB_TYPE_NUMBER - }, - P_ENDCARNETVALUE: { - val: body.P_ENDCARNETVALUE, - type: oracledb.DB_TYPE_NUMBER - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_VARCHAR - }, - P_FEES: { - val: body.P_FEES, - type: oracledb.DB_TYPE_NUMBER - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_VARCHAR - }, + { + P_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_STARTCARNETVALUE: { + val: body.P_STARTCARNETVALUE, + type: oracledb.DB_TYPE_NUMBER, + }, + P_ENDCARNETVALUE: { + val: body.P_ENDCARNETVALUE, + type: oracledb.DB_TYPE_NUMBER, + }, + P_EFFDATE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_FEES: { + val: body.P_FEES, + 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(); + 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) { - - return { error: err.message } - } finally { } + const fres = await result.outBinds.p_cursor.getRows(); + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - async CREATEBONDRATE(body: CreateBondRateDTO) { - let connection; - try { + } + async CREATEBONDRATE(body: CreateBondRateDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEFEE_SETUP_PKG.CREATEBONDRATE( :P_SPID, :P_HOLDERTYPE, @@ -503,69 +502,71 @@ export class ManageFeeService { :P_USERID, :P_CURSOR); END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER - }, - P_HOLDERTYPE: { - val: body.P_HOLDERTYPE, - type: oracledb.DB_TYPE_VARCHAR - }, - P_USCIBMEMBERFLAG: { - val: body.P_USCIBMEMBERFLAG, - type: oracledb.DB_TYPE_VARCHAR - }, - P_SPCLCOMMODITY: { - val: body.P_SPCLCOMMODITY, - type: oracledb.DB_TYPE_VARCHAR - }, - P_SPCLCOUNTRY: { - val: body.P_SPCLCOUNTRY, - type: oracledb.DB_TYPE_VARCHAR - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_VARCHAR - }, - P_RATE: { - val: body.P_RATE, - 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(); + { + P_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_HOLDERTYPE: { + val: body.P_HOLDERTYPE, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_USCIBMEMBERFLAG: { + val: body.P_USCIBMEMBERFLAG, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_SPCLCOMMODITY: { + val: body.P_SPCLCOMMODITY, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_SPCLCOUNTRY: { + val: body.P_SPCLCOUNTRY, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_EFFDATE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_RATE: { + val: body.P_RATE, + 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(); + const fres = await result.outBinds.p_cursor.getRows(); - return fres - - } catch (err) { - - return { error: err.message } - } finally { } + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - async CREATECARGORATE(body: CreateCargoRateDTO) { - let connection; - try { + } + async CREATECARGORATE(body: CreateCargoRateDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEFEE_SETUP_PKG.CREATECARGORATE( :P_SPID, :P_CARNETTYPE, @@ -576,66 +577,67 @@ export class ManageFeeService { :P_USERID, :P_CURSOR); END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER - }, - P_CARNETTYPE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_VARCHAR - }, - P_STARTSETS: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER - }, - P_ENDSETS: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_VARCHAR - }, - P_RATE: { - val: body.P_RATE, - 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(); + { + P_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_CARNETTYPE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_STARTSETS: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_ENDSETS: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_EFFDATE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_RATE: { + val: body.P_RATE, + 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(); + const fres = await result.outBinds.p_cursor.getRows(); - return fres - - } catch (err) { - - return { error: err.message } - } finally { } + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - async CREATECFFEE(body: CreateCfFeeDTO) { + } + async CREATECFFEE(body: CreateCfFeeDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - let connection; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEFEE_SETUP_PKG.CREATECFFEE( :P_SPID, :P_STARTSETS, @@ -647,70 +649,71 @@ export class ManageFeeService { :P_USERID, :P_CURSOR); END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER - }, - P_STARTSETS: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER - }, - P_ENDSETS: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_VARCHAR - }, - P_CUSTOMERTYPE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_VARCHAR - }, - P_CARNETTYPE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_VARCHAR - }, - P_RATE: { - val: body.P_RATE, - 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(); + { + P_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_STARTSETS: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_ENDSETS: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_EFFDATE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_CUSTOMERTYPE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_CARNETTYPE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_RATE: { + val: body.P_RATE, + 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) { - - return { error: err.message } - } finally { } + const fres = await result.outBinds.p_cursor.getRows(); + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - async CREATECSFEE(body: CreateCsFeeDTO) { - let connection; - try { + } + async CREATECSFEE(body: CreateCsFeeDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEFEE_SETUP_PKG.CREATECSFEE( :P_SPID, :P_CUSTOMERTYPE, @@ -720,61 +723,63 @@ export class ManageFeeService { :P_USERID, :P_CURSOR); END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER - }, - P_CUSTOMERTYPE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_VARCHAR - }, - P_CARNETTYPE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_VARCHAR - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_VARCHAR - }, - P_RATE: { - val: body.P_RATE, - 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(); + { + P_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_CUSTOMERTYPE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_CARNETTYPE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_EFFDATE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_RATE: { + val: body.P_RATE, + 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(); + const fres = await result.outBinds.p_cursor.getRows(); - return fres - - } catch (err) { - - return { error: err.message } - } finally { } + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - async CREATEEFFEE(body: CreateEfFeeDTO) { - let connection; - try { + } + async CREATEEFFEE(body: CreateEfFeeDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEFEE_SETUP_PKG.CREATEEFFEE( :P_SPID, :P_CUSTOMERTYPE, @@ -787,74 +792,75 @@ export class ManageFeeService { :P_USERID, :P_CURSOR); END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER - }, - P_CUSTOMERTYPE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_VARCHAR - }, - P_DELIVERYTYPE: { - val: body.P_DELIVERYTYPE, - type: oracledb.DB_TYPE_VARCHAR - }, - P_STARTTIME: { - val: body.P_STARTTIME, - type: oracledb.DB_TYPE_NUMBER - }, - P_ENDTIME: { - val: body.P_ENDTIME, - type: oracledb.DB_TYPE_NUMBER - }, - P_TIMEZONE: { - val: body.P_TIMEZONE, - type: oracledb.DB_TYPE_VARCHAR - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_VARCHAR - }, - P_FEES: { - val: body.P_FEES, - 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(); + { + P_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_CUSTOMERTYPE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_DELIVERYTYPE: { + val: body.P_DELIVERYTYPE, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_STARTTIME: { + val: body.P_STARTTIME, + type: oracledb.DB_TYPE_NUMBER, + }, + P_ENDTIME: { + val: body.P_ENDTIME, + type: oracledb.DB_TYPE_NUMBER, + }, + P_TIMEZONE: { + val: body.P_TIMEZONE, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_EFFDATE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_FEES: { + val: body.P_FEES, + 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(); + const fres = await result.outBinds.p_cursor.getRows(); - return fres - - } catch (err) { - - return { error: err.message } - } finally { } + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - async CREATEFEECOMM(body: CreateFeeCommDTO) { + } + async CREATEFEECOMM(body: CreateFeeCommDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - let connection; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEFEE_SETUP_PKG.CREATEFEECOMM( :P_SPID, :P_PARAMID, @@ -863,62 +869,62 @@ export class ManageFeeService { :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_NUMBER - }, - P_COMMRATE: { - val: body.P_COMMRATE, - type: oracledb.DB_TYPE_NUMBER - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_NVARCHAR - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_NVARCHAR - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); - await connection.commit(); + { + P_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_PARAMID: { + val: body.P_PARAMID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_COMMRATE: { + val: body.P_COMMRATE, + type: oracledb.DB_TYPE_NUMBER, + }, + P_EFFDATE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_USERID: { + val: body.P_USERID, + type: oracledb.DB_TYPE_NVARCHAR, + }, + 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) { - - return { error: err.message } - } finally { } + const fres = await result.outBinds.p_cursor.getRows(); + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } - // update + // update - async UPDATEBASICFEE(body: UpdateBasicFeeDTO) { + async UPDATEBASICFEE(body: UpdateBasicFeeDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - let connection; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEFEE_SETUP_PKG.UPDATEBASICFEE( :P_BASICFEESETUPID, :P_FEES, @@ -926,56 +932,55 @@ export class ManageFeeService { :P_USERID, :P_CURSOR); END;`, - { - P_BASICFEESETUPID: { - val: body.P_BASICFEESETUPID, - type: oracledb.DB_TYPE_NUMBER - }, - P_FEES: { - val: body.P_FEES, - type: oracledb.DB_TYPE_NUMBER - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_NVARCHAR - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_NVARCHAR - }, - 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) { - - return { error: err.message } - } finally { } + { + P_BASICFEESETUPID: { + val: body.P_BASICFEESETUPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_FEES: { + val: body.P_FEES, + type: oracledb.DB_TYPE_NUMBER, + }, + P_EFFDATE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_USERID: { + val: body.P_USERID, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_CURSOR: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + await connection.commit(); + const fres = await result.outBinds.p_cursor.getRows(); + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - async UPDATEBONDRATE(body: UpdateBondRateDTO) { + } + async UPDATEBONDRATE(body: UpdateBondRateDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - let connection; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEFEE_SETUP_PKG.UPDATEBONDRATE( :P_BONDRATESETUPID, :P_RATE, @@ -983,56 +988,55 @@ export class ManageFeeService { :P_USERID, :P_CURSOR); END;`, - { - P_BONDRATESETUPID: { - val: body.P_BONDRATESETUPID, - type: oracledb.DB_TYPE_NUMBER - }, - P_RATE: { - val: body.P_RATE, - type: oracledb.DB_TYPE_NUMBER - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_NVARCHAR - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_NVARCHAR - }, - 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) { - - return { error: err.message } - } finally { } + { + P_BONDRATESETUPID: { + val: body.P_BONDRATESETUPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_RATE: { + val: body.P_RATE, + type: oracledb.DB_TYPE_NUMBER, + }, + P_EFFDATE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_USERID: { + val: body.P_USERID, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_CURSOR: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + await connection.commit(); + const fres = await result.outBinds.p_cursor.getRows(); + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - async UPDATECARGORATE(body: UpdateCargoRateDTO) { + } + async UPDATECARGORATE(body: UpdateCargoRateDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - let connection; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEFEE_SETUP_PKG.UPDATECARGORATE( :P_CARGORATESETUPID, :P_RATE, @@ -1040,55 +1044,55 @@ export class ManageFeeService { :P_USERID, :P_CURSOR); END;`, - { - P_CARGORATESETUPID: { - val: body.P_CARGORATESETUPID, - type: oracledb.DB_TYPE_NUMBER - }, - P_RATE: { - val: body.P_RATE, - type: oracledb.DB_TYPE_NUMBER - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_NVARCHAR - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_NVARCHAR - }, - 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) { - - return { error: err.message } - } finally { } + { + P_CARGORATESETUPID: { + val: body.P_CARGORATESETUPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_RATE: { + val: body.P_RATE, + type: oracledb.DB_TYPE_NUMBER, + }, + P_EFFDATE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_USERID: { + val: body.P_USERID, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_CURSOR: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + await connection.commit(); + const fres = await result.outBinds.p_cursor.getRows(); + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - async UPDATECFFEE(body: UpdateCfFeeDTO) { - let connection; - try { + } + async UPDATECFFEE(body: UpdateCfFeeDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEFEE_SETUP_PKG.UPDATECFFEE( :P_CFFEESETUPID, :P_RATE, @@ -1096,56 +1100,55 @@ export class ManageFeeService { :P_USERID, :P_CURSOR); END;`, - { - P_CFFEESETUPID: { - val: body.P_CFFEESETUPID, - type: oracledb.DB_TYPE_NUMBER - }, - P_RATE: { - val: body.P_RATE, - type: oracledb.DB_TYPE_NUMBER - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_NVARCHAR - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_NVARCHAR - }, - 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) { - - return { error: err.message } - } finally { } + { + P_CFFEESETUPID: { + val: body.P_CFFEESETUPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_RATE: { + val: body.P_RATE, + type: oracledb.DB_TYPE_NUMBER, + }, + P_EFFDATE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_USERID: { + val: body.P_USERID, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_CURSOR: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + await connection.commit(); + const fres = await result.outBinds.p_cursor.getRows(); + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - async UPDATECSFEE(body: UpdateCsFeeDTO) { + } + async UPDATECSFEE(body: UpdateCsFeeDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - let connection; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEFEE_SETUP_PKG.UPDATECSFEE( :P_CSFEESETUPID, :P_RATE, @@ -1153,57 +1156,55 @@ export class ManageFeeService { :P_USERID, :P_CURSOR); END;`, - { - P_CSFEESETUPID: { - val: body.P_CSFEESETUPID, - type: oracledb.DB_TYPE_NUMBER - }, - P_RATE: { - val: body.P_RATE, - type: oracledb.DB_TYPE_NUMBER - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_NVARCHAR - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_NVARCHAR - }, - 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) { - - return { error: err.message } - } finally { } + { + P_CSFEESETUPID: { + val: body.P_CSFEESETUPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_RATE: { + val: body.P_RATE, + type: oracledb.DB_TYPE_NUMBER, + }, + P_EFFDATE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_USERID: { + val: body.P_USERID, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_CURSOR: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + await connection.commit(); + const fres = await result.outBinds.p_cursor.getRows(); + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - async UPDATEEFFEE(body: UpdateEfFeeDTO) { + } + async UPDATEEFFEE(body: UpdateEfFeeDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - - let connection; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEFEE_SETUP_PKG.UPDATEEFFEE( :P_EFFEESETUPID, :P_FEES, @@ -1211,55 +1212,55 @@ export class ManageFeeService { :P_USERID, :P_CURSOR); END;`, - { - P_EFFEESETUPID: { - val: body.P_EFFEESETUPID, - type: oracledb.DB_TYPE_NUMBER - }, - P_FEES: { - val: body.P_FEES, - type: oracledb.DB_TYPE_NUMBER - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_NVARCHAR - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_NVARCHAR - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); - await connection.commit(); + { + P_EFFEESETUPID: { + val: body.P_EFFEESETUPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_FEES: { + val: body.P_FEES, + type: oracledb.DB_TYPE_NUMBER, + }, + P_EFFDATE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_USERID: { + val: body.P_USERID, + type: oracledb.DB_TYPE_NVARCHAR, + }, + 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) { - - return { error: err.message } - } finally { } + const fres = await result.outBinds.p_cursor.getRows(); + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - async UPDATEFEECOMM(body: UpdateFeeCommBodyDTO) { + } + async UPDATEFEECOMM(body: UpdateFeeCommBodyDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - let connection; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEFEE_SETUP_PKG.UPDATEFEECOMM( :P_FEECOMMID, :P_RATE, @@ -1267,50 +1268,47 @@ export class ManageFeeService { :P_USERID, :P_CURSOR); END;`, - { - P_FEECOMMID: { - val: body.p_fees_comm.P_FEECOMMID, - type: oracledb.DB_TYPE_NUMBER - }, - P_RATE: { - val: Number(body.p_fees_comm.P_RATE) | 0, - type: oracledb.DB_TYPE_NUMBER - }, - P_EFFDATE: { - val: body.p_fees_comm.P_EFFDATE, - type: oracledb.DB_TYPE_NVARCHAR - }, - P_USERID: { - val: body.p_fees_comm.P_USERID, - type: oracledb.DB_TYPE_NVARCHAR - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); - await connection.commit(); + { + P_FEECOMMID: { + val: body.p_fees_comm.P_FEECOMMID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_RATE: { + val: Number(body.p_fees_comm.P_RATE) | 0, + type: oracledb.DB_TYPE_NUMBER, + }, + P_EFFDATE: { + val: body.p_fees_comm.P_EFFDATE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_USERID: { + val: body.p_fees_comm.P_USERID, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_CURSOR: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + await connection.commit(); - if (result.outBinds && result.outBinds.P_CURSOR) { - let fres = await result.outBinds.P_CURSOR.getRows(); + if (result.outBinds && result.outBinds.P_CURSOR) { + const fres = await result.outBinds.P_CURSOR.getRows(); - console.log("pcursor: ", fres); + console.log('pcursor: ', fres); - return fres - } - else { - console.log("No cursor returned...."); - return { error: "No cursor found" } - } - } catch (err) { - - return { error: err.message } - // return {error: err.message} - } finally { } + return fres; + } else { + console.log('No cursor returned....'); + return { error: 'No cursor found' }; + } + } catch (err) { + return { error: err.message }; + // return {error: err.message} } - - + } } diff --git a/src/oracle/manage-holders/manage-holders.controller.ts b/src/oracle/manage-holders/manage-holders.controller.ts index 89e47df..e9f63d6 100644 --- a/src/oracle/manage-holders/manage-holders.controller.ts +++ b/src/oracle/manage-holders/manage-holders.controller.ts @@ -1,95 +1,115 @@ -import { Body, Controller, Get, Param, ParseIntPipe, Patch, Post, Put, UsePipes, ValidationPipe } from '@nestjs/common'; +import { + Body, + Controller, + Get, + Param, + ParseIntPipe, + Patch, + Post, + Put, +} from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; -import { CreateHoldersDTO, GetHolderContactActivateOrInactivateDTO, GetHolderOrContactDTO, UpdateHolderContactDTO, UpdateHolderDTO } from './manage-holders.dto'; +import { + CreateHoldersDTO, + GetHolderContactActivateOrInactivateDTO, + GetHolderOrContactDTO, + UpdateHolderContactDTO, + UpdateHolderDTO, +} from './manage-holders.dto'; import { ManageHoldersService } from './manage-holders.service'; @Controller('oracle') export class ManageHoldersController { + constructor(private readonly manageHoldersService: ManageHoldersService) {} - constructor(private readonly manageHoldersService: ManageHoldersService) { } + @ApiTags('Manage Holders - Oracle') + @Post('/CreateHolderData') + CreateHolders(@Body() body: CreateHoldersDTO) { + return this.manageHoldersService.CreateHolders(body); + // return {message:"Request received.."} + } - @ApiTags('Manage Holders - Oracle') - @Post('/CreateHolderData') - CreateHolders(@Body() body: CreateHoldersDTO) { - return this.manageHoldersService.CreateHolders(body); - // return {message:"Request received.."} - } + @ApiTags('Manage Holders - Oracle') + @Put('/UpdateHolder') + UpdateHolder(@Body() body: UpdateHolderDTO) { + return this.manageHoldersService.UpdateHolder(body); + } - @ApiTags('Manage Holders - Oracle') - @Put('/UpdateHolder') - UpdateHolder(@Body() body: UpdateHolderDTO) { - return this.manageHoldersService.UpdateHolder(body); - } + @ApiTags('Manage Holders - Oracle') + @Put('/UpdateHolderContact') + UpdateHolderContact(@Body() body: UpdateHolderContactDTO) { + return this.manageHoldersService.UpdateHolderContact(body); + } - @ApiTags('Manage Holders - Oracle') - @Put('/UpdateHolderContact') - UpdateHolderContact(@Body() body: UpdateHolderContactDTO) { - return this.manageHoldersService.UpdateHolderContact(body); - } + @ApiTags('Manage Holders - Oracle') + @Get('/GetHolderRecord/:p_spid/:p_holderid') + GetHolderMaster( + @Param('p_spid', ParseIntPipe) p_spid: number, + @Param('p_holderid', ParseIntPipe) p_holderid: number, + ) { + const reqParams: GetHolderOrContactDTO = { p_spid, p_holderid }; - @ApiTags('Manage Holders - Oracle') - @Get('/GetHolderRecord/:p_spid/:p_holderid') - GetHolderMaster( - @Param('p_spid', ParseIntPipe) p_spid: number, - @Param('p_holderid', ParseIntPipe) p_holderid: number, - ){ - const reqParams:GetHolderOrContactDTO = {p_spid,p_holderid} + return this.manageHoldersService.GetHolderRecord(reqParams); + } - return this.manageHoldersService.GetHolderRecord(reqParams); - } - - @ApiTags('Manage Holders - Oracle') - @Get('/GetHolderContacts/:p_spid/:p_holderid') - GetHolderContacts( - @Param('p_spid', ParseIntPipe) p_spid: number, - @Param('p_holderid', ParseIntPipe) p_holderid: number, - ){ - const reqParams:GetHolderOrContactDTO = {p_spid,p_holderid} + @ApiTags('Manage Holders - Oracle') + @Get('/GetHolderContacts/:p_spid/:p_holderid') + GetHolderContacts( + @Param('p_spid', ParseIntPipe) p_spid: number, + @Param('p_holderid', ParseIntPipe) p_holderid: number, + ) { + const reqParams: GetHolderOrContactDTO = { p_spid, p_holderid }; - return this.manageHoldersService.GetHolderContacts(reqParams); - } + return this.manageHoldersService.GetHolderContacts(reqParams); + } - @ApiTags('Manage Holders - Oracle') - @Patch('/InactivateHolder/:p_spid/:p_holderid') - InactivateHolder( - @Param('p_spid', ParseIntPipe) p_spid: number, - @Param('p_holderid', ParseIntPipe) p_holderid: number, - ){ - const reqParams:GetHolderOrContactDTO = {p_spid,p_holderid} + @ApiTags('Manage Holders - Oracle') + @Patch('/InactivateHolder/:p_spid/:p_holderid') + InactivateHolder( + @Param('p_spid', ParseIntPipe) p_spid: number, + @Param('p_holderid', ParseIntPipe) p_holderid: number, + ) { + const reqParams: GetHolderOrContactDTO = { p_spid, p_holderid }; - return this.manageHoldersService.InactivateHolder(reqParams); - } + return this.manageHoldersService.InactivateHolder(reqParams); + } - @ApiTags('Manage Holders - Oracle') - @Patch('/ReactivateHolder/:p_spid/:p_holderid') - ReactivateHolder( - @Param('p_spid', ParseIntPipe) p_spid: number, - @Param('p_holderid', ParseIntPipe) p_holderid: number, - ){ - const reqParams:GetHolderOrContactDTO = {p_spid,p_holderid} + @ApiTags('Manage Holders - Oracle') + @Patch('/ReactivateHolder/:p_spid/:p_holderid') + ReactivateHolder( + @Param('p_spid', ParseIntPipe) p_spid: number, + @Param('p_holderid', ParseIntPipe) p_holderid: number, + ) { + const reqParams: GetHolderOrContactDTO = { p_spid, p_holderid }; - return this.manageHoldersService.ReactivateHolder(reqParams); - } + return this.manageHoldersService.ReactivateHolder(reqParams); + } - @ApiTags('Manage Holders - Oracle') - @Patch('/InactivateHolderContact/:p_spid/:p_holderContactid') - InactivateHolderContact( - @Param('p_spid', ParseIntPipe) p_spid: number, - @Param('p_holderContactid', ParseIntPipe) p_holderContactid: number, - ){ - const reqParams:GetHolderContactActivateOrInactivateDTO = {p_spid,p_holderContactid} + @ApiTags('Manage Holders - Oracle') + @Patch('/InactivateHolderContact/:p_spid/:p_holderContactid') + InactivateHolderContact( + @Param('p_spid', ParseIntPipe) p_spid: number, + @Param('p_holderContactid', ParseIntPipe) p_holderContactid: number, + ) { + const reqParams: GetHolderContactActivateOrInactivateDTO = { + p_spid, + p_holderContactid, + }; - return this.manageHoldersService.InactivateHolderContact(reqParams); - } + return this.manageHoldersService.InactivateHolderContact(reqParams); + } - @ApiTags('Manage Holders - Oracle') - @Patch('/ReactivateHolderContact/:p_spid/:p_holderContactid') - ReactivateHolderContact( - @Param('p_spid', ParseIntPipe) p_spid: number, - @Param('p_holderid', ParseIntPipe) p_holderContactid: number, - ){ - const reqParams:GetHolderContactActivateOrInactivateDTO = {p_spid,p_holderContactid} + @ApiTags('Manage Holders - Oracle') + @Patch('/ReactivateHolderContact/:p_spid/:p_holderContactid') + ReactivateHolderContact( + @Param('p_spid', ParseIntPipe) p_spid: number, + @Param('p_holderid', ParseIntPipe) p_holderContactid: number, + ) { + const reqParams: GetHolderContactActivateOrInactivateDTO = { + p_spid, + p_holderContactid, + }; - return this.manageHoldersService.ReactivateHolderContact(reqParams); - } + return this.manageHoldersService.ReactivateHolderContact(reqParams); + } } diff --git a/src/oracle/manage-holders/manage-holders.dto.ts b/src/oracle/manage-holders/manage-holders.dto.ts index 417901b..0b9fda3 100644 --- a/src/oracle/manage-holders/manage-holders.dto.ts +++ b/src/oracle/manage-holders/manage-holders.dto.ts @@ -1,381 +1,487 @@ import { ApiProperty } from '@nestjs/swagger'; import { Type } from 'class-transformer'; -import { IsString, IsNumber, IsOptional, ValidateNested, IsArray, IsDefined, Length, Max, Min, IsInt } from 'class-validator'; +import { + IsString, + IsNumber, + IsOptional, + ValidateNested, + IsArray, + IsDefined, + Length, + Max, + Min, + IsInt, +} from 'class-validator'; export class p_contactstableDTO { - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property FirstName must be between 0 to 50 characters" }) - @IsString({ message: "Property FirstName must be a string" }) - @IsDefined({ message: "Property FirstName is required" }) - FirstName: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property FirstName must be between 0 to 50 characters', + }) + @IsString({ message: 'Property FirstName must be a string' }) + @IsDefined({ message: 'Property FirstName is required' }) + FirstName: string; - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property LastName must be between 0 to 50 characters" }) - @IsString({ message: "Property LastName must be a string" }) - @IsDefined({ message: "Property LastName is required" }) - LastName: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property LastName must be between 0 to 50 characters', + }) + @IsString({ message: 'Property LastName must be a string' }) + @IsDefined({ message: 'Property LastName is required' }) + LastName: string; - @ApiProperty({ required: false }) - @Length(0, 3, { message: "Property MiddleInitial must be between 0 to 3 characters" }) - @IsString({ message: "Property MiddleInitial must be a string" }) - @IsOptional() - MiddleInitial?: string; + @ApiProperty({ required: false }) + @Length(0, 3, { + message: 'Property MiddleInitial must be between 0 to 3 characters', + }) + @IsString({ message: 'Property MiddleInitial must be a string' }) + @IsOptional() + MiddleInitial?: string; - @ApiProperty({ required: false }) - @Length(0, 50, { message: "Property Title must be between 0 to 50 characters" }) - @IsString({ message: "Property Title must be a string" }) - @IsOptional() - Title?: string; + @ApiProperty({ required: false }) + @Length(0, 50, { + message: 'Property Title must be between 0 to 50 characters', + }) + @IsString({ message: 'Property Title must be a string' }) + @IsOptional() + Title?: string; - @ApiProperty({ required: true }) - @Length(0, 100, { message: "Property EmailAddress must be between 0 to 100 characters" }) - @IsString({ message: "Property EmailAddress must be a string" }) - @IsDefined({ message: "Property EmailAddress is required" }) - EmailAddress: string; + @ApiProperty({ required: true }) + @Length(0, 100, { + message: 'Property EmailAddress must be between 0 to 100 characters', + }) + @IsString({ message: 'Property EmailAddress must be a string' }) + @IsDefined({ message: 'Property EmailAddress is required' }) + EmailAddress: string; - @ApiProperty({ required: true }) - @Length(0, 20, { message: "Property PhoneNo must be between 0 to 20 characters" }) - @IsString({ message: "Property PhoneNo must be a string" }) - @IsDefined({ message: "Property PhoneNo is required" }) - PhoneNo: string; + @ApiProperty({ required: true }) + @Length(0, 20, { + message: 'Property PhoneNo must be between 0 to 20 characters', + }) + @IsString({ message: 'Property PhoneNo must be a string' }) + @IsDefined({ message: 'Property PhoneNo is required' }) + PhoneNo: string; - @ApiProperty({ required: true }) - @Length(0, 20, { message: "Property MobileNo must be between 0 to 20 characters" }) - @IsString({ message: "Property MobileNo must be a string" }) - @IsDefined({ message: "Property MobileNo is required" }) - MobileNo: string; + @ApiProperty({ required: true }) + @Length(0, 20, { + message: 'Property MobileNo must be between 0 to 20 characters', + }) + @IsString({ message: 'Property MobileNo must be a string' }) + @IsDefined({ message: 'Property MobileNo is required' }) + MobileNo: string; - @ApiProperty({ required: false }) - @Length(0, 20, { message: "Property FaxNo must be between 0 to 20 characters" }) - @IsString({ message: "Property FaxNo must be a string" }) - @IsOptional() - FaxNo?: string; + @ApiProperty({ required: false }) + @Length(0, 20, { + message: 'Property FaxNo must be between 0 to 20 characters', + }) + @IsString({ message: 'Property FaxNo must be a string' }) + @IsOptional() + FaxNo?: string; } export class CreateHoldersDTO { - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_spid must not exceed 999999999" }) - @Min(0, { message: "Property p_spid must be at least 0 or more" }) - @IsInt({ message: "Property p_spid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_spid must be a number" }) - @IsDefined({ message: "Property p_spid is required" }) - p_spid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) + @Min(0, { message: 'Property p_spid must be at least 0 or more' }) + @IsInt({ message: 'Property p_spid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_spid must be a number' }) + @IsDefined({ message: 'Property p_spid is required' }) + p_spid: number; - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_clientlocationid must not exceed 999999999" }) - @Min(0, { message: "Property p_clientlocationid must be at least 0 or more" }) - @IsInt({ message: "Property p_clientlocationid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_clientlocationid must be a number" }) - @IsDefined({ message: "Property p_clientlocationid is required" }) - p_clientlocationid: number; + @ApiProperty({ required: true }) + @Max(999999999, { + message: 'Property p_clientlocationid must not exceed 999999999', + }) + @Min(0, { message: 'Property p_clientlocationid must be at least 0 or more' }) + @IsInt({ message: 'Property p_clientlocationid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_clientlocationid must be a number' }) + @IsDefined({ message: 'Property p_clientlocationid is required' }) + p_clientlocationid: number; - @ApiProperty({ required: true }) - @Length(0, 15, { message: "Property p_holderno must be between 0 to 15 characters" }) - @IsString({ message: "Property p_holderno must be a string" }) - @IsDefined({ message: "Property p_holderno is required" }) - p_holderno: string; + @ApiProperty({ required: true }) + @Length(0, 15, { + message: 'Property p_holderno must be between 0 to 15 characters', + }) + @IsString({ message: 'Property p_holderno must be a string' }) + @IsDefined({ message: 'Property p_holderno is required' }) + p_holderno: string; - @ApiProperty({ required: true }) - @Length(0, 3, { message: "Property p_holdertype must be between 0 to 3 characters" }) - @IsString({ message: "Property p_holdertype must be a string" }) - @IsDefined({ message: "Property p_holdertype is required" }) - p_holdertype: string; + @ApiProperty({ required: true }) + @Length(0, 3, { + message: 'Property p_holdertype must be between 0 to 3 characters', + }) + @IsString({ message: 'Property p_holdertype must be a string' }) + @IsDefined({ message: 'Property p_holdertype is required' }) + p_holdertype: string; - @ApiProperty({ required: true }) - @Length(0, 1, { message: "Property p_uscibmemberflag must be between 0 to 1 character" }) - @IsString({ message: "Property p_uscibmemberflag must be a string" }) - @IsDefined({ message: "Property p_uscibmemberflag is required" }) - p_uscibmemberflag: string; + @ApiProperty({ required: true }) + @Length(0, 1, { + message: 'Property p_uscibmemberflag must be between 0 to 1 character', + }) + @IsString({ message: 'Property p_uscibmemberflag must be a string' }) + @IsDefined({ message: 'Property p_uscibmemberflag is required' }) + p_uscibmemberflag: string; - @ApiProperty({ required: true }) - @Length(0, 1, { message: "Property p_govagencyflag must be between 0 to 1 character" }) - @IsString({ message: "Property p_govagencyflag must be a string" }) - @IsDefined({ message: "Property p_govagencyflag is required" }) - p_govagencyflag: string; + @ApiProperty({ required: true }) + @Length(0, 1, { + message: 'Property p_govagencyflag must be between 0 to 1 character', + }) + @IsString({ message: 'Property p_govagencyflag must be a string' }) + @IsDefined({ message: 'Property p_govagencyflag is required' }) + p_govagencyflag: string; - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property p_holdername must be between 0 to 50 characters" }) - @IsString({ message: "Property p_holdername must be a string" }) - @IsDefined({ message: "Property p_holdername is required" }) - p_holdername: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property p_holdername must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_holdername must be a string' }) + @IsDefined({ message: 'Property p_holdername is required' }) + p_holdername: string; - @ApiProperty({ required: false }) - @Length(0, 10, { message: "Property p_namequalifier must be between 0 to 10 characters" }) - @IsString({ message: "Property p_namequalifier must be a string" }) - @IsOptional() - p_namequalifier?: string; + @ApiProperty({ required: false }) + @Length(0, 10, { + message: 'Property p_namequalifier must be between 0 to 10 characters', + }) + @IsString({ message: 'Property p_namequalifier must be a string' }) + @IsOptional() + p_namequalifier?: string; - @ApiProperty({ required: false }) - @Length(0, 50, { message: "Property p_addlname must be between 0 to 50 characters" }) - @IsString({ message: "Property p_addlname must be a string" }) - @IsOptional() - p_addlname?: string; + @ApiProperty({ required: false }) + @Length(0, 50, { + message: 'Property p_addlname must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_addlname must be a string' }) + @IsOptional() + p_addlname?: string; - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property p_address1 must be between 0 to 50 characters" }) - @IsString({ message: "Property p_address1 must be a string" }) - @IsDefined({ message: "Property p_address1 is required" }) - p_address1: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property p_address1 must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_address1 must be a string' }) + @IsDefined({ message: 'Property p_address1 is required' }) + p_address1: string; - @ApiProperty({ required: false }) - @Length(0, 50, { message: "Property p_address2 must be between 0 to 50 characters" }) - @IsString({ message: "Property p_address2 must be a string" }) - @IsOptional() - p_address2?: string; + @ApiProperty({ required: false }) + @Length(0, 50, { + message: 'Property p_address2 must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_address2 must be a string' }) + @IsOptional() + p_address2?: string; - @ApiProperty({ required: true }) - @Length(0, 30, { message: "Property p_city must be between 0 to 30 characters" }) - @IsString({ message: "Property p_city must be a string" }) - @IsDefined({ message: "Property p_city is required" }) - p_city: string; + @ApiProperty({ required: true }) + @Length(0, 30, { + message: 'Property p_city must be between 0 to 30 characters', + }) + @IsString({ message: 'Property p_city must be a string' }) + @IsDefined({ message: 'Property p_city is required' }) + p_city: string; - @ApiProperty({ required: true }) - @Length(0, 2, { message: "Property p_state must be between 0 to 2 characters" }) - @IsString({ message: "Property p_state must be a string" }) - @IsDefined({ message: "Property p_state is required" }) - p_state: string; + @ApiProperty({ required: true }) + @Length(0, 2, { + message: 'Property p_state must be between 0 to 2 characters', + }) + @IsString({ message: 'Property p_state must be a string' }) + @IsDefined({ message: 'Property p_state is required' }) + p_state: string; - @ApiProperty({ required: true }) - @Length(0, 10, { message: "Property p_zip must be between 0 to 10 characters" }) - @IsString({ message: "Property p_zip must be a string" }) - @IsDefined({ message: "Property p_zip is required" }) - p_zip: string; + @ApiProperty({ required: true }) + @Length(0, 10, { + message: 'Property p_zip must be between 0 to 10 characters', + }) + @IsString({ message: 'Property p_zip must be a string' }) + @IsDefined({ message: 'Property p_zip is required' }) + p_zip: string; - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property p_country must be between 0 to 50 characters" }) - @IsString({ message: "Property p_country must be a string" }) - @IsDefined({ message: "Property p_country is required" }) - p_country: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property p_country must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_country must be a string' }) + @IsDefined({ message: 'Property p_country is required' }) + p_country: string; - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property p_userid must be between 0 to 50 characters" }) - @IsString({ message: "Property p_userid must be a string" }) - @IsDefined({ message: "Property p_userid is required" }) - p_userid: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property p_userid must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_userid must be a string' }) + @IsDefined({ message: 'Property p_userid is required' }) + p_userid: string; - @ApiProperty({ required: false, type: () => [p_contactstableDTO] }) - @Type(() => p_contactstableDTO) - @ValidateNested({ each: true }) - @IsArray({ message: "Property p_contactstable allows only array type" }) - @IsOptional() - p_contactstable?: p_contactstableDTO[]; + @ApiProperty({ required: false, type: () => [p_contactstableDTO] }) + @Type(() => p_contactstableDTO) + @ValidateNested({ each: true }) + @IsArray({ message: 'Property p_contactstable allows only array type' }) + @IsOptional() + p_contactstable?: p_contactstableDTO[]; } export class UpdateHolderDTO { - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_holderid must not exceed 999999999" }) - @Min(0, { message: "Property p_holderid must be at least 0 or more" }) - @IsInt({ message: "Property p_holderid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_holderid must be a number" }) - @IsDefined({ message: "Property p_holderid is required" }) - p_holderid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_holderid must not exceed 999999999' }) + @Min(0, { message: 'Property p_holderid must be at least 0 or more' }) + @IsInt({ message: 'Property p_holderid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_holderid must be a number' }) + @IsDefined({ message: 'Property p_holderid is required' }) + p_holderid: number; - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_spid must not exceed 999999999" }) - @Min(0, { message: "Property p_spid must be at least 0 or more" }) - @IsInt({ message: "Property p_spid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_spid must be a number" }) - @IsDefined({ message: "Property p_spid is required" }) - p_spid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) + @Min(0, { message: 'Property p_spid must be at least 0 or more' }) + @IsInt({ message: 'Property p_spid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_spid must be a number' }) + @IsDefined({ message: 'Property p_spid is required' }) + p_spid: number; - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_locationid must not exceed 999999999" }) - @Min(0, { message: "Property p_locationid must be at least 0 or more" }) - @IsInt({ message: "Property p_locationid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_locationid must be a number" }) - @IsDefined({ message: "Property p_locationid is required" }) - p_locationid: number; + @ApiProperty({ required: true }) + @Max(999999999, { + message: 'Property p_locationid must not exceed 999999999', + }) + @Min(0, { message: 'Property p_locationid must be at least 0 or more' }) + @IsInt({ message: 'Property p_locationid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_locationid must be a number' }) + @IsDefined({ message: 'Property p_locationid is required' }) + p_locationid: number; - @ApiProperty({ required: true }) - @Length(0, 15, { message: "Property p_holderno must be between 0 to 15 characters" }) - @IsString({ message: "Property p_holderno must be a string" }) - @IsDefined({ message: "Property p_holderno is required" }) - p_holderno: string; + @ApiProperty({ required: true }) + @Length(0, 15, { + message: 'Property p_holderno must be between 0 to 15 characters', + }) + @IsString({ message: 'Property p_holderno must be a string' }) + @IsDefined({ message: 'Property p_holderno is required' }) + p_holderno: string; - @ApiProperty({ required: true }) - @Length(0, 3, { message: "Property p_holdertype must be between 0 to 3 characters" }) - @IsString({ message: "Property p_holdertype must be a string" }) - @IsDefined({ message: "Property p_holdertype is required" }) - p_holdertype: string; + @ApiProperty({ required: true }) + @Length(0, 3, { + message: 'Property p_holdertype must be between 0 to 3 characters', + }) + @IsString({ message: 'Property p_holdertype must be a string' }) + @IsDefined({ message: 'Property p_holdertype is required' }) + p_holdertype: string; - @ApiProperty({ required: true }) - @Length(0, 1, { message: "Property p_uscibmemberflag must be between 0 to 1 character" }) - @IsString({ message: "Property p_uscibmemberflag must be a string" }) - @IsDefined({ message: "Property p_uscibmemberflag is required" }) - p_uscibmemberflag: string; + @ApiProperty({ required: true }) + @Length(0, 1, { + message: 'Property p_uscibmemberflag must be between 0 to 1 character', + }) + @IsString({ message: 'Property p_uscibmemberflag must be a string' }) + @IsDefined({ message: 'Property p_uscibmemberflag is required' }) + p_uscibmemberflag: string; - @ApiProperty({ required: true }) - @Length(0, 1, { message: "Property p_govagencyflag must be between 0 to 1 character" }) - @IsString({ message: "Property p_govagencyflag must be a string" }) - @IsDefined({ message: "Property p_govagencyflag is required" }) - p_govagencyflag: string; + @ApiProperty({ required: true }) + @Length(0, 1, { + message: 'Property p_govagencyflag must be between 0 to 1 character', + }) + @IsString({ message: 'Property p_govagencyflag must be a string' }) + @IsDefined({ message: 'Property p_govagencyflag is required' }) + p_govagencyflag: string; - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property p_holdername must be between 0 to 50 characters" }) - @IsString({ message: "Property p_holdername must be a string" }) - @IsDefined({ message: "Property p_holdername is required" }) - p_holdername: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property p_holdername must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_holdername must be a string' }) + @IsDefined({ message: 'Property p_holdername is required' }) + p_holdername: string; - @ApiProperty({ required: false }) - @Length(0, 10, { message: "Property p_namequalifier must be between 0 to 10 characters" }) - @IsString({ message: "Property p_namequalifier must be a string" }) - @IsOptional() - p_namequalifier?: string; + @ApiProperty({ required: false }) + @Length(0, 10, { + message: 'Property p_namequalifier must be between 0 to 10 characters', + }) + @IsString({ message: 'Property p_namequalifier must be a string' }) + @IsOptional() + p_namequalifier?: string; - @ApiProperty({ required: false }) - @Length(0, 50, { message: "Property p_addlname must be between 0 to 50 characters" }) - @IsString({ message: "Property p_addlname must be a string" }) - @IsOptional() - p_addlname?: string; + @ApiProperty({ required: false }) + @Length(0, 50, { + message: 'Property p_addlname must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_addlname must be a string' }) + @IsOptional() + p_addlname?: string; - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property p_address1 must be between 0 to 50 characters" }) - @IsString({ message: "Property p_address1 must be a string" }) - @IsDefined({ message: "Property p_address1 is required" }) - p_address1: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property p_address1 must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_address1 must be a string' }) + @IsDefined({ message: 'Property p_address1 is required' }) + p_address1: string; - @ApiProperty({ required: false }) - @Length(0, 50, { message: "Property p_address2 must be between 0 to 50 characters" }) - @IsString({ message: "Property p_address2 must be a string" }) - @IsOptional() - p_address2?: string; + @ApiProperty({ required: false }) + @Length(0, 50, { + message: 'Property p_address2 must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_address2 must be a string' }) + @IsOptional() + p_address2?: string; - @ApiProperty({ required: true }) - @Length(0, 30, { message: "Property p_city must be between 0 to 30 characters" }) - @IsString({ message: "Property p_city must be a string" }) - @IsDefined({ message: "Property p_city is required" }) - p_city: string; + @ApiProperty({ required: true }) + @Length(0, 30, { + message: 'Property p_city must be between 0 to 30 characters', + }) + @IsString({ message: 'Property p_city must be a string' }) + @IsDefined({ message: 'Property p_city is required' }) + p_city: string; - @ApiProperty({ required: true }) - @Length(0, 2, { message: "Property p_state must be between 0 to 2 characters" }) - @IsString({ message: "Property p_state must be a string" }) - @IsDefined({ message: "Property p_state is required" }) - p_state: string; + @ApiProperty({ required: true }) + @Length(0, 2, { + message: 'Property p_state must be between 0 to 2 characters', + }) + @IsString({ message: 'Property p_state must be a string' }) + @IsDefined({ message: 'Property p_state is required' }) + p_state: string; - @ApiProperty({ required: true }) - @Length(0, 10, { message: "Property p_zip must be between 0 to 10 characters" }) - @IsString({ message: "Property p_zip must be a string" }) - @IsDefined({ message: "Property p_zip is required" }) - p_zip: string; + @ApiProperty({ required: true }) + @Length(0, 10, { + message: 'Property p_zip must be between 0 to 10 characters', + }) + @IsString({ message: 'Property p_zip must be a string' }) + @IsDefined({ message: 'Property p_zip is required' }) + p_zip: string; - @ApiProperty({ required: true }) - @Length(0, 2, { message: "Property p_country must be between 0 to 2 characters" }) - @IsString({ message: "Property p_country must be a string" }) - @IsDefined({ message: "Property p_country is required" }) - p_country: string; + @ApiProperty({ required: true }) + @Length(0, 2, { + message: 'Property p_country must be between 0 to 2 characters', + }) + @IsString({ message: 'Property p_country must be a string' }) + @IsDefined({ message: 'Property p_country is required' }) + p_country: string; - @ApiProperty({ required: true }) - @Length(0, 100, { message: "Property p_userid must be between 0 to 100 characters" }) - @IsString({ message: "Property p_userid must be a string" }) - @IsDefined({ message: "Property p_userid is required" }) - p_userid: string; + @ApiProperty({ required: true }) + @Length(0, 100, { + message: 'Property p_userid must be between 0 to 100 characters', + }) + @IsString({ message: 'Property p_userid must be a string' }) + @IsDefined({ message: 'Property p_userid is required' }) + p_userid: string; } export class UpdateHolderContactDTO { - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_holdercontactid must not exceed 999999999" }) - @Min(0, { message: "Property p_holdercontactid must be at least 0 or more" }) - @IsInt({ message: "Property p_holdercontactid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_holdercontactid must be a number" }) - @IsDefined({ message: "Property p_holdercontactid is required" }) - p_holdercontactid: number; + @ApiProperty({ required: true }) + @Max(999999999, { + message: 'Property p_holdercontactid must not exceed 999999999', + }) + @Min(0, { message: 'Property p_holdercontactid must be at least 0 or more' }) + @IsInt({ message: 'Property p_holdercontactid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_holdercontactid must be a number' }) + @IsDefined({ message: 'Property p_holdercontactid is required' }) + p_holdercontactid: number; - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_spid must not exceed 999999999" }) - @Min(0, { message: "Property p_spid must be at least 0 or more" }) - @IsInt({ message: "Property p_spid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_spid must be a number" }) - @IsDefined({ message: "Property p_spid is required" }) - p_spid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) + @Min(0, { message: 'Property p_spid must be at least 0 or more' }) + @IsInt({ message: 'Property p_spid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_spid must be a number' }) + @IsDefined({ message: 'Property p_spid is required' }) + p_spid: number; - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property p_firstname must be between 0 to 50 characters" }) - @IsString({ message: "Property p_firstname must be a string" }) - @IsDefined({ message: "Property p_firstname is required" }) - p_firstname: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property p_firstname must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_firstname must be a string' }) + @IsDefined({ message: 'Property p_firstname is required' }) + p_firstname: string; - @ApiProperty({ required: true }) - @Length(0, 50, { message: "Property p_lastname must be between 0 to 50 characters" }) - @IsString({ message: "Property p_lastname must be a string" }) - @IsDefined({ message: "Property p_lastname is required" }) - p_lastname: string; + @ApiProperty({ required: true }) + @Length(0, 50, { + message: 'Property p_lastname must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_lastname must be a string' }) + @IsDefined({ message: 'Property p_lastname is required' }) + p_lastname: string; - @ApiProperty({ required: false }) - @Length(0, 3, { message: "Property p_middleinitial must be between 0 to 3 characters" }) - @IsString({ message: "Property p_middleinitial must be a string" }) - @IsOptional() - p_middleinitial?: string; + @ApiProperty({ required: false }) + @Length(0, 3, { + message: 'Property p_middleinitial must be between 0 to 3 characters', + }) + @IsString({ message: 'Property p_middleinitial must be a string' }) + @IsOptional() + p_middleinitial?: string; - @ApiProperty({ required: false }) - @Length(0, 50, { message: "Property p_title must be between 0 to 50 characters" }) - @IsString({ message: "Property p_title must be a string" }) - @IsOptional() - p_title?: string; + @ApiProperty({ required: false }) + @Length(0, 50, { + message: 'Property p_title must be between 0 to 50 characters', + }) + @IsString({ message: 'Property p_title must be a string' }) + @IsOptional() + p_title?: string; - @ApiProperty({ required: true }) - @Length(0, 20, { message: "Property p_phone must be between 0 to 20 characters" }) - @IsString({ message: "Property p_phone must be a string" }) - @IsDefined({ message: "Property p_phone is required" }) - p_phone: string; + @ApiProperty({ required: true }) + @Length(0, 20, { + message: 'Property p_phone must be between 0 to 20 characters', + }) + @IsString({ message: 'Property p_phone must be a string' }) + @IsDefined({ message: 'Property p_phone is required' }) + p_phone: string; - @ApiProperty({ required: true }) - @Length(0, 20, { message: "Property p_mobile must be between 0 to 20 characters" }) - @IsString({ message: "Property p_mobile must be a string" }) - @IsDefined({ message: "Property p_mobile is required" }) - p_mobile: string; + @ApiProperty({ required: true }) + @Length(0, 20, { + message: 'Property p_mobile must be between 0 to 20 characters', + }) + @IsString({ message: 'Property p_mobile must be a string' }) + @IsDefined({ message: 'Property p_mobile is required' }) + p_mobile: string; - @ApiProperty({ required: false }) - @Length(0, 20, { message: "Property p_fax must be between 0 to 20 characters" }) - @IsString({ message: "Property p_fax must be a string" }) - @IsOptional() - p_fax?: string; + @ApiProperty({ required: false }) + @Length(0, 20, { + message: 'Property p_fax must be between 0 to 20 characters', + }) + @IsString({ message: 'Property p_fax must be a string' }) + @IsOptional() + p_fax?: string; - @ApiProperty({ required: true }) - @Length(0, 100, { message: "Property p_emailaddress must be between 0 to 100 characters" }) - @IsString({ message: "Property p_emailaddress must be a string" }) - @IsDefined({ message: "Property p_emailaddress is required" }) - p_emailaddress: string; + @ApiProperty({ required: true }) + @Length(0, 100, { + message: 'Property p_emailaddress must be between 0 to 100 characters', + }) + @IsString({ message: 'Property p_emailaddress must be a string' }) + @IsDefined({ message: 'Property p_emailaddress is required' }) + p_emailaddress: string; - @ApiProperty({ required: true }) - @Length(0, 100, { message: "Property p_userid must be between 0 to 100 characters" }) - @IsString({ message: "Property p_userid must be a string" }) - @IsDefined({ message: "Property p_userid is required" }) - p_userid: string; + @ApiProperty({ required: true }) + @Length(0, 100, { + message: 'Property p_userid must be between 0 to 100 characters', + }) + @IsString({ message: 'Property p_userid must be a string' }) + @IsDefined({ message: 'Property p_userid is required' }) + p_userid: string; } export class GetHolderOrContactDTO { - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_spid must not exceed 999999999" }) - @Min(0, { message: "Property p_spid must be at least 0 or more" }) - @IsInt({ message: "Property p_spid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_spid must be a number" }) - @IsDefined({ message: "Property p_spid is required" }) - p_spid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) + @Min(0, { message: 'Property p_spid must be at least 0 or more' }) + @IsInt({ message: 'Property p_spid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_spid must be a number' }) + @IsDefined({ message: 'Property p_spid is required' }) + p_spid: number; - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_holderid must not exceed 999999999" }) - @Min(0, { message: "Property p_holderid must be at least 0 or more" }) - @IsInt({ message: "Property p_holderid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_holderid must be a number" }) - @IsDefined({ message: "Property p_holderid is required" }) - p_holderid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_holderid must not exceed 999999999' }) + @Min(0, { message: 'Property p_holderid must be at least 0 or more' }) + @IsInt({ message: 'Property p_holderid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_holderid must be a number' }) + @IsDefined({ message: 'Property p_holderid is required' }) + p_holderid: number; } export class GetHolderContactActivateOrInactivateDTO { - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_spid must not exceed 999999999" }) - @Min(0, { message: "Property p_spid must be at least 0 or more" }) - @IsInt({ message: "Property p_spid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_spid must be a number" }) - @IsDefined({ message: "Property p_spid is required" }) - p_spid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) + @Min(0, { message: 'Property p_spid must be at least 0 or more' }) + @IsInt({ message: 'Property p_spid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_spid must be a number' }) + @IsDefined({ message: 'Property p_spid is required' }) + p_spid: number; - @ApiProperty({ required: true }) - @Max(999999999, { message: "Property p_holderid must not exceed 999999999" }) - @Min(0, { message: "Property p_holderid must be at least 0 or more" }) - @IsInt({ message: "Property p_holderid allows only whole numbers" }) - @IsNumber({}, { message: "Property p_holderid must be a number" }) - @IsDefined({ message: "Property p_holderid is required" }) - p_holderContactid: number; + @ApiProperty({ required: true }) + @Max(999999999, { message: 'Property p_holderid must not exceed 999999999' }) + @Min(0, { message: 'Property p_holderid must be at least 0 or more' }) + @IsInt({ message: 'Property p_holderid allows only whole numbers' }) + @IsNumber({}, { message: 'Property p_holderid must be a number' }) + @IsDefined({ message: 'Property p_holderid is required' }) + p_holderContactid: number; } - diff --git a/src/oracle/manage-holders/manage-holders.module.ts b/src/oracle/manage-holders/manage-holders.module.ts index 730e36f..ee3435e 100644 --- a/src/oracle/manage-holders/manage-holders.module.ts +++ b/src/oracle/manage-holders/manage-holders.module.ts @@ -4,8 +4,8 @@ import { ManageHoldersController } from './manage-holders.controller'; import { DbModule } from 'src/db/db.module'; @Module({ - imports:[DbModule], + imports: [DbModule], providers: [ManageHoldersService], - controllers: [ManageHoldersController] + controllers: [ManageHoldersController], }) export class ManageHoldersModule {} diff --git a/src/oracle/manage-holders/manage-holders.service.ts b/src/oracle/manage-holders/manage-holders.service.ts index 34a0dfd..02348c0 100644 --- a/src/oracle/manage-holders/manage-holders.service.ts +++ b/src/oracle/manage-holders/manage-holders.service.ts @@ -1,99 +1,129 @@ import { Injectable } from '@nestjs/common'; import { OracleDBService } from 'src/db/db.service'; -import { CreateHoldersDTO, GetHolderContactActivateOrInactivateDTO, GetHolderOrContactDTO, p_contactstableDTO, UpdateHolderContactDTO, UpdateHolderDTO } from './manage-holders.dto'; -import * as oracledb from 'oracledb' +import { + CreateHoldersDTO, + GetHolderContactActivateOrInactivateDTO, + GetHolderOrContactDTO, + p_contactstableDTO, + UpdateHolderContactDTO, + UpdateHolderDTO, +} from './manage-holders.dto'; +import * as oracledb from 'oracledb'; @Injectable() export class ManageHoldersService { + constructor(private readonly oracleDBService: OracleDBService) {} - constructor(private readonly oracleDBService: OracleDBService) { } + CreateHolders = async (body: CreateHoldersDTO) => { + const newBody = { + p_spid: null, + p_clientlocationid: null, + p_holderno: null, + p_holdertype: null, + p_uscibmemberflag: null, + p_govagencyflag: null, + p_holdername: null, + p_namequalifier: null, + p_addlname: null, + p_address1: null, + p_address2: null, + p_city: null, + p_state: null, + p_zip: null, + p_country: null, + p_userid: null, + p_contactstable: null, + }; - CreateHolders = async (body: CreateHoldersDTO) => { + const reqBody = JSON.parse(JSON.stringify(body)); - let newBody = { - "p_spid": null, - "p_clientlocationid": null, - "p_holderno": null, - "p_holdertype": null, - "p_uscibmemberflag": null, - "p_govagencyflag": null, - "p_holdername": null, - "p_namequalifier": null, - "p_addlname": null, - "p_address1": null, - "p_address2": null, - "p_city": null, - "p_state": null, - "p_zip": null, - "p_country": null, - "p_userid": null, - "p_contactstable": null + function setEmptyStringsToNull(obj) { + Object.keys(obj).forEach((key) => { + if (typeof obj[key] === 'object' && obj[key] !== null) { + setEmptyStringsToNull(obj[key]); + } else if (obj[key] === '') { + obj[key] = null; } + }); + } - let reqBody = JSON.parse(JSON.stringify(body)); + setEmptyStringsToNull(reqBody); - function setEmptyStringsToNull(obj) { - Object.keys(obj).forEach(key => { - if (typeof obj[key] === 'object' && obj[key] !== null) { - setEmptyStringsToNull(obj[key]); - } else if (obj[key] === "") { - obj[key] = null; - } - }); - } + const finalBody: CreateHoldersDTO = { ...newBody, ...reqBody }; - setEmptyStringsToNull(reqBody); + let connection; + let p_holdercursor_rows = []; + let p_holdercontactcursor_rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - const finalBody: CreateHoldersDTO = { ...newBody, ...reqBody }; + // let res = await connection.execute(`SELECT owner, type_name FROM all_types WHERE type_name LIKE '%CONTACT%'`); - let connection; - let p_holdercursor_rows = []; - let p_holdercontactcursor_rows = []; - try { + // return { res:res.rows }; - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } + // const CONTACTSARRAY = await connection.getDbObjectClass('CARNETSYS.CONTACTSARRAY'); + const CONTACTSTABLE = await connection.getDbObjectClass( + 'CARNETSYS.CONTACTSTABLE', + ); - // let res = await connection.execute(`SELECT owner, type_name FROM all_types WHERE type_name LIKE '%CONTACT%'`); + // Check if GLTABLE is a constructor + if (typeof CONTACTSTABLE !== 'function') { + throw new Error('CONTACTSTABLE is not a constructor'); + } - // return { res:res.rows }; + async function CREATECONTACTSTABLE_INSTANCE( + connection, + FirstName, + LastName, + MiddleInitial, + Title, + EmailAddress, + PhoneNo, + MobileNo, + FaxNo, + ) { + const result = await connection.execute( + `SELECT CARNETSYS.CONTACTSARRAY(:FirstName, :LastName, :MiddleInitial, :Title, :EmailAddress, :PhoneNo, :MobileNo, :FaxNo) FROM dual`, + { + FirstName, + LastName, + MiddleInitial, + Title, + EmailAddress, + PhoneNo, + MobileNo, + FaxNo, + }, + ); + return result.rows[0][0]; + } - // const CONTACTSARRAY = await connection.getDbObjectClass('CARNETSYS.CONTACTSARRAY'); - const CONTACTSTABLE = await connection.getDbObjectClass('CARNETSYS.CONTACTSTABLE'); + const CONTACTSARRAY = finalBody.p_contactstable + ? await Promise.all( + finalBody.p_contactstable.map(async (x: p_contactstableDTO) => { + return await CREATECONTACTSTABLE_INSTANCE( + connection, + x.FirstName, + x.LastName, + x.MiddleInitial, + x.Title, + x.EmailAddress, + x.PhoneNo, + x.MobileNo, + x.FaxNo, + ); + }), + ) + : []; - // Check if GLTABLE is a constructor - if (typeof CONTACTSTABLE !== 'function') { - throw new Error('CONTACTSTABLE is not a constructor'); - } + // Create an instance of GLTABLE + const CONTACTSTABLE_INSTANCE = new CONTACTSTABLE(CONTACTSARRAY); - async function CREATECONTACTSTABLE_INSTANCE(connection, FirstName, LastName, MiddleInitial, Title, EmailAddress, PhoneNo, MobileNo, FaxNo) { - const result = await connection.execute( - `SELECT CARNETSYS.CONTACTSARRAY(:FirstName, :LastName, :MiddleInitial, :Title, :EmailAddress, :PhoneNo, :MobileNo, :FaxNo) FROM dual`, - { - FirstName, - LastName, - MiddleInitial, - Title, - EmailAddress, - PhoneNo, - MobileNo, - FaxNo - } - ); - return result.rows[0][0]; - } - - const CONTACTSARRAY = finalBody.p_contactstable ? await Promise.all(finalBody.p_contactstable.map(async (x: p_contactstableDTO) => { - return await CREATECONTACTSTABLE_INSTANCE(connection, x.FirstName, x.LastName, x.MiddleInitial, x.Title, x.EmailAddress, x.PhoneNo, x.MobileNo, x.FaxNo); - })) : []; - - // Create an instance of GLTABLE - const CONTACTSTABLE_INSTANCE = new CONTACTSTABLE(CONTACTSARRAY); - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEHOLDER_PKG.CreateHolderData( :p_spid, :p_clientlocationid, @@ -116,181 +146,188 @@ export class ManageHoldersService { :p_holdercontactcursor ); END;`, - { - p_spid: { - val: finalBody.p_spid ? finalBody.p_spid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_clientlocationid: { - val: finalBody.p_clientlocationid ? finalBody.p_clientlocationid : null, - type: oracledb.DB_TYPE_NUMBER - }, + { + p_spid: { + val: finalBody.p_spid ? finalBody.p_spid : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_clientlocationid: { + val: finalBody.p_clientlocationid + ? finalBody.p_clientlocationid + : null, + type: oracledb.DB_TYPE_NUMBER, + }, - p_holderno: { - val: finalBody.p_holderno ? finalBody.p_holderno : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_holdertype: { - val: finalBody.p_holdertype ? finalBody.p_holdertype : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_uscibmemberflag: { - val: finalBody.p_uscibmemberflag ? finalBody.p_uscibmemberflag : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_govagencyflag: { - val: finalBody.p_govagencyflag ? finalBody.p_govagencyflag : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_holdername: { - val: finalBody.p_holdername ? finalBody.p_holdername : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_namequalifier: { - val: finalBody.p_namequalifier ? finalBody.p_namequalifier : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_addlname: { - val: finalBody.p_addlname ? finalBody.p_addlname : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_address1: { - val: finalBody.p_address1 ? finalBody.p_address1 : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_address2: { - val: finalBody.p_address2 ? finalBody.p_address2 : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_city: { - val: finalBody.p_city ? finalBody.p_city : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_state: { - val: finalBody.p_state ? finalBody.p_state : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_zip: { - val: finalBody.p_zip ? finalBody.p_zip : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_country: { - val: finalBody.p_country ? finalBody.p_country : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_userid: { - val: finalBody.p_userid ? finalBody.p_userid : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_contactstable: { - val: CONTACTSTABLE_INSTANCE, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_holdercursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - }, - p_holdercontactcursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + p_holderno: { + val: finalBody.p_holderno ? finalBody.p_holderno : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_holdertype: { + val: finalBody.p_holdertype ? finalBody.p_holdertype : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_uscibmemberflag: { + val: finalBody.p_uscibmemberflag + ? finalBody.p_uscibmemberflag + : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_govagencyflag: { + val: finalBody.p_govagencyflag ? finalBody.p_govagencyflag : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_holdername: { + val: finalBody.p_holdername ? finalBody.p_holdername : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_namequalifier: { + val: finalBody.p_namequalifier ? finalBody.p_namequalifier : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_addlname: { + val: finalBody.p_addlname ? finalBody.p_addlname : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_address1: { + val: finalBody.p_address1 ? finalBody.p_address1 : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_address2: { + val: finalBody.p_address2 ? finalBody.p_address2 : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_city: { + val: finalBody.p_city ? finalBody.p_city : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_state: { + val: finalBody.p_state ? finalBody.p_state : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_zip: { + val: finalBody.p_zip ? finalBody.p_zip : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_country: { + val: finalBody.p_country ? finalBody.p_country : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_userid: { + val: finalBody.p_userid ? finalBody.p_userid : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_contactstable: { + val: CONTACTSTABLE_INSTANCE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_holdercursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + p_holdercontactcursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); - await connection.commit(); + await connection.commit(); - // let fres = await result.outBinds.P_cursor.getRows(); + // let fres = await result.outBinds.P_cursor.getRows(); - if (result.outBinds && result.outBinds.p_holdercursor) { - const cursor = result.outBinds.p_holdercursor; - let rowsBatch; + if (result.outBinds && result.outBinds.p_holdercursor) { + const cursor = result.outBinds.p_holdercursor; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); - p_holdercursor_rows = p_holdercursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + do { + rowsBatch = await cursor.getRows(100); + p_holdercursor_rows = p_holdercursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + await cursor.close(); + } else { + throw new Error('No cursor returned from the stored procedure'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } + if (result.outBinds && result.outBinds.p_holdercontactcursor) { + const cursor = result.outBinds.p_holdercontactcursor; + let rowsBatch; - if (result.outBinds && result.outBinds.p_holdercontactcursor) { - const cursor = result.outBinds.p_holdercontactcursor; - let rowsBatch; + do { + rowsBatch = await cursor.getRows(100); + p_holdercontactcursor_rows = + p_holdercontactcursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); - do { - rowsBatch = await cursor.getRows(100); - p_holdercontactcursor_rows = p_holdercontactcursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + await cursor.close(); + } else { + throw new Error('No cursor returned from the stored procedure'); + } + return { + p_holdercursor: p_holdercursor_rows, + p_holdercontactcursor: p_holdercontactcursor_rows, + }; - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } - - return { p_holdercursor: p_holdercursor_rows, p_holdercontactcursor: p_holdercontactcursor_rows }; - - // return fres - - } catch (err) { - - return { error: err.message } - } finally { } - + // return fres + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - UpdateHolder = async (body: UpdateHolderDTO) => { - let newBody = { - "p_holderid": null, - "p_spid": null, - "p_locationid": null, - "p_holderno": null, - "p_holdertype": null, - "p_uscibmemberflag": null, - "p_govagencyflag": null, - "p_holdername": null, - "p_namequalifier": null, - "p_addlname": null, - "p_address1": null, - "p_address2": null, - "p_city": null, - "p_state": null, - "p_zip": null, - "p_country": null, - "p_userid": null + }; + UpdateHolder = async (body: UpdateHolderDTO) => { + const newBody = { + p_holderid: null, + p_spid: null, + p_locationid: null, + p_holderno: null, + p_holdertype: null, + p_uscibmemberflag: null, + p_govagencyflag: null, + p_holdername: null, + p_namequalifier: null, + p_addlname: null, + p_address1: null, + p_address2: null, + p_city: null, + p_state: null, + p_zip: null, + p_country: null, + p_userid: null, + }; + + const reqBody = JSON.parse(JSON.stringify(body)); + + function setEmptyStringsToNull(obj) { + Object.keys(obj).forEach((key) => { + if (typeof obj[key] === 'object' && obj[key] !== null) { + setEmptyStringsToNull(obj[key]); + } else if (obj[key] === '') { + obj[key] = null; } + }); + } - let reqBody = JSON.parse(JSON.stringify(body)); + setEmptyStringsToNull(reqBody); - function setEmptyStringsToNull(obj) { - Object.keys(obj).forEach(key => { - if (typeof obj[key] === 'object' && obj[key] !== null) { - setEmptyStringsToNull(obj[key]); - } else if (obj[key] === "") { - obj[key] = null; - } - }); - } + const finalBody = { ...newBody, ...reqBody }; - setEmptyStringsToNull(reqBody); + let connection; + let P_cursor_rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - const finalBody = { ...newBody, ...reqBody }; - - let connection; - let P_cursor_rows = []; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEHOLDER_PKG.UpdateHolders( :p_holderid, :p_spid, @@ -312,213 +349,214 @@ export class ManageHoldersService { :P_cursor ); END;`, - { - p_holderid: { - val: finalBody.p_holderid ? finalBody.p_holderid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_spid: { - val: finalBody.p_spid ? finalBody.p_spid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_locationid: { - val: finalBody.p_locationid ? finalBody.p_locationid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_holderno: { - val: finalBody.p_holderno ? finalBody.p_holderno : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_holdertype: { - val: finalBody.p_holdertype ? finalBody.p_holdertype : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_uscibmemberflag: { - val: finalBody.p_uscibmemberflag ? finalBody.p_uscibmemberflag : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_govagencyflag: { - val: finalBody.p_govagencyflag ? finalBody.p_govagencyflag : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_holdername: { - val: finalBody.p_holdername ? finalBody.p_holdername : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_namequalifier: { - val: finalBody.p_namequalifier ? finalBody.p_namequalifier : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_addlname: { - val: finalBody.p_addlname ? finalBody.p_addlname : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_address1: { - val: finalBody.p_address1 ? finalBody.p_address1 : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_address2: { - val: finalBody.p_address2 ? finalBody.p_address2 : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_city: { - val: finalBody.p_city ? finalBody.p_city : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_state: { - val: finalBody.p_state ? finalBody.p_state : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_zip: { - val: finalBody.p_zip ? finalBody.p_zip : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_country: { - val: finalBody.p_country ? finalBody.p_country : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_userid: { - val: finalBody.p_userid ? finalBody.p_userid : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - P_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); - await connection.commit(); + { + p_holderid: { + val: finalBody.p_holderid ? finalBody.p_holderid : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_spid: { + val: finalBody.p_spid ? finalBody.p_spid : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_locationid: { + val: finalBody.p_locationid ? finalBody.p_locationid : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_holderno: { + val: finalBody.p_holderno ? finalBody.p_holderno : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_holdertype: { + val: finalBody.p_holdertype ? finalBody.p_holdertype : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_uscibmemberflag: { + val: finalBody.p_uscibmemberflag + ? finalBody.p_uscibmemberflag + : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_govagencyflag: { + val: finalBody.p_govagencyflag ? finalBody.p_govagencyflag : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_holdername: { + val: finalBody.p_holdername ? finalBody.p_holdername : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_namequalifier: { + val: finalBody.p_namequalifier ? finalBody.p_namequalifier : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_addlname: { + val: finalBody.p_addlname ? finalBody.p_addlname : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_address1: { + val: finalBody.p_address1 ? finalBody.p_address1 : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_address2: { + val: finalBody.p_address2 ? finalBody.p_address2 : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_city: { + val: finalBody.p_city ? finalBody.p_city : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_state: { + val: finalBody.p_state ? finalBody.p_state : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_zip: { + val: finalBody.p_zip ? finalBody.p_zip : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_country: { + val: finalBody.p_country ? finalBody.p_country : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_userid: { + val: finalBody.p_userid ? finalBody.p_userid : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + 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(); + // let fres = await result.outBinds.P_cursor.getRows(); - if (result.outBinds && result.outBinds.P_cursor) { - const cursor = result.outBinds.P_cursor; - let rowsBatch; + if (result.outBinds && result.outBinds.P_cursor) { + const cursor = result.outBinds.P_cursor; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); - P_cursor_rows = P_cursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + do { + rowsBatch = await cursor.getRows(100); + P_cursor_rows = P_cursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + await cursor.close(); + } else { + throw new Error('No cursor returned from the stored procedure'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } - - return { P_cursor: P_cursor_rows }; - - // return fres - - } catch (err) { - - return { error: err.message } - } finally { } + return { P_cursor: P_cursor_rows }; + // return fres + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - GetHolderRecord = async (body: GetHolderOrContactDTO) => { + }; + GetHolderRecord = async (body: GetHolderOrContactDTO) => { + let connection; + let p_cursor_rows = []; - let connection; - let p_cursor_rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - try { - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEHOLDER_PKG.GetHolderMaster( :p_spid, :p_holderid, :p_cursor ); END;`, - { - P_spid: { - val: body.p_spid, - type: oracledb.DB_TYPE_NUMBER, - }, - p_holderid: { - val: body.p_holderid, - type: oracledb.DB_TYPE_NUMBER, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + P_spid: { + val: body.p_spid, + type: oracledb.DB_TYPE_NUMBER, + }, + p_holderid: { + val: body.p_holderid, + 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; + if (result.outBinds && result.outBinds.p_cursor) { + const cursor = result.outBinds.p_cursor; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); - p_cursor_rows = p_cursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + do { + rowsBatch = await cursor.getRows(100); + p_cursor_rows = p_cursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + await cursor.close(); + } - await cursor.close(); - } - - return { p_cursor: p_cursor_rows }; - - } catch (err) { - - return { error: err.message } - } finally { } + return { p_cursor: p_cursor_rows }; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - UpdateHolderContact = async (body: UpdateHolderContactDTO) => { + }; + UpdateHolderContact = async (body: UpdateHolderContactDTO) => { + const newBody = { + p_holdercontactid: null, + p_spid: null, + p_firstname: null, + p_lastname: null, + p_middleinitial: null, + p_title: null, + p_phone: null, + p_mobile: null, + p_fax: null, + p_emailaddress: null, + p_userid: null, + }; - let newBody = { - "p_holdercontactid": null, - "p_spid": null, - "p_firstname": null, - "p_lastname": null, - "p_middleinitial": null, - "p_title": null, - "p_phone": null, - "p_mobile": null, - "p_fax": null, - "p_emailaddress": null, - "p_userid": null + const reqBody = JSON.parse(JSON.stringify(body)); + + function setEmptyStringsToNull(obj) { + Object.keys(obj).forEach((key) => { + if (typeof obj[key] === 'object' && obj[key] !== null) { + setEmptyStringsToNull(obj[key]); + } else if (obj[key] === '') { + obj[key] = null; } + }); + } - let reqBody = JSON.parse(JSON.stringify(body)); + setEmptyStringsToNull(reqBody); - function setEmptyStringsToNull(obj) { - Object.keys(obj).forEach(key => { - if (typeof obj[key] === 'object' && obj[key] !== null) { - setEmptyStringsToNull(obj[key]); - } else if (obj[key] === "") { - obj[key] = null; - } - }); - } + const finalBody: UpdateHolderContactDTO = { ...newBody, ...reqBody }; - setEmptyStringsToNull(reqBody); + let connection; + let P_cursor_rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - const finalBody: UpdateHolderContactDTO = { ...newBody, ...reqBody }; - - let connection; - let P_cursor_rows = []; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEHOLDER_PKG.UpdateHolders( :p_holdercontactid, :p_spid, @@ -534,370 +572,383 @@ export class ManageHoldersService { :P_cursor ); END;`, - { - p_holdercontactid: { - val: finalBody.p_holdercontactid ? finalBody.p_holdercontactid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_spid: { - val: finalBody.p_spid ? finalBody.p_spid : null, - type: oracledb.DB_TYPE_NUMBER - }, - p_firstname: { - val: finalBody.p_firstname ? finalBody.p_firstname : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_lastname: { - val: finalBody.p_lastname ? finalBody.p_lastname : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_middleinitial: { - val: finalBody.p_middleinitial ? finalBody.p_middleinitial : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_title: { - val: finalBody.p_title ? finalBody.p_title : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_phone: { - val: finalBody.p_phone ? finalBody.p_phone : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_mobile: { - val: finalBody.p_mobile ? finalBody.p_mobile : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_fax: { - val: finalBody.p_fax ? finalBody.p_fax : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_emailaddress: { - val: finalBody.p_emailaddress ? finalBody.p_emailaddress : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_userid: { - val: finalBody.p_userid ? finalBody.p_userid : null, - type: oracledb.DB_TYPE_NVARCHAR - }, - P_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); - await connection.commit(); + { + p_holdercontactid: { + val: finalBody.p_holdercontactid + ? finalBody.p_holdercontactid + : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_spid: { + val: finalBody.p_spid ? finalBody.p_spid : null, + type: oracledb.DB_TYPE_NUMBER, + }, + p_firstname: { + val: finalBody.p_firstname ? finalBody.p_firstname : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_lastname: { + val: finalBody.p_lastname ? finalBody.p_lastname : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_middleinitial: { + val: finalBody.p_middleinitial ? finalBody.p_middleinitial : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_title: { + val: finalBody.p_title ? finalBody.p_title : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_phone: { + val: finalBody.p_phone ? finalBody.p_phone : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_mobile: { + val: finalBody.p_mobile ? finalBody.p_mobile : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_fax: { + val: finalBody.p_fax ? finalBody.p_fax : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_emailaddress: { + val: finalBody.p_emailaddress ? finalBody.p_emailaddress : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_userid: { + val: finalBody.p_userid ? finalBody.p_userid : null, + type: oracledb.DB_TYPE_NVARCHAR, + }, + 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(); + // let fres = await result.outBinds.P_cursor.getRows(); - if (result.outBinds && result.outBinds.P_cursor) { - const cursor = result.outBinds.P_cursor; - let rowsBatch; + if (result.outBinds && result.outBinds.P_cursor) { + const cursor = result.outBinds.P_cursor; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); - P_cursor_rows = P_cursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + do { + rowsBatch = await cursor.getRows(100); + P_cursor_rows = P_cursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + await cursor.close(); + } else { + throw new Error('No cursor returned from the stored procedure'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } + return { P_cursor: P_cursor_rows }; - return { P_cursor: P_cursor_rows }; - - // return fres - - } catch (err) { - - return { error: err.message } - } finally { } + // return fres + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - GetHolderContacts = async (body: GetHolderOrContactDTO) => { - let connection; - let p_cursor_rows = []; + }; + GetHolderContacts = async (body: GetHolderOrContactDTO) => { + let connection; + let p_cursor_rows = []; - try { - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEHOLDER_PKG.GetHolderContacts( :p_spid, :p_holderid, :p_cursor ); END;`, - { - P_spid: { - val: body.p_spid, - type: oracledb.DB_TYPE_NUMBER, - }, - p_holderid: { - val: body.p_holderid, - type: oracledb.DB_TYPE_NUMBER, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + P_spid: { + val: body.p_spid, + type: oracledb.DB_TYPE_NUMBER, + }, + p_holderid: { + val: body.p_holderid, + 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; + if (result.outBinds && result.outBinds.p_cursor) { + const cursor = result.outBinds.p_cursor; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); - p_cursor_rows = p_cursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + do { + rowsBatch = await cursor.getRows(100); + p_cursor_rows = p_cursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + await cursor.close(); + } - await cursor.close(); - } - - return { p_cursor: p_cursor_rows }; - - } catch (err) { - - return { error: err.message } - } finally { } + return { p_cursor: p_cursor_rows }; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - InactivateHolder = async (body: GetHolderOrContactDTO) => { - let connection; - let p_cursor_rows = []; + }; + InactivateHolder = async (body: GetHolderOrContactDTO) => { + let connection; + let p_cursor_rows = []; - try { - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN ManageHolder_Pkg.InactivateHolder( :p_spid, :p_holderid, :p_cursor ); END;`, - { - P_spid: { - val: body.p_spid, - type: oracledb.DB_TYPE_NUMBER, - }, - p_holderid: { - val: body.p_holderid, - type: oracledb.DB_TYPE_NUMBER, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + P_spid: { + val: body.p_spid, + type: oracledb.DB_TYPE_NUMBER, + }, + p_holderid: { + val: body.p_holderid, + 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; + if (result.outBinds && result.outBinds.p_cursor) { + const cursor = result.outBinds.p_cursor; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); - p_cursor_rows = p_cursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + do { + rowsBatch = await cursor.getRows(100); + p_cursor_rows = p_cursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + await cursor.close(); + } - await cursor.close(); - } - - return { p_cursor: p_cursor_rows }; - - } catch (err) { - - return { error: err.message } - } finally { } + return { p_cursor: p_cursor_rows }; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - ReactivateHolder = async (body: GetHolderOrContactDTO) => { - let connection; - let p_cursor_rows = []; + }; + ReactivateHolder = async (body: GetHolderOrContactDTO) => { + let connection; + let p_cursor_rows = []; - try { - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN ManageHolder_Pkg.ReactivateHolder( :p_spid, :p_holderid, :p_cursor ); END;`, - { - P_spid: { - val: body.p_spid, - type: oracledb.DB_TYPE_NUMBER, - }, - p_holderid: { - val: body.p_holderid, - type: oracledb.DB_TYPE_NUMBER, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + P_spid: { + val: body.p_spid, + type: oracledb.DB_TYPE_NUMBER, + }, + p_holderid: { + val: body.p_holderid, + 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; + if (result.outBinds && result.outBinds.p_cursor) { + const cursor = result.outBinds.p_cursor; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); - p_cursor_rows = p_cursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + do { + rowsBatch = await cursor.getRows(100); + p_cursor_rows = p_cursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + await cursor.close(); + } - await cursor.close(); - } - - return { p_cursor: p_cursor_rows }; - - } catch (err) { - - return { error: err.message } - } finally { } + return { p_cursor: p_cursor_rows }; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - InactivateHolderContact = async (body: GetHolderContactActivateOrInactivateDTO) => { - let connection; - let p_cursor_rows = []; + }; + InactivateHolderContact = async ( + body: GetHolderContactActivateOrInactivateDTO, + ) => { + let connection; + let p_cursor_rows = []; - try { - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN ManageHolder_Pkg.InactivateHolderContact( :p_spid, :p_holderid, :p_cursor ); END;`, - { - P_spid: { - val: body.p_spid, - type: oracledb.DB_TYPE_NUMBER, - }, - p_holderid: { - val: body.p_holderContactid, - type: oracledb.DB_TYPE_NUMBER, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + P_spid: { + val: body.p_spid, + type: oracledb.DB_TYPE_NUMBER, + }, + p_holderid: { + val: body.p_holderContactid, + 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; + if (result.outBinds && result.outBinds.p_cursor) { + const cursor = result.outBinds.p_cursor; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); - p_cursor_rows = p_cursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + do { + rowsBatch = await cursor.getRows(100); + p_cursor_rows = p_cursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + await cursor.close(); + } - await cursor.close(); - } - - return { p_cursor: p_cursor_rows }; - - } catch (err) { - - return { error: err.message } - } finally { } + return { p_cursor: p_cursor_rows }; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } - ReactivateHolderContact = async (body: GetHolderContactActivateOrInactivateDTO) => { - let connection; - let p_cursor_rows = []; + }; + ReactivateHolderContact = async ( + body: GetHolderContactActivateOrInactivateDTO, + ) => { + let connection; + let p_cursor_rows = []; - try { - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN ManageHolder_Pkg.ReactivateHolderContact( :p_spid, :p_holderid, :p_cursor ); END;`, - { - P_spid: { - val: body.p_spid, - type: oracledb.DB_TYPE_NUMBER, - }, - p_holderid: { - val: body.p_holderContactid, - type: oracledb.DB_TYPE_NUMBER, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + P_spid: { + val: body.p_spid, + type: oracledb.DB_TYPE_NUMBER, + }, + p_holderid: { + val: body.p_holderContactid, + 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; + if (result.outBinds && result.outBinds.p_cursor) { + const cursor = result.outBinds.p_cursor; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); - p_cursor_rows = p_cursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + do { + rowsBatch = await cursor.getRows(100); + p_cursor_rows = p_cursor_rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + await cursor.close(); + } - await cursor.close(); - } - - return { p_cursor: p_cursor_rows }; - - } catch (err) { - - return { error: err.message } - } finally { } + return { p_cursor: p_cursor_rows }; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + }; } diff --git a/src/oracle/oracle.dto.ts b/src/oracle/oracle.dto.ts deleted file mode 100644 index a45d910..0000000 --- a/src/oracle/oracle.dto.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { ApiProperty } from '@nestjs/swagger'; -import { Type } from 'class-transformer'; -import { IsArray, IsDefined, IsEmail, IsNumber, IsOptional, IsString, ValidateNested } from 'class-validator'; - - - - - - - - - - -//-------------------------------- - -export class UserDTO { - @ApiProperty({ required: true }) - @IsNumber() - id: number; - - @ApiProperty({ required: true }) - @IsDefined({ message: "Property name is required" }) - @IsString({ message: "property name is required" }) - name: string; -} - -export class TestDTO { - @ApiProperty({ required: true }) - @IsNumber() - ItemNo: number; - - @ApiProperty({ required: true, type: () => [UserDTO] }) - @Type(() => UserDTO) - @ValidateNested({ each: true }) - @IsArray() - user: UserDTO[]; -} \ No newline at end of file diff --git a/src/oracle/oracle.module.ts b/src/oracle/oracle.module.ts index 16f35a4..1a2bfc6 100644 --- a/src/oracle/oracle.module.ts +++ b/src/oracle/oracle.module.ts @@ -8,9 +8,17 @@ import { ManageFeeModule } from './manage-fee/manage-fee.module'; import { ManageClientsModule } from './manage-clients/manage-clients.module'; @Module({ - imports:[DbModule, HomePageModule, UscibManagedSpModule, ParamTableModule, ManageFeeModule, ManageHoldersModule, ManageClientsModule], + imports: [ + DbModule, + HomePageModule, + UscibManagedSpModule, + ParamTableModule, + ManageFeeModule, + ManageHoldersModule, + ManageClientsModule, + ], providers: [], controllers: [], - exports:[] + exports: [], }) export class OracleModule {} diff --git a/src/oracle/param-table/param-table.controller.ts b/src/oracle/param-table/param-table.controller.ts index 0f774fc..44e1b55 100644 --- a/src/oracle/param-table/param-table.controller.ts +++ b/src/oracle/param-table/param-table.controller.ts @@ -1,48 +1,63 @@ -import { Body, Controller, Get, Patch, Post, Put, Query, UsePipes } from '@nestjs/common'; +import { Body, Controller, Get, Patch, Post, Put, Query } from '@nestjs/common'; import { ApiQuery, ApiTags } from '@nestjs/swagger'; import { ParamTableService } from './param-table.service'; -import { ActivateOrInactivateParamRecordDTO, CreateParamRecordDTO, CreateTableRecordDTO, getParamValuesDTO, UpdateParamRecordDTO } from './param-table.dto'; +import { + ActivateOrInactivateParamRecordDTO, + CreateParamRecordDTO, + CreateTableRecordDTO, + getParamValuesDTO, + UpdateParamRecordDTO, +} from './param-table.dto'; @Controller('param-table') export class ParamTableController { + constructor(private readonly paramTableService: ParamTableService) {} - constructor(private readonly paramTableService: ParamTableService) { } + @ApiTags('Param Table - Oracle') + @Get('/GetParamValues') + @ApiQuery({ + name: 'P_SPID', + required: false, + type: Number, + description: 'The ID of the parameter', + }) + @ApiQuery({ + name: 'P_PARAMTYPE', + required: false, + type: String, + description: 'The type of the parameter', + }) + getParamValues(@Query() body: getParamValuesDTO) { + return this.paramTableService.GETPARAMVALUES(body); + } - @ApiTags('Param Table - Oracle') - @Get('/GetParamValues') - @ApiQuery({ name: 'P_SPID', required: false, type: Number, description: 'The ID of the parameter' }) - @ApiQuery({ name: 'P_PARAMTYPE', required: false, type: String, description: 'The type of the parameter' }) - getParamValues(@Query() body: getParamValuesDTO) { - return this.paramTableService.GETPARAMVALUES(body) - } + @ApiTags('Param Table - Oracle') + @Post('/CreateTableRecord') + createTableRecord(@Body() body: CreateTableRecordDTO) { + return this.paramTableService.CREATETABLERECORD(body); + } - @ApiTags('Param Table - Oracle') - @Post('/CreateTableRecord') - createTableRecord(@Body() body: CreateTableRecordDTO) { - return this.paramTableService.CREATETABLERECORD(body) - } + @ApiTags('Param Table - Oracle') + @Post('/CreateParamRecord') + createParamRecord(@Body() body: CreateParamRecordDTO) { + return this.paramTableService.CREATEPARAMRECORD(body); + } - @ApiTags('Param Table - Oracle') - @Post('/CreateParamRecord') - createParamRecord(@Body() body: CreateParamRecordDTO) { - return this.paramTableService.CREATEPARAMRECORD(body) - } + @ApiTags('Param Table - Oracle') + @Patch('/UpdateParamRecord') + UpdateParamRecord(@Body() body: UpdateParamRecordDTO) { + return this.paramTableService.UPDATEPARAMRECORD(body); + } - @ApiTags('Param Table - Oracle') - @Patch('/UpdateParamRecord') - UpdateParamRecord(@Body() body: UpdateParamRecordDTO) { - return this.paramTableService.UPDATEPARAMRECORD(body) - } + @ApiTags('Param Table - Oracle') + @Put('/InActivateParamRecord') + inActivateParamRecord(@Body() body: ActivateOrInactivateParamRecordDTO) { + return this.paramTableService.INACTIVATEPARAMRECORD(body); + } - @ApiTags('Param Table - Oracle') - @Put('/InActivateParamRecord') - inActivateParamRecord(@Body() body: ActivateOrInactivateParamRecordDTO) { - return this.paramTableService.INACTIVATEPARAMRECORD(body) - } - - @ApiTags('Param Table - Oracle') - @Put('/ReActivateParamRecord') - reActivateParamRecord(@Body() body: ActivateOrInactivateParamRecordDTO) { - return this.paramTableService.REACTIVATEPARAMRECORD(body) - } + @ApiTags('Param Table - Oracle') + @Put('/ReActivateParamRecord') + reActivateParamRecord(@Body() body: ActivateOrInactivateParamRecordDTO) { + return this.paramTableService.REACTIVATEPARAMRECORD(body); + } } diff --git a/src/oracle/param-table/param-table.dto.ts b/src/oracle/param-table/param-table.dto.ts index 7dae1bb..4bf016c 100644 --- a/src/oracle/param-table/param-table.dto.ts +++ b/src/oracle/param-table/param-table.dto.ts @@ -1,140 +1,147 @@ -import { ApiProperty } from "@nestjs/swagger"; -import { Transform } from "class-transformer"; -import { IsDefined, IsInt, IsNumber, IsOptional, IsString, Min, ValidateIf } from "class-validator"; +import { ApiProperty } from '@nestjs/swagger'; +import { Transform } from 'class-transformer'; +import { + IsDefined, + IsInt, + IsNumber, + IsOptional, + IsString, + Min, +} from 'class-validator'; export class CreateTableRecordDTO { - @ApiProperty({ required: true }) - @IsString({ message: "Property P_USERID must be a string" }) - @IsDefined({ message: "Property P_USERID is required" }) - P_USERID: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property P_USERID must be a string' }) + @IsDefined({ message: 'Property P_USERID is required' }) + P_USERID: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property P_TABLEFULLDESC must be a string" }) - @IsDefined({ message: "Property P_TABLEFULLDESC is required" }) - P_TABLEFULLDESC: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property P_TABLEFULLDESC must be a string' }) + @IsDefined({ message: 'Property P_TABLEFULLDESC is required' }) + P_TABLEFULLDESC: string; } export class CreateParamRecordDTO { - @ApiProperty({ required: false }) - @IsOptional() - @IsNumber() - P_SPID?: number; + @ApiProperty({ required: false }) + @IsOptional() + @IsNumber() + P_SPID?: number; - @ApiProperty({ required: true }) - @IsString() - P_PARAMTYPE: string; + @ApiProperty({ required: true }) + @IsString() + P_PARAMTYPE: string; - @ApiProperty({ required: true }) - @IsString() - P_PARAMDESC: string; + @ApiProperty({ required: true }) + @IsString() + P_PARAMDESC: string; - @ApiProperty({ required: true }) - @IsString() - P_PARAMVALUE: string; + @ApiProperty({ required: true }) + @IsString() + P_PARAMVALUE: string; - @ApiProperty({ required: false }) - @IsOptional() - @IsString() - P_ADDLPARAMVALUE1?: string; + @ApiProperty({ required: false }) + @IsOptional() + @IsString() + P_ADDLPARAMVALUE1?: string; - @ApiProperty({ required: false }) - @IsOptional() - @IsString() - P_ADDLPARAMVALUE2?: string; + @ApiProperty({ required: false }) + @IsOptional() + @IsString() + P_ADDLPARAMVALUE2?: string; - @ApiProperty({ required: false }) - @IsOptional() - @IsString() - P_ADDLPARAMVALUE3?: string; + @ApiProperty({ required: false }) + @IsOptional() + @IsString() + P_ADDLPARAMVALUE3?: string; - @ApiProperty({ required: false }) - @IsOptional() - @IsString() - P_ADDLPARAMVALUE4?: string; + @ApiProperty({ required: false }) + @IsOptional() + @IsString() + P_ADDLPARAMVALUE4?: string; - @ApiProperty({ required: false }) - @IsOptional() - @IsString() - P_ADDLPARAMVALUE5?: string; + @ApiProperty({ required: false }) + @IsOptional() + @IsString() + P_ADDLPARAMVALUE5?: string; - @ApiProperty({ required: true }) - @IsNumber() - P_SORTSEQ: number; + @ApiProperty({ required: true }) + @IsNumber() + P_SORTSEQ: number; - @ApiProperty({ required: true }) - @IsString() - P_USERID: string; + @ApiProperty({ required: true }) + @IsString() + P_USERID: string; } export class UpdateParamRecordDTO { - @ApiProperty({ required: false }) - @IsOptional() - @IsNumber() - P_SPID?: number; + @ApiProperty({ required: false }) + @IsOptional() + @IsNumber() + P_SPID?: number; - @ApiProperty({ required: true }) - @IsNumber() - P_PARAMID: number; + @ApiProperty({ required: true }) + @IsNumber() + P_PARAMID: number; - @ApiProperty({ required: true }) - @IsString() - P_PARAMDESC: string; + @ApiProperty({ required: true }) + @IsString() + P_PARAMDESC: string; - @ApiProperty({ required: false }) - @IsOptional() - @IsString() - P_ADDLPARAMVALUE1?: string; + @ApiProperty({ required: false }) + @IsOptional() + @IsString() + P_ADDLPARAMVALUE1?: string; - @ApiProperty({ required: false }) - @IsOptional() - @IsString() - P_ADDLPARAMVALUE2?: string; + @ApiProperty({ required: false }) + @IsOptional() + @IsString() + P_ADDLPARAMVALUE2?: string; - @ApiProperty({ required: false }) - @IsOptional() - @IsString() - P_ADDLPARAMVALUE3?: string; + @ApiProperty({ required: false }) + @IsOptional() + @IsString() + P_ADDLPARAMVALUE3?: string; - @ApiProperty({ required: false }) - @IsOptional() - @IsString() - P_ADDLPARAMVALUE4?: string; + @ApiProperty({ required: false }) + @IsOptional() + @IsString() + P_ADDLPARAMVALUE4?: string; - @ApiProperty({ required: false }) - @IsOptional() - @IsString() - P_ADDLPARAMVALUE5?: string; + @ApiProperty({ required: false }) + @IsOptional() + @IsString() + P_ADDLPARAMVALUE5?: string; - @ApiProperty({ required: true }) - @IsNumber() - P_SORTSEQ: number; + @ApiProperty({ required: true }) + @IsNumber() + P_SORTSEQ: number; - @ApiProperty({ required: true }) - @IsString() - P_USERID: string; + @ApiProperty({ required: true }) + @IsString() + P_USERID: string; } export class getParamValuesDTO { - @IsInt({ message: "Property P_SPID must be a whole number" }) - @IsNumber({}, { message: "Property P_SPID must be a number" }) - @Min(0, { message: "Property P_SPID must be at least 0" }) - @Transform(({ value }) => Number(value)) - @IsOptional() - P_SPID?: number; + @IsInt({ message: 'Property P_SPID must be a whole number' }) + @IsNumber({}, { message: 'Property P_SPID must be a number' }) + @Min(0, { message: 'Property P_SPID must be at least 0' }) + @Transform(({ value }) => Number(value)) + @IsOptional() + P_SPID?: number; - @IsString({ message: "Property P_PARAMTYPE must be a string" }) - @IsOptional() - P_PARAMTYPE?: string; + @IsString({ message: 'Property P_PARAMTYPE must be a string' }) + @IsOptional() + P_PARAMTYPE?: string; } export class ActivateOrInactivateParamRecordDTO { - @ApiProperty({ required: true }) - @IsNumber({}, { message: "Property P_PARAMID must be a number" }) - @IsDefined({ message: "Property P_PARAMID is required" }) - P_PARAMID: number; + @ApiProperty({ required: true }) + @IsNumber({}, { message: 'Property P_PARAMID must be a number' }) + @IsDefined({ message: 'Property P_PARAMID is required' }) + P_PARAMID: number; - @ApiProperty({ required: true }) - @IsString({ message: "Property P_USERID must be a string" }) - @IsDefined({ message: "Property P_USERID is required" }) - P_USERID: string; -} \ No newline at end of file + @ApiProperty({ required: true }) + @IsString({ message: 'Property P_USERID must be a string' }) + @IsDefined({ message: 'Property P_USERID is required' }) + P_USERID: string; +} diff --git a/src/oracle/param-table/param-table.module.ts b/src/oracle/param-table/param-table.module.ts index 3d63d1c..701eae0 100644 --- a/src/oracle/param-table/param-table.module.ts +++ b/src/oracle/param-table/param-table.module.ts @@ -4,6 +4,6 @@ import { ParamTableService } from './param-table.service'; @Module({ controllers: [ParamTableController], - providers: [ParamTableService] + providers: [ParamTableService], }) export class ParamTableModule {} diff --git a/src/oracle/param-table/param-table.service.ts b/src/oracle/param-table/param-table.service.ts index ee1d838..71cd9b2 100644 --- a/src/oracle/param-table/param-table.service.ts +++ b/src/oracle/param-table/param-table.service.ts @@ -1,128 +1,134 @@ import { Injectable } from '@nestjs/common'; import { OracleDBService } from 'src/db/db.service'; -import * as oracledb from 'oracledb' -import { ActivateOrInactivateParamRecordDTO, CreateParamRecordDTO, CreateTableRecordDTO, getParamValuesDTO, UpdateParamRecordDTO } from './param-table.dto'; +import * as oracledb from 'oracledb'; +import { + ActivateOrInactivateParamRecordDTO, + CreateParamRecordDTO, + CreateTableRecordDTO, + getParamValuesDTO, + UpdateParamRecordDTO, +} from './param-table.dto'; @Injectable() export class ParamTableService { - constructor(private readonly oracleDBService: OracleDBService) { } + constructor(private readonly oracleDBService: OracleDBService) {} - async GETPARAMVALUES(body:getParamValuesDTO) { + async GETPARAMVALUES(body: getParamValuesDTO) { + const finalBody = { + P_SPID: body.P_SPID ? body.P_SPID : null, + P_PARAMTYPE: body.P_PARAMTYPE ? body.P_PARAMTYPE : null, + }; - let finalBody = { - P_SPID: body.P_SPID ? body.P_SPID : null, - P_PARAMTYPE: body.P_PARAMTYPE ? body.P_PARAMTYPE : null - } + let connection; + let rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - let connection; - let rows = []; - try { - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEPARAMTABLE_PKG.GETPARAMVALUES(:P_SPID,:P_PARAMTYPE,:p_cursor); END;`, - { - P_SPID: { - val: finalBody.P_SPID, - type: oracledb.DB_TYPE_NUMBER - }, - P_PARAMTYPE: { - val: finalBody.P_PARAMTYPE, - type: oracledb.DB_TYPE_NVARCHAR - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + P_SPID: { + val: finalBody.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_PARAMTYPE: { + val: finalBody.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; - let rowsBatch; + 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); + 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'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } - - return rows; - - } catch (err) { - - return { error: err.message } - } finally { } - + return rows; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } - async CREATETABLERECORD(body: CreateTableRecordDTO) { - let connection; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } + async CREATETABLERECORD(body: CreateTableRecordDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEPARAMTABLE_PKG.CREATETABLERECORD(:P_USERID,:P_TABLEFULLDESC,:p_cursor); END;`, - { - P_TABLEFULLDESC: { - val: body.P_TABLEFULLDESC, - type: oracledb.DB_TYPE_VARCHAR - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_VARCHAR - }, + { + P_TABLEFULLDESC: { + val: body.P_TABLEFULLDESC, + type: oracledb.DB_TYPE_VARCHAR, + }, + 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(); + 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(); + const fres = await result.outBinds.p_cursor.getRows(); - return fres - - } catch (err) { - - return { error: err.message } - } finally { } + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } - async CREATEPARAMRECORD(body: CreateParamRecordDTO) { - let connection; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } + async CREATEPARAMRECORD(body: CreateParamRecordDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEPARAMTABLE_PKG.CREATEPARAMRECORD( :P_SPID, :P_PARAMTYPE, @@ -137,84 +143,85 @@ export class ParamTableService { :P_USERID, :p_cursor); END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER - }, - P_PARAMTYPE: { - val: body.P_PARAMTYPE, - type: oracledb.DB_TYPE_VARCHAR - }, - P_PARAMDESC: { - val: body.P_PARAMDESC, - type: oracledb.DB_TYPE_VARCHAR - }, - P_PARAMVALUE: { - val: body.P_PARAMVALUE, - 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_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_PARAMTYPE: { + val: body.P_PARAMTYPE, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_PARAMDESC: { + val: body.P_PARAMDESC, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_PARAMVALUE: { + val: body.P_PARAMVALUE, + 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(); + 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(); + const fres = await result.outBinds.p_cursor.getRows(); - return fres - - - } catch (err) { - - return { error: err.message } - } finally { } + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } - async UPDATEPARAMRECORD(body: UpdateParamRecordDTO) { - let connection; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } + async UPDATEPARAMRECORD(body: UpdateParamRecordDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEPARAMTABLE_PKG.UPDATEPARAMRECORD( :P_SPID, :P_PARAMID, @@ -228,140 +235,142 @@ export class ParamTableService { :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_NUMBER - }, - 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_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_PARAMID: { + val: body.P_PARAMID, + type: oracledb.DB_TYPE_NUMBER, + }, + 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(); + 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(); + const fres = await result.outBinds.p_cursor.getRows(); - return fres - - - } catch (err) { - - return { error: err.message } - } finally { } + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } - async INACTIVATEPARAMRECORD(body: ActivateOrInactivateParamRecordDTO) { - let connection; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } + async INACTIVATEPARAMRECORD(body: ActivateOrInactivateParamRecordDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEPARAMTABLE_PKG.INACTIVATEPARAMRECORD( :P_PARAMID, :P_USERID); END;`, - { - P_PARAMID: { - val: body.P_PARAMID, - type: oracledb.DB_TYPE_NUMBER - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_VARCHAR - }, - } - ); - await connection.commit(); + { + P_PARAMID: { + val: body.P_PARAMID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_USERID: { + val: body.P_USERID, + type: oracledb.DB_TYPE_VARCHAR, + }, + }, + ); + await connection.commit(); - return "SP Executed Successfully" - - - } catch (err) { - - return { error: err.message } - } finally { } + return 'SP Executed Successfully'; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } - async REACTIVATEPARAMRECORD(body: ActivateOrInactivateParamRecordDTO) { - let connection; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } + async REACTIVATEPARAMRECORD(body: ActivateOrInactivateParamRecordDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN MANAGEPARAMTABLE_PKG.REACTIVATEPARAMRECORD( :P_PARAMID, :P_USERID); END;`, - { - P_PARAMID: { - val: body.P_PARAMID, - type: oracledb.DB_TYPE_NUMBER - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_VARCHAR - }, - }, - ); - await connection.commit(); + { + P_PARAMID: { + val: body.P_PARAMID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_USERID: { + val: body.P_USERID, + type: oracledb.DB_TYPE_VARCHAR, + }, + }, + ); + await connection.commit(); - return "SP Executed Successfully" - - - } catch (err) { - - return { error: err.message } - } finally { } + return 'SP Executed Successfully'; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } } diff --git a/src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.controller.ts b/src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.controller.ts index b7f676a..ce2e0d6 100644 --- a/src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.controller.ts +++ b/src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.controller.ts @@ -1,22 +1,24 @@ -import { Body, Controller, Get, Param, ParseIntPipe, Post, Query } from '@nestjs/common'; -import { CreateCarnetSequenceDTO, GetCarnetSequenceDTO } from './carnet-sequence.dto'; +import { Body, Controller, Get, Post, Query } from '@nestjs/common'; +import { + CreateCarnetSequenceDTO, + GetCarnetSequenceDTO, +} from './carnet-sequence.dto'; import { ApiTags } from '@nestjs/swagger'; import { CarnetSequenceService } from './carnet-sequence.service'; @Controller('carnet-sequence') export class CarnetSequenceController { + constructor(private readonly carnetSequenceService: CarnetSequenceService) {} - constructor(private readonly carnetSequenceService:CarnetSequenceService){} - - @ApiTags('Carnet Sequence - Oracle') - @Post('/CreateCarnetSequence/') - createCarnetSequence(@Body() body: CreateCarnetSequenceDTO) { - return this.carnetSequenceService.createCarnetSequence(body) - } + @ApiTags('Carnet Sequence - Oracle') + @Post('/CreateCarnetSequence/') + createCarnetSequence(@Body() body: CreateCarnetSequenceDTO) { + return this.carnetSequenceService.createCarnetSequence(body); + } - @ApiTags('Carnet Sequence - Oracle') - @Get('/GetCarnetSequence') - getCarnetSequence(@Query() body: GetCarnetSequenceDTO) { - return this.carnetSequenceService.getCarnetSequence(body) - } + @ApiTags('Carnet Sequence - Oracle') + @Get('/GetCarnetSequence') + getCarnetSequence(@Query() body: GetCarnetSequenceDTO) { + return this.carnetSequenceService.getCarnetSequence(body); + } } diff --git a/src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.dto.ts b/src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.dto.ts index b84c7c0..57c926e 100644 --- a/src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.dto.ts +++ b/src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.dto.ts @@ -1,42 +1,42 @@ -import { ApiProperty } from "@nestjs/swagger"; -import { Transform } from "class-transformer"; -import { IsDefined, IsInt, IsNumber, IsString, Min } from "class-validator"; +import { ApiProperty } from '@nestjs/swagger'; +import { Transform } from 'class-transformer'; +import { IsDefined, IsInt, IsNumber, IsString, Min } from 'class-validator'; export class CreateCarnetSequenceDTO { - @ApiProperty({ required: true }) - @IsNumber({}, { message: "Property p_spid must be a number" }) - @IsDefined({ message: "Property p_spid is required" }) - p_spid: number; + @ApiProperty({ required: true }) + @IsNumber({}, { message: 'Property p_spid must be a number' }) + @IsDefined({ message: 'Property p_spid is required' }) + p_spid: number; - @ApiProperty({ required: true }) - @IsNumber({}, { message: "Property p_regionid must be a number" }) - @IsDefined({ message: "Property p_regionid is required" }) - p_regionid: number; + @ApiProperty({ required: true }) + @IsNumber({}, { message: 'Property p_regionid must be a number' }) + @IsDefined({ message: 'Property p_regionid is required' }) + p_regionid: number; - @ApiProperty({ required: true }) - @IsNumber({}, { message: "Property p_startnumber must be a number" }) - @IsDefined({ message: "Property p_startnumber is required" }) - @Min(0, { message: "Property p_startnumber must be at least 0" }) - p_startnumber: number; + @ApiProperty({ required: true }) + @IsNumber({}, { message: 'Property p_startnumber must be a number' }) + @IsDefined({ message: 'Property p_startnumber is required' }) + @Min(0, { message: 'Property p_startnumber must be at least 0' }) + p_startnumber: number; - @ApiProperty({ required: true }) - @IsNumber({}, { message: "Property p_endnumber must be a number" }) - @IsDefined({ message: "Property p_endnumber is required" }) - @Min(0, { message: "Property p_endnumber must be at least 0" }) - p_endnumber: number; + @ApiProperty({ required: true }) + @IsNumber({}, { message: 'Property p_endnumber must be a number' }) + @IsDefined({ message: 'Property p_endnumber is required' }) + @Min(0, { message: 'Property p_endnumber must be at least 0' }) + p_endnumber: number; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_carnettype must be a string" }) - @IsDefined({ message: "Property p_carnettype is required" }) - p_carnettype: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_carnettype must be a string' }) + @IsDefined({ message: 'Property p_carnettype is required' }) + p_carnettype: string; } -export class GetCarnetSequenceDTO{ - @ApiProperty({ required: true }) - @Min(0, { message: "Property p_spid must be at least 0" }) - @IsInt({ message: "Property p_SPid must be a whole number" }) - @Transform(({ value }) => Number(value)) - @IsNumber({}, { message: "Property p_spid must be a number" }) - @IsDefined({ message: "Property p_spid is required" }) - p_spid:number; -} \ No newline at end of file +export class GetCarnetSequenceDTO { + @ApiProperty({ required: true }) + @Min(0, { message: 'Property p_spid must be at least 0' }) + @IsInt({ message: 'Property p_SPid must be a whole number' }) + @Transform(({ value }) => Number(value)) + @IsNumber({}, { message: 'Property p_spid must be a number' }) + @IsDefined({ message: 'Property p_spid is required' }) + p_spid: number; +} diff --git a/src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.module.ts b/src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.module.ts index 64f6ca9..4add6fd 100644 --- a/src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.module.ts +++ b/src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.module.ts @@ -4,6 +4,6 @@ import { CarnetSequenceService } from './carnet-sequence.service'; @Module({ controllers: [CarnetSequenceController], - providers: [CarnetSequenceService] + providers: [CarnetSequenceService], }) export class CarnetSequenceModule {} diff --git a/src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.service.ts b/src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.service.ts index 3be18cf..a4ffc36 100644 --- a/src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.service.ts +++ b/src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.service.ts @@ -1,23 +1,25 @@ import { Injectable } from '@nestjs/common'; import * as oracledb from 'oracledb'; import { OracleDBService } from 'src/db/db.service'; -import { CreateCarnetSequenceDTO, GetCarnetSequenceDTO } from './carnet-sequence.dto'; +import { + CreateCarnetSequenceDTO, + GetCarnetSequenceDTO, +} from './carnet-sequence.dto'; @Injectable() export class CarnetSequenceService { + constructor(private readonly oracleDBService: OracleDBService) {} - constructor(private readonly oracleDBService:OracleDBService){} + async createCarnetSequence(body: CreateCarnetSequenceDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - async createCarnetSequence(body:CreateCarnetSequenceDTO) { - let connection; - try { - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN USCIB_Managed_Pkg.CreateCarnetSequence( :p_spid, :p_regionid, @@ -25,99 +27,104 @@ export class CarnetSequenceService { :p_endnumber, :p_carnettype, :p_cursor); - END;`, { - p_spid: { - val: body.p_spid, - type: oracledb.DB_TYPE_NUMBER - }, - p_regionid: { - val: body.p_regionid, - type: oracledb.DB_TYPE_NUMBER - }, - p_startnumber: { - val: body.p_startnumber, - type: oracledb.DB_TYPE_NUMBER - }, - p_endnumber: { - val: body.p_endnumber, - type: oracledb.DB_TYPE_NUMBER - }, - p_carnettype: { - val: body.p_carnettype, - type: oracledb.DB_TYPE_VARCHAR - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + END;`, + { + p_spid: { + val: body.p_spid, + type: oracledb.DB_TYPE_NUMBER, + }, + p_regionid: { + val: body.p_regionid, + type: oracledb.DB_TYPE_NUMBER, + }, + p_startnumber: { + val: body.p_startnumber, + type: oracledb.DB_TYPE_NUMBER, + }, + p_endnumber: { + val: body.p_endnumber, + type: oracledb.DB_TYPE_NUMBER, + }, + p_carnettype: { + val: body.p_carnettype, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_cursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); - await connection.commit(); + await connection.commit(); - let fres = await result.outBinds.p_cursor.getRows(); + const fres = await result.outBinds.p_cursor.getRows(); - await result.outBinds.p_cursor.close() + await result.outBinds.p_cursor.close(); - return fres - - } catch (err) { - - return { error: err.message } - } finally { } + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } - async getCarnetSequence(body: GetCarnetSequenceDTO) { - let connection; - let rows = []; - try { - // Connect to the Oracle database using oracledb - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } + async getCarnetSequence(body: GetCarnetSequenceDTO) { + let connection; + let rows = []; + 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 + const result = await connection.execute( + `BEGIN USCIB_Managed_Pkg.GetCarnetSequence(: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 - } - ); + { + 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; + if (result.outBinds && result.outBinds.p_cursor) { + const cursor = result.outBinds.p_cursor; + let rowsBatch; - do { - rowsBatch = await cursor.getRows(100); // Fetch 100 rows at a time - rows = rows.concat(rowsBatch); - } while (rowsBatch.length > 0); + do { + rowsBatch = await cursor.getRows(100); // Fetch 100 rows at a time + rows = rows.concat(rowsBatch); + } while (rowsBatch.length > 0); - - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } + await cursor.close(); + } else { + throw new Error('No cursor returned from the stored procedure'); + } - return rows; - - } catch (err) { - - return { error: err.message } - } finally { } + return rows; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } } diff --git a/src/oracle/uscib-managed-sp/region/region.controller.ts b/src/oracle/uscib-managed-sp/region/region.controller.ts index b2b7ddd..804c908 100644 --- a/src/oracle/uscib-managed-sp/region/region.controller.ts +++ b/src/oracle/uscib-managed-sp/region/region.controller.ts @@ -1,38 +1,29 @@ import { RegionService } from './region.service'; -import { - Get, - Post, - Body, - Controller, - Patch, -} from '@nestjs/common'; +import { Get, Post, Body, Controller, Patch } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { InsertRegionsDto, UpdateRegionDto } from './region.dto'; @Controller('oracle') export class RegionController { + constructor(private readonly regionService: RegionService) {} - constructor( - private readonly regionService: RegionService - ) { } + @ApiTags('Regions - Oracle') + @Post('/InsertRegions') + insertRegions(@Body() body: InsertRegionsDto) { + return this.regionService.insertRegions(body); + } - @ApiTags('Regions - Oracle') - @Post('/InsertRegions') - insertRegions(@Body() body: InsertRegionsDto) { - return this.regionService.insertRegions(body); - } + @ApiTags('Regions - Oracle') + @Patch('/UpdateRegion') + updateRegions(@Body() body: UpdateRegionDto) { + return this.regionService.updateRegions(body); + } - @ApiTags('Regions - Oracle') - @Patch('/UpdateRegion') - updateRegions(@Body() body: UpdateRegionDto) { - return this.regionService.updateRegions(body); - } - - @ApiTags('Regions - Oracle') - @Get('/GetRegions') - getRegions() { - return this.regionService.getRegions(); - } + @ApiTags('Regions - Oracle') + @Get('/GetRegions') + getRegions() { + return this.regionService.getRegions(); + } } diff --git a/src/oracle/uscib-managed-sp/region/region.dto.ts b/src/oracle/uscib-managed-sp/region/region.dto.ts index 89290d4..f7e4d54 100644 --- a/src/oracle/uscib-managed-sp/region/region.dto.ts +++ b/src/oracle/uscib-managed-sp/region/region.dto.ts @@ -1,26 +1,26 @@ -import { IsDefined, IsNumber,IsString } from "class-validator"; -import { ApiProperty } from "@nestjs/swagger"; +import { IsDefined, IsNumber, IsString } from 'class-validator'; +import { ApiProperty } from '@nestjs/swagger'; export class InsertRegionsDto { - @ApiProperty({ required: true }) - @IsString({ message: "Property p_region must be a string" }) - @IsDefined({ message: "Property p_region is required" }) - p_region: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_region must be a string' }) + @IsDefined({ message: 'Property p_region is required' }) + p_region: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_name must be a string" }) - @IsDefined({ message: "Property p_name is required" }) - p_name: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_name must be a string' }) + @IsDefined({ message: 'Property p_name is required' }) + p_name: string; } export class UpdateRegionDto { - @ApiProperty({ required: true }) - @IsNumber({}, { message: "Property p_regionID must be a number" }) - @IsDefined({ message: "Property p_regionID is required" }) - p_regionID: number; + @ApiProperty({ required: true }) + @IsNumber({}, { message: 'Property p_regionID must be a number' }) + @IsDefined({ message: 'Property p_regionID is required' }) + p_regionID: number; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_name must be a string" }) - @IsDefined({ message: "Property p_name is required" }) - p_name: string; -} \ No newline at end of file + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_name must be a string' }) + @IsDefined({ message: 'Property p_name is required' }) + p_name: string; +} diff --git a/src/oracle/uscib-managed-sp/region/region.module.ts b/src/oracle/uscib-managed-sp/region/region.module.ts index 12ff331..9041ec8 100644 --- a/src/oracle/uscib-managed-sp/region/region.module.ts +++ b/src/oracle/uscib-managed-sp/region/region.module.ts @@ -4,6 +4,6 @@ import { RegionService } from './region.service'; @Module({ controllers: [RegionController], - providers: [RegionService] -}) + providers: [RegionService], +}) export class RegionModule {} diff --git a/src/oracle/uscib-managed-sp/region/region.service.ts b/src/oracle/uscib-managed-sp/region/region.service.ts index cd6aaf4..87a5957 100644 --- a/src/oracle/uscib-managed-sp/region/region.service.ts +++ b/src/oracle/uscib-managed-sp/region/region.service.ts @@ -1,142 +1,148 @@ import { Injectable } from '@nestjs/common'; import { OracleDBService } from 'src/db/db.service'; -import * as oracledb from 'oracledb' +import * as oracledb from 'oracledb'; import { InsertRegionsDto, UpdateRegionDto } from './region.dto'; @Injectable() export class RegionService { + constructor(private readonly oracleDBService: OracleDBService) {} - constructor(private readonly oracleDBService: OracleDBService) { } + async insertRegions(body: InsertRegionsDto) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - async insertRegions(body: InsertRegionsDto) { - let connection; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN USCIB_Managed_Pkg.InsertNewRegion(:p_region,:p_name,:p_cursor); - END;`, { - p_region: { - val: body.p_region, - type: oracledb.DB_TYPE_VARCHAR - }, - p_name: { - val: body.p_name, - type: oracledb.DB_TYPE_VARCHAR - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + END;`, + { + p_region: { + val: body.p_region, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_name: { + val: body.p_name, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_cursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); - await connection.commit(); + await connection.commit(); - let fres = await result.outBinds.p_cursor.getRows(); + const fres = await result.outBinds.p_cursor.getRows(); - return fres - - } catch (err) { - - return { error: err.message } - } finally { } + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } - async updateRegions(body: UpdateRegionDto) { - let connection; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } + async updateRegions(body: UpdateRegionDto) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN USCIB_Managed_Pkg.UpdateRegion(:p_regionID,:p_name,:p_cursor); - END;`, { - p_regionID: { - val: body.p_regionID, - type: oracledb.DB_TYPE_NUMBER - }, - p_name: { - val: body.p_name, - type: oracledb.DB_TYPE_VARCHAR - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + END;`, + { + p_regionID: { + val: body.p_regionID, + type: oracledb.DB_TYPE_NUMBER, + }, + p_name: { + val: body.p_name, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_cursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); - await connection.commit(); + await connection.commit(); - let fres = await result.outBinds.p_cursor.getRows(); + const fres = await result.outBinds.p_cursor.getRows(); - return fres - - } catch (err) { - - return { error: err.message } - } finally { } + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } - async getRegions() { - let connection; - let rows = []; - try { - try { - connection = await this.oracleDBService.getConnection() - } - catch (err) { - console.log("DB ERROR: ", err); - return { error: "Error while connecting to DB" } - } - const result = await connection.execute( - `BEGIN + async getRegions() { + let connection; + let rows = []; + try { + try { + connection = await this.oracleDBService.getConnection(); + } catch (err) { + console.log('DB ERROR: ', err); + return { error: 'Error while connecting to DB' }; + } + const result = await connection.execute( + `BEGIN USCIB_Managed_Pkg.GetRegions(:p_cursor); END;`, - { - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + 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; + 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); + 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'); - } + await cursor.close(); + } else { + throw new Error('No cursor returned from the stored procedure'); + } - return rows; - - } catch (err) { - - return { error: err.message } - } finally { } + return rows; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } } diff --git a/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.controller.ts b/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.controller.ts index 1c09432..f339ec0 100644 --- a/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.controller.ts +++ b/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.controller.ts @@ -1,47 +1,50 @@ import { SpContactsService } from './sp-contacts.service'; -import { Body, Controller, Get, Param, ParseIntPipe, Post, Put, Query } from '@nestjs/common'; -import { getSPDefaultcontactDTO, inactivateSPContactDTO, InsertSPContactsDTO, setSPDefaultcontactDTO, UpdateSPContactsDTO } from './sp-contacts.dto'; +import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common'; +import { + getSPDefaultcontactDTO, + inactivateSPContactDTO, + InsertSPContactsDTO, + setSPDefaultcontactDTO, + UpdateSPContactsDTO, +} from './sp-contacts.dto'; import { ApiTags } from '@nestjs/swagger'; @Controller('oracle') export class SpContactsController { + constructor(private readonly spContactsService: SpContactsService) {} - constructor( - private readonly spContactsService: SpContactsService, - ) { } + @ApiTags('SPContacts - Oracle') + @Post('/InsertSPContacts') + insertSPContacts(@Body() body: InsertSPContactsDTO) { + return this.spContactsService.insertSPContacts(body); + } - @ApiTags('SPContacts - Oracle') - @Post('/InsertSPContacts') - insertSPContacts(@Body() body: InsertSPContactsDTO) { - return this.spContactsService.insertSPContacts(body) - } + @ApiTags('SPContacts - Oracle') + @Post('/SetSPDefaultcontact') + setSPDefaultcontact(@Query() body: setSPDefaultcontactDTO) { + return this.spContactsService.setSPDefaultcontact(body); + } - @ApiTags('SPContacts - Oracle') - @Post('/SetSPDefaultcontact') - setSPDefaultcontact(@Query() body:setSPDefaultcontactDTO) { - return this.spContactsService.setSPDefaultcontact(body) - } + @ApiTags('SPContacts - Oracle') + @Put('/UpdateSPContacts') + updateSPContacts(@Body() body: UpdateSPContactsDTO) { + return this.spContactsService.updateSPContacts(body); + } - @ApiTags('SPContacts - Oracle') - @Put('/UpdateSPContacts') - updateSPContacts(@Body() body: UpdateSPContactsDTO) { - return this.spContactsService.updateSPContacts(body) - } + @ApiTags('SPContacts - Oracle') + @Post('/InactivateSPContact') + inactivateSPContact(@Query() body: inactivateSPContactDTO) { + return this.spContactsService.inactivateSPContact(body); + } - @ApiTags('SPContacts - Oracle') - @Post('/InactivateSPContact') - inactivateSPContact(@Query() body:inactivateSPContactDTO) { - return this.spContactsService.inactivateSPContact(body) - } + @ApiTags('SPContacts - Oracle') + @Get('/GetSPDefaultcontact') + getSPDefaultcontact(@Query() body: getSPDefaultcontactDTO) { + return this.spContactsService.getSPDefaultcontacts(body); + } - @ApiTags('SPContacts - Oracle') - @Get('/GetSPDefaultcontact') - getSPDefaultcontact(@Query() body:getSPDefaultcontactDTO) { - return this.spContactsService.getSPDefaultcontacts(body) - } - - // @Get('/GetAllSPcontacts') - // getSPcontacts() { - // return this.oarcleService.getSPcontacts(); - // } + // @Get('/GetAllSPcontacts') + // getSPcontacts() { + // return this.oarcleService.getSPcontacts(); + // } } diff --git a/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.dto.ts b/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.dto.ts index b335e73..90b1eab 100644 --- a/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.dto.ts +++ b/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.dto.ts @@ -1,112 +1,119 @@ import { ApiProperty } from '@nestjs/swagger'; import { Transform } from 'class-transformer'; -import { IsDefined, IsEmail, IsInt, IsNumber, IsString, Min } from 'class-validator'; +import { + IsDefined, + IsEmail, + IsInt, + IsNumber, + IsString, + Min, +} from 'class-validator'; export class InsertSPContactsDTO { - @ApiProperty({ required: true }) - @IsNumber() - p_spid: number; + @ApiProperty({ required: true }) + @IsNumber() + p_spid: number; - @ApiProperty({ required: true }) - @IsString() - p_defcontactflag: string; + @ApiProperty({ required: true }) + @IsString() + p_defcontactflag: string; - @ApiProperty({ required: true }) - @IsString() - p_firstname: string; + @ApiProperty({ required: true }) + @IsString() + p_firstname: string; - @ApiProperty({ required: true }) - @IsString() - p_lastname: string; + @ApiProperty({ required: true }) + @IsString() + p_lastname: string; - @ApiProperty({ required: false }) - @IsString() - P_MIDDLEINITIAL: string; + @ApiProperty({ required: false }) + @IsString() + P_MIDDLEINITIAL: string; - @ApiProperty({ required: true }) - @IsString() - p_title: string; + @ApiProperty({ required: true }) + @IsString() + p_title: string; - @ApiProperty({ required: true }) - @IsString() - p_phoneno: string; + @ApiProperty({ required: true }) + @IsString() + p_phoneno: string; - @ApiProperty({ required: true }) - @IsString() - p_mobileno: string; + @ApiProperty({ required: true }) + @IsString() + p_mobileno: string; - @ApiProperty({ required: true }) - @IsString() - p_faxno: string; + @ApiProperty({ required: true }) + @IsString() + p_faxno: string; - @ApiProperty({ required: true }) - @IsEmail() - p_emailaddress: string; + @ApiProperty({ required: true }) + @IsEmail() + p_emailaddress: string; - @ApiProperty({ required: true }) - @IsString() - p_user_id: string; + @ApiProperty({ required: true }) + @IsString() + p_user_id: string; } export class UpdateSPContactsDTO { - @ApiProperty({ required: true }) - @IsNumber() - p_spcontactid: number; + @ApiProperty({ required: true }) + @IsNumber() + p_spcontactid: number; - @ApiProperty({ required: true }) - @IsString() - p_firstname: string; + @ApiProperty({ required: true }) + @IsString() + p_firstname: string; - @ApiProperty({ required: true }) - @IsString() - p_lastname: string; + @ApiProperty({ required: true }) + @IsString() + p_lastname: string; - @ApiProperty({ required: false }) - @IsString() - P_MIDDLEINITIAL: string; + @ApiProperty({ required: false }) + @IsString() + P_MIDDLEINITIAL: string; - @ApiProperty({ required: true }) - @IsString() - p_title: string; + @ApiProperty({ required: true }) + @IsString() + p_title: string; - @ApiProperty({ required: true }) - @IsString() - p_phoneno: string; + @ApiProperty({ required: true }) + @IsString() + p_phoneno: string; - @ApiProperty({ required: true }) - @IsString() - p_mobileno: string; + @ApiProperty({ required: true }) + @IsString() + p_mobileno: string; - @ApiProperty({ required: true }) - @IsString() - p_faxno: string; + @ApiProperty({ required: true }) + @IsString() + p_faxno: string; - @ApiProperty({ required: true }) - @IsEmail() - p_emailaddress: string; + @ApiProperty({ required: true }) + @IsEmail() + p_emailaddress: string; - @ApiProperty({ required: true }) - @IsString() - p_user_id: string; + @ApiProperty({ required: true }) + @IsString() + p_user_id: string; } -export class setSPDefaultcontactDTO{ - @ApiProperty({ required: true }) - @Min(0, { message: "Property p_spcontactid must be at least 0" }) - @IsInt({ message: "Property p_SPid must be a whole number" }) - @Transform(({ value }) => Number(value)) - @IsNumber({}, { message: "Property p_spcontactid must be a number" }) - @IsDefined({ message: "Property p_spcontactid is required" }) - p_spcontactid:number; +export class setSPDefaultcontactDTO { + @ApiProperty({ required: true }) + @Min(0, { message: 'Property p_spcontactid must be at least 0' }) + @IsInt({ message: 'Property p_SPid must be a whole number' }) + @Transform(({ value }) => Number(value)) + @IsNumber({}, { message: 'Property p_spcontactid must be a number' }) + @IsDefined({ message: 'Property p_spcontactid is required' }) + p_spcontactid: number; } -export class inactivateSPContactDTO extends setSPDefaultcontactDTO{} +export class inactivateSPContactDTO extends setSPDefaultcontactDTO {} export class getSPDefaultcontactDTO { - @ApiProperty({ required: true }) - @Min(0, { message: "Property p_SPid must be at least 0" }) - @IsInt({ message: "Property p_SPid must be a whole number" }) - @Transform(({ value }) => Number(value)) - @IsNumber({}, { message: "Property p_SPid must be a number" }) - @IsDefined({ message: "Property p_SPid is required" }) - p_SPid:number; -} \ No newline at end of file + @ApiProperty({ required: true }) + @Min(0, { message: 'Property p_SPid must be at least 0' }) + @IsInt({ message: 'Property p_SPid must be a whole number' }) + @Transform(({ value }) => Number(value)) + @IsNumber({}, { message: 'Property p_SPid must be a number' }) + @IsDefined({ message: 'Property p_SPid is required' }) + p_SPid: number; +} diff --git a/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.module.ts b/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.module.ts index b57e192..fd4b37e 100644 --- a/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.module.ts +++ b/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.module.ts @@ -4,8 +4,8 @@ import { SpContactsController } from './sp-contacts.controller'; import { DbModule } from 'src/db/db.module'; @Module({ - imports:[DbModule], + imports: [DbModule], providers: [SpContactsService], - controllers: [SpContactsController] + controllers: [SpContactsController], }) export class SpContactsModule {} diff --git a/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.service.ts b/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.service.ts index 06c3425..5b14ff2 100644 --- a/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.service.ts +++ b/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.service.ts @@ -1,30 +1,28 @@ import { Injectable } from '@nestjs/common'; import { OracleDBService } from 'src/db/db.service'; -import * as oracledb from 'oracledb' +import * as oracledb from 'oracledb'; import { - getSPDefaultcontactDTO, - inactivateSPContactDTO, - InsertSPContactsDTO, - setSPDefaultcontactDTO, - UpdateSPContactsDTO + getSPDefaultcontactDTO, + inactivateSPContactDTO, + InsertSPContactsDTO, + setSPDefaultcontactDTO, + UpdateSPContactsDTO, } from './sp-contacts.dto'; @Injectable() export class SpContactsService { + constructor(private readonly oracleDBService: OracleDBService) {} - constructor(private readonly oracleDBService: OracleDBService) { } + async insertSPContacts(body: InsertSPContactsDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - async insertSPContacts(body: InsertSPContactsDTO) { - let connection; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN USCIB_Managed_Pkg.InsertSPContacts( :p_spid, :p_defcontactflag, @@ -38,116 +36,118 @@ export class SpContactsService { :p_emailaddress, :p_user_id, :p_cursor); - END;`, { - p_spid: { - val: body.p_spid, - type: oracledb.DB_TYPE_NUMBER - }, - p_defcontactflag: { - val: body.p_defcontactflag, - type: oracledb.DB_TYPE_VARCHAR - }, - p_firstname: { - val: body.p_firstname, - type: oracledb.DB_TYPE_VARCHAR - }, - p_lastname: { - val: body.p_lastname, - type: oracledb.DB_TYPE_VARCHAR - }, - P_MIDDLEINITIAL: { - val: body.P_MIDDLEINITIAL, - type: oracledb.DB_TYPE_VARCHAR - }, - p_title: { - val: body.p_title, - type: oracledb.DB_TYPE_VARCHAR - }, - p_phoneno: { - val: body.p_phoneno, - type: oracledb.DB_TYPE_VARCHAR - }, - p_mobileno: { - val: body.p_mobileno, - type: oracledb.DB_TYPE_VARCHAR - }, - p_faxno: { - val: body.p_faxno, - type: oracledb.DB_TYPE_VARCHAR - }, - p_emailaddress: { - val: body.p_emailaddress, - type: oracledb.DB_TYPE_VARCHAR - }, - p_user_id: { - val: body.p_user_id, - type: oracledb.DB_TYPE_VARCHAR - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + END;`, + { + p_spid: { + val: body.p_spid, + type: oracledb.DB_TYPE_NUMBER, + }, + p_defcontactflag: { + val: body.p_defcontactflag, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_firstname: { + val: body.p_firstname, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_lastname: { + val: body.p_lastname, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_MIDDLEINITIAL: { + val: body.P_MIDDLEINITIAL, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_title: { + val: body.p_title, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_phoneno: { + val: body.p_phoneno, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_mobileno: { + val: body.p_mobileno, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_faxno: { + val: body.p_faxno, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_emailaddress: { + val: body.p_emailaddress, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_user_id: { + val: body.p_user_id, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_cursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); - await connection.commit(); + await connection.commit(); - let fres = await result.outBinds.p_cursor.getRows(); + const fres = await result.outBinds.p_cursor.getRows(); - return fres - - } catch (err) { - - return { error: err.message } - } finally { } + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } - async setSPDefaultcontact(body: setSPDefaultcontactDTO) { + async setSPDefaultcontact(body: setSPDefaultcontactDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - let connection; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN USCIB_Managed_Pkg.SetDefaultContact(:p_spcontactid); END;`, - { - p_spcontactid: { - val: body.p_spcontactid, - type: oracledb.DB_TYPE_NUMBER - }, - } - ); + { + p_spcontactid: { + val: body.p_spcontactid, + type: oracledb.DB_TYPE_NUMBER, + }, + }, + ); - await connection.commit(); - - return "SP executed successfully" - - } catch (err) { - - return { error: err.message } - } finally { } + await connection.commit(); + return 'SP executed successfully'; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } - async updateSPContacts(body: UpdateSPContactsDTO) { - let connection; - try { + async updateSPContacts(body: UpdateSPContactsDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN USCIB_Managed_Pkg.UpdateSPContacts( :p_spcontactid, :p_firstname, @@ -160,201 +160,201 @@ export class SpContactsService { :p_emailaddress, :p_user_id, :p_cursor); - END;`, { - p_spcontactid: { - val: body.p_spcontactid, - type: oracledb.DB_TYPE_NUMBER - }, - p_firstname: { - val: body.p_firstname, - type: oracledb.DB_TYPE_VARCHAR - }, - p_lastname: { - val: body.p_lastname, - type: oracledb.DB_TYPE_VARCHAR - }, - P_MIDDLEINITIAL: { - val: body.P_MIDDLEINITIAL, - type: oracledb.DB_TYPE_VARCHAR - }, - p_title: { - val: body.p_title, - type: oracledb.DB_TYPE_VARCHAR - }, - p_phoneno: { - val: body.p_phoneno, - type: oracledb.DB_TYPE_VARCHAR - }, - p_mobileno: { - val: body.p_mobileno, - type: oracledb.DB_TYPE_VARCHAR - }, - p_faxno: { - val: body.p_faxno, - type: oracledb.DB_TYPE_VARCHAR - }, - p_emailaddress: { - val: body.p_emailaddress, - type: oracledb.DB_TYPE_VARCHAR - }, - p_user_id: { - val: body.p_user_id, - type: oracledb.DB_TYPE_VARCHAR - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + END;`, + { + p_spcontactid: { + val: body.p_spcontactid, + type: oracledb.DB_TYPE_NUMBER, + }, + p_firstname: { + val: body.p_firstname, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_lastname: { + val: body.p_lastname, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_MIDDLEINITIAL: { + val: body.P_MIDDLEINITIAL, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_title: { + val: body.p_title, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_phoneno: { + val: body.p_phoneno, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_mobileno: { + val: body.p_mobileno, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_faxno: { + val: body.p_faxno, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_emailaddress: { + val: body.p_emailaddress, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_user_id: { + val: body.p_user_id, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_cursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); - await connection.commit(); + await connection.commit(); - let fres = await result.outBinds.p_cursor.getRows(); + const fres = await result.outBinds.p_cursor.getRows(); - return fres - - } catch (err) { - - return { error: err.message } - } finally { } + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } - async inactivateSPContact(body: inactivateSPContactDTO) { + async inactivateSPContact(body: inactivateSPContactDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - let connection; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN USCIB_Managed_Pkg.InActivateSPContacts(:p_spcontactid); - END;`, { - p_spcontactid: { - val: body.p_spcontactid, - type: oracledb.DB_TYPE_NUMBER - } - } - ); + END;`, + { + p_spcontactid: { + val: body.p_spcontactid, + type: oracledb.DB_TYPE_NUMBER, + }, + }, + ); - await connection.commit(); - - return "SP executed successfully" - - } catch (err) { - - return { error: err.message } - } finally { } + await connection.commit(); + return 'SP executed successfully'; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } - async getSPDefaultcontacts(body: getSPDefaultcontactDTO) { + async getSPDefaultcontacts(body: getSPDefaultcontactDTO) { + let connection; + let rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - let connection; - let rows = []; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN USCIB_Managed_Pkg.GetSPDefaultContacts(: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 - } - ); + { + 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; + 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); + 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'); + } - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } - - return rows; - - } catch (err) { - - return { error: err.message } - } finally { } - + return rows; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } - async getSPcontacts() { - let connection; - let rows = []; - try { + async getSPcontacts() { + let connection; + let rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + 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 - } - ); + { + 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; + 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); + 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'); + } - - - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); - } - - return rows; - - } catch (err) { - - return { error: err.message } - } finally { } + return rows; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } } diff --git a/src/oracle/uscib-managed-sp/sp/sp.controller.ts b/src/oracle/uscib-managed-sp/sp/sp.controller.ts index 1c35fd7..7973401 100644 --- a/src/oracle/uscib-managed-sp/sp/sp.controller.ts +++ b/src/oracle/uscib-managed-sp/sp/sp.controller.ts @@ -1,36 +1,37 @@ -import { Body, Controller, Get, Param, ParseIntPipe, Post, Put, Query } from '@nestjs/common'; +import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common'; import { SpService } from './sp.service'; -import { ApiTags } from '@nestjs/swagger'; -import { getSelectedServiceproviderDTO, InsertNewServiceProviderDTO, UpdateServiceProviderDTO } from './sp.dto'; +import { ApiTags } from '@nestjs/swagger'; +import { + getSelectedServiceproviderDTO, + InsertNewServiceProviderDTO, + UpdateServiceProviderDTO, +} from './sp.dto'; @Controller('oracle') export class SpController { + constructor(private readonly spService: SpService) {} - constructor( - private readonly spService: SpService - ) { } + @ApiTags('SP - Oracle') + @Post('/InsertNewServiceProvider') + insertNewServiceProvider(@Body() body: InsertNewServiceProviderDTO) { + return this.spService.insertNewServiceProvider(body); + } - @ApiTags('SP - Oracle') - @Post('/InsertNewServiceProvider') - insertNewServiceProvider(@Body() body: InsertNewServiceProviderDTO) { - return this.spService.insertNewServiceProvider(body) - } + @ApiTags('SP - Oracle') + @Put('/UpdateServiceProvider') + updateServiceProider(@Body() body: UpdateServiceProviderDTO) { + return this.spService.updateServiceProvider(body); + } - @ApiTags('SP - Oracle') - @Put('/UpdateServiceProvider') - updateServiceProider(@Body() body: UpdateServiceProviderDTO) { - return this.spService.updateServiceProvider(body) - } + @ApiTags('SP - Oracle') + @Get('/GetAllServiceproviders') + getAllServiceproviders() { + return this.spService.getAllServiceproviders(); + } - @ApiTags('SP - Oracle') - @Get('/GetAllServiceproviders') - getAllServiceproviders() { - return this.spService.getAllServiceproviders(); - } - - @ApiTags('SP - Oracle') - @Get('/GetSelectedServiceprovider') - getSelectedServiceprovider(@Query() body:getSelectedServiceproviderDTO) { - return this.spService.getServiceproviderByID(body); - } + @ApiTags('SP - Oracle') + @Get('/GetSelectedServiceprovider') + getSelectedServiceprovider(@Query() body: getSelectedServiceproviderDTO) { + return this.spService.getServiceproviderByID(body); + } } diff --git a/src/oracle/uscib-managed-sp/sp/sp.dto.ts b/src/oracle/uscib-managed-sp/sp/sp.dto.ts index 56815c7..5aacd3d 100644 --- a/src/oracle/uscib-managed-sp/sp/sp.dto.ts +++ b/src/oracle/uscib-managed-sp/sp/sp.dto.ts @@ -1,183 +1,189 @@ import { ApiProperty } from '@nestjs/swagger'; import { Transform } from 'class-transformer'; -import { IsDefined, IsInt, IsNumber, IsOptional, IsString, Min } from 'class-validator'; +import { + IsDefined, + IsInt, + IsNumber, + IsOptional, + IsString, + Min, +} from 'class-validator'; export class InsertNewServiceProviderDTO { - @ApiProperty({ required: true }) - @IsString({ message: "Property p_name must be a string" }) - @IsDefined({ message: "Property p_name is required" }) - p_name: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_name must be a string' }) + @IsDefined({ message: 'Property p_name is required' }) + p_name: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_lookupcode must be a string" }) - @IsDefined({ message: "Property p_lookupcode is required" }) - p_lookupcode: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_lookupcode must be a string' }) + @IsDefined({ message: 'Property p_lookupcode is required' }) + p_lookupcode: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_address1 must be a string" }) - @IsDefined({ message: "Property p_address1 is required" }) - p_address1: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_address1 must be a string' }) + @IsDefined({ message: 'Property p_address1 is required' }) + p_address1: string; - @ApiProperty({ required: false }) - @IsString({ message: "Property p_address2 must be a string" }) - @IsOptional() - p_address2?: string; + @ApiProperty({ required: false }) + @IsString({ message: 'Property p_address2 must be a string' }) + @IsOptional() + p_address2?: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_city must be a string" }) - @IsDefined({ message: "Property p_city is required" }) - p_city: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_city must be a string' }) + @IsDefined({ message: 'Property p_city is required' }) + p_city: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_state must be a string" }) - @IsDefined({ message: "Property p_state is required" }) - p_state: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_state must be a string' }) + @IsDefined({ message: 'Property p_state is required' }) + p_state: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_zip must be a string" }) - @IsDefined({ message: "Property p_zip is required" }) - p_zip: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_zip must be a string' }) + @IsDefined({ message: 'Property p_zip is required' }) + p_zip: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_country must be a string" }) - @IsDefined({ message: "Property p_country is required" }) - p_country: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_country must be a string' }) + @IsDefined({ message: 'Property p_country is required' }) + p_country: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_issuingregion must be a string" }) - @IsDefined({ message: "Property p_issuingregion is required" }) - p_issuingregion: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_issuingregion must be a string' }) + @IsDefined({ message: 'Property p_issuingregion is required' }) + p_issuingregion: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_replacementregion must be a string" }) - @IsDefined({ message: "Property p_replacementregion is required" }) - p_replacementregion: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_replacementregion must be a string' }) + @IsDefined({ message: 'Property p_replacementregion is required' }) + p_replacementregion: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_bondsurety must be a string" }) - @IsDefined({ message: "Property p_bondsurety is required" }) - p_bondsurety: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_bondsurety must be a string' }) + @IsDefined({ message: 'Property p_bondsurety is required' }) + p_bondsurety: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_cargopolicyno must be a string" }) - @IsDefined({ message: "Property p_cargopolicyno is required" }) - p_cargopolicyno: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_cargopolicyno must be a string' }) + @IsDefined({ message: 'Property p_cargopolicyno is required' }) + p_cargopolicyno: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_cargosurety must be a string" }) - @IsDefined({ message: "Property p_cargosurety is required" }) - p_cargosurety: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_cargosurety must be a string' }) + @IsDefined({ message: 'Property p_cargosurety is required' }) + p_cargosurety: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_user_id must be a string" }) - @IsDefined({ message: "Property p_user_id is required" }) - p_user_id: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_user_id must be a string' }) + @IsDefined({ message: 'Property p_user_id is required' }) + p_user_id: string; - @ApiProperty({ required: false }) - @IsString({ message: "Property P_NOTES must be a string" }) - @IsOptional() - P_NOTES?: string; + @ApiProperty({ required: false }) + @IsString({ message: 'Property P_NOTES must be a string' }) + @IsOptional() + P_NOTES?: string; - @ApiProperty({ required: false }) - @IsString({ message: "Property P_FILEIDS must be a string" }) - @IsOptional() - P_FILEIDS?: string; + @ApiProperty({ required: false }) + @IsString({ message: 'Property P_FILEIDS must be a string' }) + @IsOptional() + P_FILEIDS?: string; } export class UpdateServiceProviderDTO { - @ApiProperty({ required: true }) - @IsNumber({}, { message: "Property p_spid must be a number" }) - @IsDefined({ message: "Property p_spid is required" }) - p_spid: number; + @ApiProperty({ required: true }) + @IsNumber({}, { message: 'Property p_spid must be a number' }) + @IsDefined({ message: 'Property p_spid is required' }) + p_spid: number; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_name must be a string" }) - @IsDefined({ message: "Property p_name is required" }) - p_name: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_name must be a string' }) + @IsDefined({ message: 'Property p_name is required' }) + p_name: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_lookupcode must be a string" }) - @IsDefined({ message: "Property p_lookupcode is required" }) - p_lookupcode: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_lookupcode must be a string' }) + @IsDefined({ message: 'Property p_lookupcode is required' }) + p_lookupcode: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_address1 must be a string" }) - @IsDefined({ message: "Property p_address1 is required" }) - p_address1: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_address1 must be a string' }) + @IsDefined({ message: 'Property p_address1 is required' }) + p_address1: string; - @ApiProperty({ required: false }) - @IsString({ message: "Property p_address2 must be a string" }) - @IsOptional() - p_address2?: string; + @ApiProperty({ required: false }) + @IsString({ message: 'Property p_address2 must be a string' }) + @IsOptional() + p_address2?: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_city must be a string" }) - @IsDefined({ message: "Property p_city is required" }) - p_city: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_city must be a string' }) + @IsDefined({ message: 'Property p_city is required' }) + p_city: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_state must be a string" }) - @IsDefined({ message: "Property p_state is required" }) - p_state: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_state must be a string' }) + @IsDefined({ message: 'Property p_state is required' }) + p_state: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_zip must be a string" }) - @IsDefined({ message: "Property p_zip is required" }) - p_zip: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_zip must be a string' }) + @IsDefined({ message: 'Property p_zip is required' }) + p_zip: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_country must be a string" }) - @IsDefined({ message: "Property p_country is required" }) - p_country: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_country must be a string' }) + @IsDefined({ message: 'Property p_country is required' }) + p_country: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_issuingregion must be a string" }) - @IsDefined({ message: "Property p_issuingregion is required" }) - p_issuingregion: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_issuingregion must be a string' }) + @IsDefined({ message: 'Property p_issuingregion is required' }) + p_issuingregion: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_replacementregion must be a string" }) - @IsDefined({ message: "Property p_replacementregion is required" }) - p_replacementregion: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_replacementregion must be a string' }) + @IsDefined({ message: 'Property p_replacementregion is required' }) + p_replacementregion: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_bondsurety must be a string" }) - @IsDefined({ message: "Property p_bondsurety is required" }) - p_bondsurety: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_bondsurety must be a string' }) + @IsDefined({ message: 'Property p_bondsurety is required' }) + p_bondsurety: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_cargopolicyno must be a string" }) - @IsDefined({ message: "Property p_cargopolicyno is required" }) - p_cargopolicyno: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_cargopolicyno must be a string' }) + @IsDefined({ message: 'Property p_cargopolicyno is required' }) + p_cargopolicyno: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_cargosurety must be a string" }) - @IsDefined({ message: "Property p_cargosurety is required" }) - p_cargosurety: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_cargosurety must be a string' }) + @IsDefined({ message: 'Property p_cargosurety is required' }) + p_cargosurety: string; - @ApiProperty({ required: true }) - @IsString({ message: "Property p_user_id must be a string" }) - @IsDefined({ message: "Property p_user_id is required" }) - p_user_id: string; + @ApiProperty({ required: true }) + @IsString({ message: 'Property p_user_id must be a string' }) + @IsDefined({ message: 'Property p_user_id is required' }) + p_user_id: string; - @ApiProperty({ required: false }) - @IsString({ message: "Property P_NOTES must be a string" }) - @IsOptional() - P_NOTES?: string; + @ApiProperty({ required: false }) + @IsString({ message: 'Property P_NOTES must be a string' }) + @IsOptional() + P_NOTES?: string; - @ApiProperty({ required: false }) - @IsString({ message: "Property P_FILEIDS must be a string" }) - @IsOptional() - P_FILEIDS?: string; + @ApiProperty({ required: false }) + @IsString({ message: 'Property P_FILEIDS must be a string' }) + @IsOptional() + P_FILEIDS?: string; } -export class getSelectedServiceproviderDTO{ - @ApiProperty({ required: true }) - @Min(0, { message: "Property p_spid must be at least 0" }) - @IsInt({ message: "Property p_SPid must be a whole number" }) - @Transform(({ value }) => Number(value)) - @IsNumber({}, { message: "Property p_spid must be a number" }) - @IsDefined({ message: "Property p_spid is required" }) - p_spid:number; +export class getSelectedServiceproviderDTO { + @ApiProperty({ required: true }) + @Min(0, { message: 'Property p_spid must be at least 0' }) + @IsInt({ message: 'Property p_SPid must be a whole number' }) + @Transform(({ value }) => Number(value)) + @IsNumber({}, { message: 'Property p_spid must be a number' }) + @IsDefined({ message: 'Property p_spid is required' }) + p_spid: number; } - diff --git a/src/oracle/uscib-managed-sp/sp/sp.module.ts b/src/oracle/uscib-managed-sp/sp/sp.module.ts index 774e3e0..c65a3ab 100644 --- a/src/oracle/uscib-managed-sp/sp/sp.module.ts +++ b/src/oracle/uscib-managed-sp/sp/sp.module.ts @@ -4,6 +4,6 @@ import { SpService } from './sp.service'; @Module({ controllers: [SpController], - providers: [SpService] + providers: [SpService], }) export class SpModule {} diff --git a/src/oracle/uscib-managed-sp/sp/sp.service.ts b/src/oracle/uscib-managed-sp/sp/sp.service.ts index d5b7781..85777d0 100644 --- a/src/oracle/uscib-managed-sp/sp/sp.service.ts +++ b/src/oracle/uscib-managed-sp/sp/sp.service.ts @@ -1,25 +1,26 @@ import { Injectable } from '@nestjs/common'; import { OracleDBService } from 'src/db/db.service'; -import * as oracledb from 'oracledb' -import { getSelectedServiceproviderDTO, InsertNewServiceProviderDTO, UpdateServiceProviderDTO } from './sp.dto'; +import * as oracledb from 'oracledb'; +import { + getSelectedServiceproviderDTO, + InsertNewServiceProviderDTO, + UpdateServiceProviderDTO, +} from './sp.dto'; @Injectable() export class SpService { + constructor(private readonly oracleDBService: OracleDBService) {} - constructor(private readonly oracleDBService: OracleDBService) { } + async insertNewServiceProvider(body: InsertNewServiceProviderDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - async insertNewServiceProvider(body: InsertNewServiceProviderDTO) { - - let connection; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN USCIB_Managed_Pkg.InsertNewSP( :p_name, :p_lookupcode, @@ -38,105 +39,106 @@ export class SpService { :P_NOTES, :P_FILEIDS, :p_cursor); - END;`, { - p_name: { - val: body.p_name, - type: oracledb.DB_TYPE_VARCHAR - }, - p_lookupcode: { - val: body.p_lookupcode, - type: oracledb.DB_TYPE_VARCHAR - }, - p_address1: { - val: body.p_address1, - type: oracledb.DB_TYPE_VARCHAR - }, - p_address2: { - val: body.p_address2, - type: oracledb.DB_TYPE_VARCHAR - }, - p_city: { - val: body.p_city, - type: oracledb.DB_TYPE_VARCHAR - }, - p_state: { - val: body.p_state, - type: oracledb.DB_TYPE_VARCHAR - }, - p_zip: { - val: body.p_zip, - type: oracledb.DB_TYPE_VARCHAR - }, - p_country: { - val: body.p_country, - type: oracledb.DB_TYPE_VARCHAR - }, - p_issuingregion: { - val: body.p_issuingregion, - type: oracledb.DB_TYPE_VARCHAR - }, - p_replacementregion: { - val: body.p_replacementregion, - type: oracledb.DB_TYPE_VARCHAR - }, - p_bondsurety: { - val: body.p_bondsurety, - type: oracledb.DB_TYPE_VARCHAR - }, - p_cargopolicyno: { - val: body.p_cargopolicyno, - type: oracledb.DB_TYPE_VARCHAR - }, - p_cargosurety: { - val: body.p_cargosurety, - type: oracledb.DB_TYPE_VARCHAR - }, - p_user_id: { - val: body.p_user_id, - type: oracledb.DB_TYPE_VARCHAR - }, - P_NOTES: { - val: body.P_NOTES, - type: oracledb.DB_TYPE_VARCHAR - }, - P_FILEIDS: { - val: body.P_FILEIDS, - type: oracledb.DB_TYPE_VARCHAR - }, + END;`, + { + p_name: { + val: body.p_name, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_lookupcode: { + val: body.p_lookupcode, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_address1: { + val: body.p_address1, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_address2: { + val: body.p_address2, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_city: { + val: body.p_city, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_state: { + val: body.p_state, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_zip: { + val: body.p_zip, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_country: { + val: body.p_country, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_issuingregion: { + val: body.p_issuingregion, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_replacementregion: { + val: body.p_replacementregion, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_bondsurety: { + val: body.p_bondsurety, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_cargopolicyno: { + val: body.p_cargopolicyno, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_cargosurety: { + val: body.p_cargosurety, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_user_id: { + val: body.p_user_id, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_NOTES: { + val: body.P_NOTES, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_FILEIDS: { + val: body.P_FILEIDS, + type: oracledb.DB_TYPE_VARCHAR, + }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); - await connection.commit(); + 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) { - - return { error: err.message } - } finally { } + const fres = await result.outBinds.p_cursor.getRows(); + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } - async updateServiceProvider(body: UpdateServiceProviderDTO) { + async updateServiceProvider(body: UpdateServiceProviderDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - let connection; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN USCIB_Managed_Pkg.UpdateSP( :p_spid, :p_name, @@ -156,197 +158,197 @@ export class SpService { :P_NOTES, :P_FILEIDS, :p_cursor); - END;`, { - p_spid: { - val: body.p_spid, - type: oracledb.DB_TYPE_NUMBER - }, - p_name: { - val: body.p_name, - type: oracledb.DB_TYPE_VARCHAR - }, - p_lookupcode: { - val: body.p_lookupcode, - type: oracledb.DB_TYPE_VARCHAR - }, - p_address1: { - val: body.p_address1, - type: oracledb.DB_TYPE_VARCHAR - }, - p_address2: { - val: body.p_address2, - type: oracledb.DB_TYPE_VARCHAR - }, - p_city: { - val: body.p_city, - type: oracledb.DB_TYPE_VARCHAR - }, - p_state: { - val: body.p_state, - type: oracledb.DB_TYPE_VARCHAR - }, - p_zip: { - val: body.p_zip, - type: oracledb.DB_TYPE_VARCHAR - }, - p_country: { - val: body.p_country, - type: oracledb.DB_TYPE_VARCHAR - }, - p_issuingregion: { - val: body.p_issuingregion, - type: oracledb.DB_TYPE_VARCHAR - }, - p_replacementregion: { - val: body.p_replacementregion, - type: oracledb.DB_TYPE_VARCHAR - }, - p_bondsurety: { - val: body.p_bondsurety, - type: oracledb.DB_TYPE_VARCHAR - }, - p_cargopolicyno: { - val: body.p_cargopolicyno, - type: oracledb.DB_TYPE_VARCHAR - }, - p_cargosurety: { - val: body.p_cargosurety, - type: oracledb.DB_TYPE_VARCHAR - }, - p_user_id: { - val: body.p_user_id, - type: oracledb.DB_TYPE_VARCHAR - }, - P_NOTES: { - val: body.P_NOTES, - type: oracledb.DB_TYPE_VARCHAR - }, - P_FILEIDS: { - val: body.P_FILEIDS, - type: oracledb.DB_TYPE_VARCHAR - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + END;`, + { + p_spid: { + val: body.p_spid, + type: oracledb.DB_TYPE_NUMBER, + }, + p_name: { + val: body.p_name, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_lookupcode: { + val: body.p_lookupcode, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_address1: { + val: body.p_address1, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_address2: { + val: body.p_address2, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_city: { + val: body.p_city, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_state: { + val: body.p_state, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_zip: { + val: body.p_zip, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_country: { + val: body.p_country, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_issuingregion: { + val: body.p_issuingregion, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_replacementregion: { + val: body.p_replacementregion, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_bondsurety: { + val: body.p_bondsurety, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_cargopolicyno: { + val: body.p_cargopolicyno, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_cargosurety: { + val: body.p_cargosurety, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_user_id: { + val: body.p_user_id, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_NOTES: { + val: body.P_NOTES, + type: oracledb.DB_TYPE_VARCHAR, + }, + P_FILEIDS: { + val: body.P_FILEIDS, + type: oracledb.DB_TYPE_VARCHAR, + }, + p_cursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); - await connection.commit(); + await connection.commit(); - let fres = await result.outBinds.p_cursor.getRows(); - - return fres - - } catch (err) { - - return { error: err.message } - } finally { } + const fres = await result.outBinds.p_cursor.getRows(); + return fres; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } - async getAllServiceproviders() { + async getAllServiceproviders() { + let connection; + let rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - let connection; - let rows = []; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN USCIB_Managed_Pkg.GetAllSPs(:p_cursor); END;`, - { - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT - } - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT - } - ); + { + 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; + 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); + do { + rowsBatch = await cursor.getRows(100); + rows = rows.concat(rowsBatch); + } while (rowsBatch.length > 0); - - await cursor.close(); - - return rows; - } else { - throw new Error('No cursor returned from the stored procedure'); - } - - } catch (err) { - - return { error: err.message } - } finally { } + await cursor.close(); + return rows; + } else { + throw new Error('No cursor returned from the stored procedure'); + } + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } } + } - async getServiceproviderByID(body:getSelectedServiceproviderDTO) { + async getServiceproviderByID(body: getSelectedServiceproviderDTO) { + let connection; + let rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } - let connection; - let rows = []; - try { - - connection = await this.oracleDBService.getConnection() - if (!connection) { - throw new Error('No DB Connected') - } - - const result = await connection.execute( - `BEGIN + const result = await connection.execute( + `BEGIN USCIB_Managed_Pkg.GetSPbySPID(: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 - } - ); + { + 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; + 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); + 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) { - - return { error: err.message } - } finally { } + 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' }; + } } + } } diff --git a/src/oracle/uscib-managed-sp/uscib-managed-sp.module.ts b/src/oracle/uscib-managed-sp/uscib-managed-sp.module.ts index 830fd5c..0598223 100644 --- a/src/oracle/uscib-managed-sp/uscib-managed-sp.module.ts +++ b/src/oracle/uscib-managed-sp/uscib-managed-sp.module.ts @@ -7,6 +7,6 @@ import { CarnetSequenceModule } from './carnet-sequence/carnet-sequence.module'; @Module({ controllers: [], providers: [], - imports: [RegionModule, SpModule, SpContactsModule, CarnetSequenceModule] + imports: [RegionModule, SpModule, SpContactsModule, CarnetSequenceModule], }) export class UscibManagedSpModule {}