1692 lines
46 KiB
TypeScript
1692 lines
46 KiB
TypeScript
import { Injectable, Logger } from '@nestjs/common';
|
|
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,
|
|
UpdateFeeCommDTO,
|
|
} from './manage-fee.dto';
|
|
import { BadRequestException } from 'src/exceptions/badRequest.exception';
|
|
import { InternalServerException } from 'src/exceptions/internalServerError.exception';
|
|
|
|
@Injectable()
|
|
export class ManageFeeService {
|
|
private readonly logger = new Logger(ManageFeeService.name);
|
|
|
|
constructor(private readonly oracleDBService: OracleDBService) { }
|
|
|
|
// basic fee
|
|
|
|
async GETBASICFEERATES(body: GetFeeGeneralDTO): Promise<any[]> {
|
|
let connection;
|
|
let rows: any[] = [];
|
|
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
if (!connection) {
|
|
this.logger.error(`Database connection failed`);
|
|
throw new InternalServerException();
|
|
}
|
|
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_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?.p_cursor) {
|
|
const cursor = result.outBinds.p_cursor;
|
|
let rowsBatch;
|
|
|
|
do {
|
|
rowsBatch = await cursor.getRows(100);
|
|
rows = rows.concat(rowsBatch);
|
|
} while (rowsBatch.length > 0);
|
|
|
|
await cursor.close();
|
|
} else {
|
|
this.logger.error(`Invalid response from database procedure`);
|
|
throw new BadRequestException();
|
|
}
|
|
|
|
if (rows.length > 0 && rows[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${rows[0].ERRORMESG}`);
|
|
throw new BadRequestException(rows[0].ERRORMESG);
|
|
}
|
|
|
|
return rows;
|
|
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
this.logger.warn(error.message);
|
|
throw error;
|
|
}
|
|
else if (error.message === "NJS-107: invalid cursor") {
|
|
this.logger.warn(error.message);
|
|
throw new BadRequestException();
|
|
}
|
|
this.logger.error('GETBASICFEERATES failed', error.stack || error);
|
|
throw new InternalServerException();
|
|
} finally {
|
|
if (connection) {
|
|
try {
|
|
await connection.close();
|
|
} catch (closeErr) {
|
|
this.logger.error('Failed to close DB connection', closeErr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
async CREATEBASICFEE(body: CreateBasicFeeDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
if (!connection) {
|
|
this.logger.error(`Database connection failed`);
|
|
throw new InternalServerException();
|
|
}
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
MANAGEFEE_SETUP_PKG.CREATEBASICFEE(
|
|
:P_SPID,
|
|
:P_STARTCARNETVALUE,
|
|
:P_ENDCARNETVALUE,
|
|
:P_EFFDATE,
|
|
:P_FEES,
|
|
: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_CURSOR: {
|
|
type: oracledb.CURSOR,
|
|
dir: oracledb.BIND_OUT,
|
|
},
|
|
},
|
|
{
|
|
outFormat: oracledb.OUT_FORMAT_OBJECT,
|
|
},
|
|
);
|
|
await connection.commit();
|
|
|
|
const fres = await result.outBinds.P_CURSOR.getRows();
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 201, message: "Created Successfully" };
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
this.logger.warn(error.message);
|
|
throw error;
|
|
}
|
|
this.logger.error('CREATEBASICFEE failed', error.stack || error);
|
|
throw new InternalServerException();
|
|
} finally {
|
|
if (connection) {
|
|
try {
|
|
await connection.close();
|
|
} catch (closeErr) {
|
|
this.logger.error('Failed to close DB connection', closeErr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
async UPDATEBASICFEE(body: UpdateBasicFeeDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
if (!connection) {
|
|
this.logger.error(`Database connection failed`);
|
|
throw new InternalServerException();
|
|
}
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
MANAGEFEE_SETUP_PKG.UPDATEBASICFEE(
|
|
:P_BASICFEESETUPID,
|
|
:P_FEES,
|
|
:P_EFFDATE,
|
|
: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();
|
|
|
|
const fres = await result.outBinds.P_CURSOR.getRows();
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Updated Successfully" };
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
this.logger.warn(error.message);
|
|
throw error;
|
|
}
|
|
this.logger.error('UPDATEBASICFEE failed', error.stack || error);
|
|
throw new InternalServerException();
|
|
} finally {
|
|
if (connection) {
|
|
try {
|
|
await connection.close();
|
|
} catch (closeErr) {
|
|
this.logger.error('Failed to close DB connection', closeErr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// bond rate
|
|
|
|
async GETBONDRATES(body: GetFeeGeneralDTO): Promise<any[]> {
|
|
let connection;
|
|
let rows: any = [];
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
if (!connection) {
|
|
this.logger.error(`Database connection failed`);
|
|
throw new InternalServerException();
|
|
}
|
|
|
|
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,
|
|
},
|
|
);
|
|
|
|
if (result.outBinds && result.outBinds.p_cursor) {
|
|
const cursor = result.outBinds.p_cursor;
|
|
let rowsBatch;
|
|
|
|
do {
|
|
rowsBatch = await cursor.getRows(100);
|
|
rows = rows.concat(rowsBatch);
|
|
} while (rowsBatch.length > 0);
|
|
|
|
await cursor.close();
|
|
} else {
|
|
throw new BadRequestException()
|
|
}
|
|
|
|
console.warn(rows);
|
|
|
|
|
|
if (rows.length > 0 && rows[0].ERRORMESG) {
|
|
console.log(rows[0].ERRORMESG);
|
|
throw new BadRequestException(rows[0].ERRORMESG)
|
|
}
|
|
|
|
return rows;
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
this.logger.warn(error.message);
|
|
throw error;
|
|
}
|
|
else if (error.message === "NJS-107: invalid cursor") {
|
|
this.logger.warn(error.message);
|
|
throw new BadRequestException();
|
|
}
|
|
this.logger.error('GETBONDRATES failed', error.stack || error);
|
|
throw new InternalServerException();
|
|
} finally {
|
|
if (connection) {
|
|
try {
|
|
await connection.close();
|
|
} catch (closeErr) {
|
|
this.logger.error('Failed to close DB connection', closeErr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
async CREATEBONDRATE(body: CreateBondRateDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
if (!connection) {
|
|
this.logger.error(`Database connection failed`);
|
|
throw new InternalServerException();
|
|
}
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
MANAGEFEE_SETUP_PKG.CREATEBONDRATE(
|
|
:P_SPID,
|
|
:P_HOLDERTYPE,
|
|
:P_USCIBMEMBERFLAG,
|
|
:P_SPCLCOMMODITY,
|
|
:P_SPCLCOUNTRY,
|
|
:P_EFFDATE,
|
|
:P_RATE,
|
|
: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();
|
|
|
|
const fres = await result.outBinds.P_CURSOR.getRows();
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 201, message: "Created Successfully" };
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
this.logger.warn(error.message);
|
|
throw error;
|
|
}
|
|
this.logger.error('CREATEBONDRATE failed', error.stack || error);
|
|
throw new InternalServerException();
|
|
} finally {
|
|
if (connection) {
|
|
try {
|
|
await connection.close();
|
|
} catch (closeErr) {
|
|
this.logger.error('Failed to close DB connection', closeErr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
async UPDATEBONDRATE(body: UpdateBondRateDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
if (!connection) {
|
|
this.logger.error(`Database connection failed`);
|
|
throw new InternalServerException();
|
|
}
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
MANAGEFEE_SETUP_PKG.UPDATEBONDRATE(
|
|
:P_BONDRATESETUPID,
|
|
:P_RATE,
|
|
:P_EFFDATE,
|
|
: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();
|
|
|
|
const fres = await result.outBinds.P_CURSOR.getRows();
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Updated Successfully" };
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
this.logger.warn(error.message);
|
|
throw error;
|
|
}
|
|
this.logger.error('UPDATEBONDRATE failed', error.stack || error);
|
|
throw new InternalServerException();
|
|
} finally {
|
|
if (connection) {
|
|
try {
|
|
await connection.close();
|
|
} catch (closeErr) {
|
|
this.logger.error('Failed to close DB connection', closeErr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// cargo rate
|
|
|
|
async GETCARGORATES(body: GetFeeGeneralDTO): Promise<any[]> {
|
|
let connection;
|
|
let rows: any = [];
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
if (!connection) {
|
|
this.logger.error(`Database connection failed`);
|
|
throw new InternalServerException();
|
|
}
|
|
|
|
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,
|
|
},
|
|
);
|
|
|
|
if (result.outBinds && result.outBinds.p_cursor) {
|
|
const cursor = result.outBinds.p_cursor;
|
|
let rowsBatch;
|
|
|
|
do {
|
|
rowsBatch = await cursor.getRows(100);
|
|
rows = rows.concat(rowsBatch);
|
|
} while (rowsBatch.length > 0);
|
|
|
|
await cursor.close();
|
|
} else {
|
|
throw new BadRequestException();
|
|
}
|
|
|
|
if (rows.length > 0 && rows[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${rows[0].ERRORMESG}`);
|
|
throw new BadRequestException(rows[0].ERRORMESG);
|
|
}
|
|
|
|
return rows;
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
this.logger.warn(error.message);
|
|
throw error;
|
|
}
|
|
else if (error.message === "NJS-107: invalid cursor") {
|
|
this.logger.warn(error.message);
|
|
throw new BadRequestException();
|
|
}
|
|
this.logger.error('GETCARGORATES failed', error.stack || error);
|
|
throw new InternalServerException();
|
|
} finally {
|
|
// Ensure connection is closed
|
|
if (connection) {
|
|
try {
|
|
await connection.close();
|
|
} catch (closeErr) {
|
|
this.logger.error('Failed to close DB connection', closeErr);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
async CREATECARGORATE(body: CreateCargoRateDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
if (!connection) {
|
|
this.logger.error(`Database connection failed`);
|
|
throw new InternalServerException();
|
|
}
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
MANAGEFEE_SETUP_PKG.CREATECARGORATE(
|
|
:P_SPID,
|
|
:P_CARNETTYPE,
|
|
:P_STARTSETS,
|
|
:P_ENDSETS,
|
|
:P_EFFDATE,
|
|
:P_RATE,
|
|
:P_USERID,
|
|
:P_CURSOR);
|
|
END;`,
|
|
{
|
|
P_SPID: {
|
|
val: body.P_SPID,
|
|
type: oracledb.DB_TYPE_NUMBER,
|
|
},
|
|
P_CARNETTYPE: {
|
|
val: body.P_CARNETTYPE,
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
},
|
|
P_STARTSETS: {
|
|
val: body.P_STARTSETS,
|
|
type: oracledb.DB_TYPE_NUMBER,
|
|
},
|
|
P_ENDSETS: {
|
|
val: body.P_ENDSETS,
|
|
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();
|
|
|
|
const fres = await result.outBinds.P_CURSOR.getRows();
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 201, message: "Created Successfully" };
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
this.logger.warn(error.message);
|
|
throw error;
|
|
}
|
|
this.logger.error('CREATECARGORATE failed', error.stack || error);
|
|
throw new InternalServerException();
|
|
} finally {
|
|
if (connection) {
|
|
try {
|
|
await connection.close();
|
|
} catch (closeErr) {
|
|
this.logger.error('Failed to close DB connection', closeErr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
async UPDATECARGORATE(body: UpdateCargoRateDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
if (!connection) {
|
|
this.logger.error(`Database connection failed`);
|
|
throw new InternalServerException();
|
|
}
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
MANAGEFEE_SETUP_PKG.UPDATECARGORATE(
|
|
:P_CARGORATESETUPID,
|
|
:P_RATE,
|
|
:P_EFFDATE,
|
|
: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();
|
|
|
|
const fres = await result.outBinds.P_CURSOR.getRows();
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Updated Successfully" };
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
this.logger.warn(error.message);
|
|
throw error;
|
|
}
|
|
this.logger.error('UPDATECARGORATE failed', error.stack || error);
|
|
throw new InternalServerException();
|
|
} finally {
|
|
if (connection) {
|
|
try {
|
|
await connection.close();
|
|
} catch (closeErr) {
|
|
this.logger.error('Failed to close DB connection', closeErr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// counter foil
|
|
|
|
async GETCFFEERATES(body: GetFeeGeneralDTO): Promise<any[]> {
|
|
let connection;
|
|
let rows: any = [];
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
if (!connection) {
|
|
this.logger.error(`Database connection failed`);
|
|
throw new InternalServerException();
|
|
}
|
|
|
|
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,
|
|
},
|
|
);
|
|
|
|
if (result.outBinds && result.outBinds.p_cursor) {
|
|
const cursor = result.outBinds.p_cursor;
|
|
let rowsBatch;
|
|
|
|
do {
|
|
rowsBatch = await cursor.getRows(100);
|
|
rows = rows.concat(rowsBatch);
|
|
} while (rowsBatch.length > 0);
|
|
|
|
await cursor.close();
|
|
} else {
|
|
throw new BadRequestException();
|
|
}
|
|
|
|
if (rows.length > 0 && rows[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${rows[0].ERRORMESG}`);
|
|
throw new BadRequestException(rows[0].ERRORMESG);
|
|
}
|
|
|
|
return rows;
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
this.logger.warn(error.message);
|
|
throw error;
|
|
}
|
|
else if (error.message === "NJS-107: invalid cursor") {
|
|
this.logger.warn(error.message);
|
|
throw new BadRequestException();
|
|
}
|
|
this.logger.error('GETCFFEERATES failed', error.stack || error);
|
|
throw new InternalServerException();
|
|
} finally {
|
|
if (connection) {
|
|
try {
|
|
await connection.close();
|
|
} catch (closeErr) {
|
|
this.logger.error('Failed to close DB connection', closeErr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
async CREATECFFEE(body: CreateCfFeeDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
if (!connection) {
|
|
this.logger.error(`Database connection failed`);
|
|
throw new InternalServerException();
|
|
}
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
MANAGEFEE_SETUP_PKG.CREATECFFEE(
|
|
:P_SPID,
|
|
:P_STARTSETS,
|
|
:P_ENDSETS,
|
|
:P_EFFDATE,
|
|
:P_CUSTOMERTYPE,
|
|
:P_CARNETTYPE,
|
|
:P_RATE,
|
|
:P_USERID,
|
|
:P_CURSOR);
|
|
END;`,
|
|
{
|
|
P_SPID: {
|
|
val: body.P_SPID,
|
|
type: oracledb.DB_TYPE_NUMBER,
|
|
},
|
|
P_STARTSETS: {
|
|
val: body.P_STARTSETS,
|
|
type: oracledb.DB_TYPE_NUMBER,
|
|
},
|
|
P_ENDSETS: {
|
|
val: body.P_ENDSETS,
|
|
type: oracledb.DB_TYPE_NUMBER,
|
|
},
|
|
P_EFFDATE: {
|
|
val: body.P_EFFDATE,
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
},
|
|
P_CUSTOMERTYPE: {
|
|
val: body.P_CUSTOMERTYPE,
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
},
|
|
P_CARNETTYPE: {
|
|
val: body.P_CARNETTYPE,
|
|
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();
|
|
|
|
const fres = await result.outBinds.P_CURSOR.getRows();
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 201, message: "Created Successfully" };
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
this.logger.warn(error.message);
|
|
throw error;
|
|
}
|
|
this.logger.error('CREATECFFEE failed', error.stack || error);
|
|
throw new InternalServerException();
|
|
} finally {
|
|
if (connection) {
|
|
try {
|
|
await connection.close();
|
|
} catch (closeErr) {
|
|
this.logger.error('Failed to close DB connection', closeErr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
async UPDATECFFEE(body: UpdateCfFeeDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
if (!connection) {
|
|
this.logger.error(`Database connection failed`);
|
|
throw new InternalServerException();
|
|
}
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
MANAGEFEE_SETUP_PKG.UPDATECFFEE(
|
|
:P_CFFEESETUPID,
|
|
:P_RATE,
|
|
:P_EFFDATE,
|
|
: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();
|
|
|
|
const fres = await result.outBinds.P_CURSOR.getRows();
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Updated Successfully" };
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
this.logger.warn(error.message);
|
|
throw error;
|
|
}
|
|
this.logger.error('UPDATECFFEE failed', error.stack || error);
|
|
throw new InternalServerException();
|
|
} finally {
|
|
if (connection) {
|
|
try {
|
|
await connection.close();
|
|
} catch (closeErr) {
|
|
this.logger.error('Failed to close DB connection', closeErr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// continuation sheet
|
|
|
|
async GETCSFEERATES(body: GetFeeGeneralDTO): Promise<any[]> {
|
|
let connection;
|
|
let rows: any = [];
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
if (!connection) {
|
|
this.logger.error(`Database connection failed`);
|
|
throw new InternalServerException();
|
|
}
|
|
|
|
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,
|
|
},
|
|
);
|
|
|
|
if (result.outBinds && result.outBinds.p_cursor) {
|
|
const cursor = result.outBinds.p_cursor;
|
|
let rowsBatch;
|
|
|
|
do {
|
|
rowsBatch = await cursor.getRows(100);
|
|
rows = rows.concat(rowsBatch);
|
|
} while (rowsBatch.length > 0);
|
|
|
|
await cursor.close();
|
|
} else {
|
|
throw new BadRequestException();
|
|
}
|
|
|
|
if (rows.length > 0 && rows[0].ERRORMESG) {
|
|
console.log(rows[0].ERRORMESG);
|
|
throw new BadRequestException(rows[0].ERRORMESG)
|
|
}
|
|
|
|
return rows;
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
this.logger.warn(error.message);
|
|
throw error;
|
|
}
|
|
else if (error.message === "NJS-107: invalid cursor") {
|
|
this.logger.warn(error.message);
|
|
throw new BadRequestException();
|
|
}
|
|
this.logger.error('GETCSFEERATES failed', error.stack || error);
|
|
throw new InternalServerException();
|
|
} finally {
|
|
if (connection) {
|
|
try {
|
|
await connection.close();
|
|
} catch (closeErr) {
|
|
this.logger.error('Failed to close DB connection', closeErr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
async CREATECSFEE(body: CreateCsFeeDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
if (!connection) {
|
|
this.logger.error(`Database connection failed`);
|
|
throw new InternalServerException();
|
|
}
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
MANAGEFEE_SETUP_PKG.CREATECSFEE(
|
|
:P_SPID,
|
|
:P_CUSTOMERTYPE,
|
|
:P_CARNETTYPE,
|
|
:P_EFFDATE,
|
|
:P_RATE,
|
|
:P_USERID,
|
|
:P_CURSOR);
|
|
END;`,
|
|
{
|
|
P_SPID: {
|
|
val: body.P_SPID,
|
|
type: oracledb.DB_TYPE_NUMBER,
|
|
},
|
|
P_CUSTOMERTYPE: {
|
|
val: body.P_CUSTOMERTYPE,
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
},
|
|
P_CARNETTYPE: {
|
|
val: body.P_CARNETTYPE,
|
|
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();
|
|
|
|
const fres = await result.outBinds.P_CURSOR.getRows();
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 201, message: "Created Successfully" };
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
this.logger.warn(error.message);
|
|
throw error;
|
|
}
|
|
this.logger.error('CREATECSFEE failed', error.stack || error);
|
|
throw new InternalServerException();
|
|
} finally {
|
|
if (connection) {
|
|
try {
|
|
await connection.close();
|
|
} catch (closeErr) {
|
|
this.logger.error('Failed to close DB connection', closeErr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
async UPDATECSFEE(body: UpdateCsFeeDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
if (!connection) {
|
|
this.logger.error(`Database connection failed`);
|
|
throw new InternalServerException();
|
|
}
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
MANAGEFEE_SETUP_PKG.UPDATECSFEE(
|
|
:P_CSFEESETUPID,
|
|
:P_RATE,
|
|
:P_EFFDATE,
|
|
: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();
|
|
|
|
const fres = await result.outBinds.P_CURSOR.getRows();
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Updated Successfully" };
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
this.logger.warn(error.message);
|
|
throw error;
|
|
}
|
|
this.logger.error('UPDATECSFEE failed', error.stack || error);
|
|
throw new InternalServerException();
|
|
} finally {
|
|
if (connection) {
|
|
try {
|
|
await connection.close();
|
|
} catch (closeErr) {
|
|
this.logger.error('Failed to close DB connection', closeErr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// expedited fee
|
|
|
|
async GETEFFEERATES(body: GetFeeGeneralDTO): Promise<any[]> {
|
|
let connection;
|
|
let rows: any = [];
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
if (!connection) {
|
|
this.logger.error(`Database connection failed`);
|
|
throw new InternalServerException();
|
|
}
|
|
|
|
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,
|
|
},
|
|
);
|
|
|
|
if (result.outBinds && result.outBinds.p_cursor) {
|
|
const cursor = result.outBinds.p_cursor;
|
|
let rowsBatch;
|
|
|
|
do {
|
|
rowsBatch = await cursor.getRows(100);
|
|
rows = rows.concat(rowsBatch);
|
|
} while (rowsBatch.length > 0);
|
|
|
|
await cursor.close();
|
|
} else {
|
|
throw new BadRequestException();
|
|
}
|
|
|
|
if (rows.length > 0 && rows[0].ERRORMESG) {
|
|
console.log(rows[0].ERRORMESG);
|
|
throw new BadRequestException(rows[0].ERRORMESG)
|
|
}
|
|
|
|
return rows;
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
this.logger.warn(error.message);
|
|
throw error;
|
|
}
|
|
else if (error.message === "NJS-107: invalid cursor") {
|
|
this.logger.warn(error.message);
|
|
throw new BadRequestException();
|
|
}
|
|
this.logger.error('GETEFFEERATES failed', error.stack || error);
|
|
throw new InternalServerException();
|
|
} finally {
|
|
if (connection) {
|
|
try {
|
|
await connection.close();
|
|
} catch (closeErr) {
|
|
this.logger.error('Failed to close DB connection', closeErr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
async CREATEEFFEE(body: CreateEfFeeDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
if (!connection) {
|
|
this.logger.error(`Database connection failed`);
|
|
throw new InternalServerException();
|
|
}
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
MANAGEFEE_SETUP_PKG.CREATEEFFEE(
|
|
:P_SPID,
|
|
:P_CUSTOMERTYPE,
|
|
:P_DELIVERYTYPE,
|
|
:P_STARTTIME,
|
|
:P_ENDTIME,
|
|
:P_TIMEZONE,
|
|
:P_EFFDATE,
|
|
:P_FEES,
|
|
:P_USERID,
|
|
:P_CURSOR
|
|
);
|
|
END;`,
|
|
{
|
|
P_SPID: {
|
|
val: body.P_SPID,
|
|
type: oracledb.DB_TYPE_NUMBER,
|
|
},
|
|
P_CUSTOMERTYPE: {
|
|
val: body.P_CUSTOMERTYPE,
|
|
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();
|
|
|
|
const fres = await result.outBinds.P_CURSOR.getRows();
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 201, message: "Created Successfully" };
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
this.logger.warn(error.message);
|
|
throw error;
|
|
}
|
|
this.logger.error('CREATEEFFEE failed', error.stack || error);
|
|
throw new InternalServerException();
|
|
} finally {
|
|
if (connection) {
|
|
try {
|
|
await connection.close();
|
|
} catch (closeErr) {
|
|
this.logger.error('Failed to close DB connection', closeErr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
async UPDATEEFFEE(body: UpdateEfFeeDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
if (!connection) {
|
|
this.logger.error(`Database connection failed`);
|
|
throw new InternalServerException();
|
|
}
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
MANAGEFEE_SETUP_PKG.UPDATEEFFEE(
|
|
:P_EFFEESETUPID,
|
|
:P_FEES,
|
|
:P_EFFDATE,
|
|
: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();
|
|
|
|
const fres = await result.outBinds.P_CURSOR.getRows();
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Updated Successfully" };
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
this.logger.warn(error.message);
|
|
throw error;
|
|
}
|
|
this.logger.error('UPDATEEFFEE failed', error.stack || error);
|
|
throw new InternalServerException();
|
|
} finally {
|
|
if (connection) {
|
|
try {
|
|
await connection.close();
|
|
} catch (closeErr) {
|
|
this.logger.error('Failed to close DB connection', closeErr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// fee comm
|
|
|
|
async GETFEECOMM(body: GetFeeGeneralDTO): Promise<any[]> {
|
|
let connection;
|
|
let rows: any = [];
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
if (!connection) {
|
|
this.logger.error(`Database connection failed`);
|
|
throw new InternalServerException();
|
|
}
|
|
|
|
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,
|
|
},
|
|
);
|
|
|
|
if (result.outBinds && result.outBinds.p_cursor) {
|
|
const cursor = result.outBinds.p_cursor;
|
|
let rowsBatch;
|
|
|
|
do {
|
|
rowsBatch = await cursor.getRows(100);
|
|
rows = rows.concat(rowsBatch);
|
|
} while (rowsBatch.length > 0);
|
|
|
|
await cursor.close();
|
|
} else {
|
|
throw new BadRequestException();
|
|
}
|
|
|
|
if (rows.length > 0 && rows[0].ERRORMESG) {
|
|
console.log(rows[0].ERRORMESG);
|
|
throw new BadRequestException(rows[0].ERRORMESG)
|
|
}
|
|
|
|
return rows;
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
this.logger.warn(error.message);
|
|
throw error;
|
|
}
|
|
else if (error.message === "NJS-107: invalid cursor") {
|
|
this.logger.warn(error.message);
|
|
throw new BadRequestException();
|
|
}
|
|
this.logger.error('GETFEECOMM failed\n', error.stack || error);
|
|
throw new InternalServerException();
|
|
} finally {
|
|
if (connection) {
|
|
try {
|
|
await connection.close();
|
|
} catch (closeErr) {
|
|
this.logger.error('Failed to close DB connection', closeErr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
async CREATEFEECOMM(body: CreateFeeCommDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
if (!connection) {
|
|
this.logger.error(`Database connection failed`);
|
|
throw new InternalServerException();
|
|
}
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
MANAGEFEE_SETUP_PKG.CREATEFEECOMM(
|
|
:P_SPID,
|
|
:P_PARAMID,
|
|
:P_COMMRATE,
|
|
:P_EFFDATE,
|
|
: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();
|
|
|
|
const fres = await result.outBinds.P_CURSOR.getRows();
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 201, message: "Created Successfully" };
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
this.logger.warn(error.message);
|
|
throw error;
|
|
}
|
|
this.logger.error('CREATEFEECOMM failed', error.stack || error);
|
|
throw new InternalServerException();
|
|
} finally {
|
|
if (connection) {
|
|
try {
|
|
await connection.close();
|
|
} catch (closeErr) {
|
|
this.logger.error('Failed to close DB connection', closeErr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
async UPDATEFEECOMM(body: UpdateFeeCommDTO) {
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
if (!connection) {
|
|
this.logger.error(`Database connection failed`);
|
|
throw new InternalServerException();
|
|
}
|
|
|
|
const result = await connection.execute(
|
|
`BEGIN
|
|
MANAGEFEE_SETUP_PKG.UPDATEFEECOMM(
|
|
:P_FEECOMMID,
|
|
:P_RATE,
|
|
:P_EFFDATE,
|
|
:P_USERID,
|
|
:P_CURSOR);
|
|
END;`,
|
|
{
|
|
P_FEECOMMID: {
|
|
val: body.P_FEECOMMID,
|
|
type: oracledb.DB_TYPE_NUMBER,
|
|
},
|
|
P_RATE: {
|
|
val: Number(body.P_RATE) | 0,
|
|
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();
|
|
|
|
if (fres.length > 0 && fres[0].ERRORMESG) {
|
|
this.logger.warn(fres[0].ERRORMESG);
|
|
throw new BadRequestException(fres[0].ERRORMESG)
|
|
}
|
|
|
|
return { statusCode: 200, message: "Updated Successfully" };
|
|
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
this.logger.warn(error.message);
|
|
throw error;
|
|
}
|
|
this.logger.error('UPDATEFEECOMM failed', error.stack || error);
|
|
throw new InternalServerException();
|
|
} finally {
|
|
if (connection) {
|
|
try {
|
|
await connection.close();
|
|
} catch (closeErr) {
|
|
this.logger.error('Failed to close DB connection', closeErr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|