BE/src/pg/manage-fee/manage-fee.service.ts
2025-09-17 10:18:44 +05:30

948 lines
29 KiB
TypeScript

import { Injectable } from '@nestjs/common';
import { PgDBService } from 'src/db/db.service';
import { CreateBasicFeeDTO, CreateBondRateDTO, CreateCargoRateDTO, CreateCfFeeDTO, CreateCsFeeDTO, CreateEfFeeDTO, CreateFeeCommDTO, GetFeeGeneralDTO, UpdateBasicFeeDTO, UpdateBondRateDTO, UpdateCargoRateDTO, UpdateCfFeeDTO, UpdateCsFeeDTO, UpdateEfFeeDTO, UpdateFeeCommDTO } from 'src/dto/property.dto';
import { PoolClient } from 'pg';
import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus } from 'src/utils/helper';
@Injectable()
export class ManageFeeService {
constructor(private readonly pgDBService: PgDBService) { }
async GETBASICFEERATES(body: GetFeeGeneralDTO) {
let client: PoolClient | null = null;
const cursorName = 'p_cursor';
try {
client = await this.pgDBService.getConnection();
await client.query('BEGIN');
const callProcQuery = `
CALL "CARNETSYS".managefee_setup_pkg_getbasicfeerates($1, $2, $3)
`;
await client.query(callProcQuery, [body.P_SPID, body.P_ACTIVE_INACTIVE, cursorName]);
// 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
// 🚫 DON'T quote the cursor name in CLOSE
await client.query(`CLOSE ${cursorName}`);
await client.query('COMMIT');
checkPgUserDefinedErrors(fetchResult);
return fetchResult?.rows ? fetchResult?.rows : []
} catch (error) {
if (client) await client.query('ROLLBACK');
handlePgError(error, ManageFeeService.name)
} finally {
releasePgClient(client)
}
}
async CREATEBASICFEE(body: CreateBasicFeeDTO) {
let client: PoolClient | null = null;
const cursorName = 'p_cursor';
try {
client = await this.pgDBService.getConnection();
await client.query('BEGIN');
const callProcQuery = `
CALL "CARNETSYS".managefee_setup_pkg_createbasicfee($1, $2, $3, $4, $5, $6, $7)
`;
await client.query(callProcQuery,
[
body.P_SPID,
body.P_STARTNUMBER,
body.P_ENDNUMBER,
body.P_EFFDATE,
body.P_FEES,
body.P_USERID,
cursorName
]);
// 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
// 🚫 DON'T quote the cursor name in CLOSE
await client.query(`CLOSE ${cursorName}`);
await client.query('COMMIT');
checkPgUserDefinedErrors(fetchResult);
return {
statusCode: 201,
message: ResponseStatus.created,
...fetchResult?.rows?.[0] || {}
};
} catch (error) {
if (client) await client.query('ROLLBACK');
handlePgError(error, ManageFeeService.name)
} finally {
releasePgClient(client)
}
}
async UPDATEBASICFEE(body: UpdateBasicFeeDTO) {
let client: PoolClient | null = null;
const cursorName = 'p_cursor';
try {
client = await this.pgDBService.getConnection();
await client.query('BEGIN');
const callProcQuery = `
CALL "CARNETSYS".managefee_setup_pkg_updatebasicfee($1, $2, $3, $4, $5)
`;
await client.query(callProcQuery,
[
body.P_BASICFEESETUPID,
body.P_FEES,
body.P_EFFDATE,
body.P_USERID,
cursorName
]);
// 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
// 🚫 DON'T quote the cursor name in CLOSE
await client.query(`CLOSE ${cursorName}`);
await client.query('COMMIT');
checkPgUserDefinedErrors(fetchResult);
return {
statusCode: 200,
message: ResponseStatus.updated,
...fetchResult?.rows?.[0] || {}
};
} catch (error) {
if (client) await client.query('ROLLBACK');
handlePgError(error, ManageFeeService.name)
} finally {
releasePgClient(client)
}
}
// bond rate
async GETBONDRATES(body: GetFeeGeneralDTO) {
let client: PoolClient | null = null;
const cursorName = 'p_cursor';
try {
client = await this.pgDBService.getConnection();
await client.query('BEGIN');
const callProcQuery = `
CALL "CARNETSYS".managefee_setup_pkg_getbondrates($1, $2, $3)
`;
await client.query(callProcQuery, [body.P_SPID, body.P_ACTIVE_INACTIVE, cursorName]);
// 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
// 🚫 DON'T quote the cursor name in CLOSE
await client.query(`CLOSE ${cursorName}`);
await client.query('COMMIT');
checkPgUserDefinedErrors(fetchResult);
return fetchResult?.rows ? fetchResult?.rows : []
} catch (error) {
if (client) await client.query('ROLLBACK');
handlePgError(error, ManageFeeService.name)
} finally {
releasePgClient(client)
}
}
async CREATEBONDRATE(body: CreateBondRateDTO) {
let client: PoolClient | null = null;
const cursorName = 'p_cursor';
try {
client = await this.pgDBService.getConnection();
await client.query('BEGIN');
const callProcQuery = `
CALL "CARNETSYS".managefee_setup_pkg_createbondrate($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
`;
await client.query(callProcQuery,
[
body.P_SPID,
body.P_HOLDERTYPE,
body.P_USCIBMEMBERFLAG,
body.P_SPCLCOMMODITY,
body.P_SPCLCOUNTRY,
body.P_EFFDATE,
body.P_RATE,
body.P_USERID,
body.P_PCT_VALUE,
cursorName
]);
// 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
// 🚫 DON'T quote the cursor name in CLOSE
await client.query(`CLOSE ${cursorName}`);
await client.query('COMMIT');
checkPgUserDefinedErrors(fetchResult);
return {
statusCode: 201,
message: ResponseStatus.created,
...fetchResult?.rows?.[0] || {}
};
} catch (error) {
if (client) await client.query('ROLLBACK');
handlePgError(error, ManageFeeService.name)
} finally {
releasePgClient(client)
}
}
async UPDATEBONDRATE(body: UpdateBondRateDTO) {
let client: PoolClient | null = null;
const cursorName = 'p_cursor';
try {
client = await this.pgDBService.getConnection();
await client.query('BEGIN');
const callProcQuery = `
CALL "CARNETSYS".managefee_setup_pkg_updatebondrate($1, $2, $3, $4, $5, $6)
`;
await client.query(callProcQuery,
[
body.P_BONDRATESETUPID,
body.P_RATE,
body.P_EFFDATE,
body.P_USERID,
body.P_PCT_VALUE,
cursorName
]);
// 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
// 🚫 DON'T quote the cursor name in CLOSE
await client.query(`CLOSE ${cursorName}`);
await client.query('COMMIT');
checkPgUserDefinedErrors(fetchResult);
return {
statusCode: 200,
message: ResponseStatus.updated,
...fetchResult?.rows?.[0] || {}
};
} catch (error) {
if (client) await client.query('ROLLBACK');
handlePgError(error, ManageFeeService.name)
} finally {
releasePgClient(client)
}
}
// cargo rate
async GETCARGORATES(body: GetFeeGeneralDTO) {
let client: PoolClient | null = null;
const cursorName = 'p_cursor';
try {
client = await this.pgDBService.getConnection();
await client.query('BEGIN');
const callProcQuery = `
CALL "CARNETSYS".managefee_setup_pkg_getcargorates($1, $2, $3)
`;
await client.query(callProcQuery, [body.P_SPID, body.P_ACTIVE_INACTIVE, cursorName]);
// 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
// 🚫 DON'T quote the cursor name in CLOSE
await client.query(`CLOSE ${cursorName}`);
await client.query('COMMIT');
checkPgUserDefinedErrors(fetchResult);
return fetchResult?.rows ? fetchResult?.rows : []
} catch (error) {
if (client) await client.query('ROLLBACK');
handlePgError(error, ManageFeeService.name)
} finally {
releasePgClient(client)
}
}
async CREATECARGORATE(body: CreateCargoRateDTO) {
let client: PoolClient | null = null;
const cursorName = 'p_cursor';
try {
client = await this.pgDBService.getConnection();
await client.query('BEGIN');
const callProcQuery = `
CALL "CARNETSYS".managefee_setup_pkg_createcargorate($1, $2, $3, $4, $5, $6, $7, $8)
`;
await client.query(callProcQuery,
[
body.P_SPID,
body.P_CARNETTYPE,
body.P_STARTSETS,
body.P_ENDSETS,
body.P_EFFDATE,
body.P_RATE,
body.P_USERID,
cursorName
]);
// 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
// 🚫 DON'T quote the cursor name in CLOSE
await client.query(`CLOSE ${cursorName}`);
await client.query('COMMIT');
checkPgUserDefinedErrors(fetchResult);
return {
statusCode: 201,
message: ResponseStatus.created,
...fetchResult?.rows?.[0] || {}
};
} catch (error) {
if (client) await client.query('ROLLBACK');
handlePgError(error, ManageFeeService.name)
} finally {
releasePgClient(client)
}
}
async UPDATECARGORATE(body: UpdateCargoRateDTO) {
let client: PoolClient | null = null;
const cursorName = 'p_cursor';
try {
client = await this.pgDBService.getConnection();
await client.query('BEGIN');
const callProcQuery = `
CALL "CARNETSYS".managefee_setup_pkg_updatecargorate($1, $2, $3, $4, $5)
`;
await client.query(callProcQuery,
[
body.P_CARGORATESETUPID,
body.P_RATE,
body.P_EFFDATE,
body.P_USERID,
cursorName
]);
// 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
// 🚫 DON'T quote the cursor name in CLOSE
await client.query(`CLOSE ${cursorName}`);
await client.query('COMMIT');
checkPgUserDefinedErrors(fetchResult);
return {
statusCode: 200,
message: ResponseStatus.updated,
...fetchResult?.rows?.[0] || {}
};
} catch (error) {
if (client) await client.query('ROLLBACK');
handlePgError(error, ManageFeeService.name)
} finally {
releasePgClient(client)
}
}
// counter foil
async GETCFFEERATES(body: GetFeeGeneralDTO) {
let client: PoolClient | null = null;
const cursorName = 'p_cursor';
try {
client = await this.pgDBService.getConnection();
await client.query('BEGIN');
const callProcQuery = `
CALL "CARNETSYS".managefee_setup_pkg_getcffeerates($1, $2, $3)
`;
await client.query(callProcQuery, [body.P_SPID, body.P_ACTIVE_INACTIVE, cursorName]);
// 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
// 🚫 DON'T quote the cursor name in CLOSE
await client.query(`CLOSE ${cursorName}`);
await client.query('COMMIT');
checkPgUserDefinedErrors(fetchResult);
return fetchResult?.rows ? fetchResult?.rows : []
} catch (error) {
if (client) await client.query('ROLLBACK');
handlePgError(error, ManageFeeService.name)
} finally {
releasePgClient(client)
}
}
async CREATECFFEE(body: CreateCfFeeDTO) {
let client: PoolClient | null = null;
const cursorName = 'p_cursor';
try {
client = await this.pgDBService.getConnection();
await client.query('BEGIN');
const callProcQuery = `
CALL "CARNETSYS".managefee_setup_pkg_createcffee($1, $2, $3, $4, $5, $6, $7, $8, $9)
`;
await client.query(callProcQuery,
[
body.P_SPID,
body.P_STARTSETS,
body.P_ENDSETS,
body.P_EFFDATE,
body.P_CUSTOMERTYPE,
body.P_CARNETTYPE,
body.P_RATE,
body.P_USERID,
cursorName
]);
// 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
// 🚫 DON'T quote the cursor name in CLOSE
await client.query(`CLOSE ${cursorName}`);
await client.query('COMMIT');
checkPgUserDefinedErrors(fetchResult);
return {
statusCode: 201,
message: ResponseStatus.created,
...fetchResult?.rows?.[0] || {}
};
} catch (error) {
if (client) await client.query('ROLLBACK');
handlePgError(error, ManageFeeService.name)
} finally {
releasePgClient(client)
}
}
async UPDATECFFEE(body: UpdateCfFeeDTO) {
let client: PoolClient | null = null;
const cursorName = 'p_cursor';
try {
client = await this.pgDBService.getConnection();
await client.query('BEGIN');
const callProcQuery = `
CALL "CARNETSYS".managefee_setup_pkg_updatecffee($1, $2, $3, $4, $5)
`;
await client.query(callProcQuery,
[
body.P_CFFEESETUPID,
body.P_RATE,
body.P_EFFDATE,
body.P_USERID,
cursorName
]);
// 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
// 🚫 DON'T quote the cursor name in CLOSE
await client.query(`CLOSE ${cursorName}`);
await client.query('COMMIT');
checkPgUserDefinedErrors(fetchResult);
return {
statusCode: 200,
message: ResponseStatus.updated,
...fetchResult?.rows?.[0] || {}
};
} catch (error) {
if (client) await client.query('ROLLBACK');
handlePgError(error, ManageFeeService.name)
} finally {
releasePgClient(client)
}
}
// continuation sheet
async GETCSFEERATES(body: GetFeeGeneralDTO) {
let client: PoolClient | null = null;
const cursorName = 'p_cursor';
try {
client = await this.pgDBService.getConnection();
await client.query('BEGIN');
const callProcQuery = `
CALL "CARNETSYS".managefee_setup_pkg_getcsfeerates($1, $2, $3)
`;
await client.query(callProcQuery, [body.P_SPID, body.P_ACTIVE_INACTIVE, cursorName]);
// 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
// 🚫 DON'T quote the cursor name in CLOSE
await client.query(`CLOSE ${cursorName}`);
await client.query('COMMIT');
checkPgUserDefinedErrors(fetchResult);
return fetchResult?.rows ? fetchResult?.rows : []
} catch (error) {
if (client) await client.query('ROLLBACK');
handlePgError(error, ManageFeeService.name)
} finally {
releasePgClient(client)
}
}
async CREATECSFEE(body: CreateCsFeeDTO) {
let client: PoolClient | null = null;
const cursorName = 'p_cursor';
try {
client = await this.pgDBService.getConnection();
await client.query('BEGIN');
const callProcQuery = `
CALL "CARNETSYS".managefee_setup_pkg_createcsfee($1, $2, $3, $4, $5, $6, $7)
`;
await client.query(callProcQuery,
[
body.P_SPID,
body.P_CUSTOMERTYPE,
body.P_CARNETTYPE,
body.P_EFFDATE,
body.P_RATE,
body.P_USERID,
cursorName
]);
// 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
// 🚫 DON'T quote the cursor name in CLOSE
await client.query(`CLOSE ${cursorName}`);
await client.query('COMMIT');
checkPgUserDefinedErrors(fetchResult);
return {
statusCode: 201,
message: ResponseStatus.created,
...fetchResult?.rows?.[0] || {}
};
} catch (error) {
if (client) await client.query('ROLLBACK');
handlePgError(error, ManageFeeService.name)
} finally {
releasePgClient(client)
}
}
async UPDATECSFEE(body: UpdateCsFeeDTO) {
let client: PoolClient | null = null;
const cursorName = 'p_cursor';
try {
client = await this.pgDBService.getConnection();
await client.query('BEGIN');
const callProcQuery = `
CALL "CARNETSYS".managefee_setup_pkg_updatecsfee($1, $2, $3, $4, $5)
`;
await client.query(callProcQuery,
[
body.P_CSFEESETUPID,
body.P_RATE,
body.P_EFFDATE,
body.P_USERID,
cursorName
]);
// 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
// 🚫 DON'T quote the cursor name in CLOSE
await client.query(`CLOSE ${cursorName}`);
await client.query('COMMIT');
checkPgUserDefinedErrors(fetchResult);
return {
statusCode: 200,
message: ResponseStatus.updated,
...fetchResult?.rows?.[0] || {}
};
} catch (error) {
if (client) await client.query('ROLLBACK');
handlePgError(error, ManageFeeService.name)
} finally {
releasePgClient(client)
}
}
// expedited fee
async GETEFFEERATES(body: GetFeeGeneralDTO) {
let client: PoolClient | null = null;
const cursorName = 'p_cursor';
try {
client = await this.pgDBService.getConnection();
await client.query('BEGIN');
const callProcQuery = `
CALL "CARNETSYS".managefee_setup_pkg_geteffeerates($1, $2, $3)
`;
await client.query(callProcQuery, [body.P_SPID, body.P_ACTIVE_INACTIVE, cursorName]);
// 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
// 🚫 DON'T quote the cursor name in CLOSE
await client.query(`CLOSE ${cursorName}`);
await client.query('COMMIT');
checkPgUserDefinedErrors(fetchResult);
return fetchResult?.rows ? fetchResult?.rows : []
} catch (error) {
if (client) await client.query('ROLLBACK');
handlePgError(error, ManageFeeService.name)
} finally {
releasePgClient(client)
}
}
async CREATEEFFEE(body: CreateEfFeeDTO) {
let client: PoolClient | null = null;
const cursorName = 'p_cursor';
try {
client = await this.pgDBService.getConnection();
await client.query('BEGIN');
const callProcQuery = `
CALL "CARNETSYS".managefee_setup_pkg_createeffee($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
`;
await client.query(callProcQuery,
[
body.P_SPID,
body.P_CUSTOMERTYPE,
body.P_DELIVERYTYPE,
body.P_STARTTIME,
body.P_ENDTIME,
body.P_TIMEZONE,
body.P_EFFDATE,
body.P_FEES,
body.P_USERID,
cursorName
]);
// 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
// 🚫 DON'T quote the cursor name in CLOSE
await client.query(`CLOSE ${cursorName}`);
await client.query('COMMIT');
checkPgUserDefinedErrors(fetchResult);
return {
statusCode: 201,
message: ResponseStatus.created,
...fetchResult?.rows?.[0] || {}
};
} catch (error) {
if (client) await client.query('ROLLBACK');
handlePgError(error, ManageFeeService.name)
} finally {
releasePgClient(client)
}
}
async UPDATEEFFEE(body: UpdateEfFeeDTO) {
let client: PoolClient | null = null;
const cursorName = 'p_cursor';
try {
client = await this.pgDBService.getConnection();
await client.query('BEGIN');
const callProcQuery = `
CALL "CARNETSYS".managefee_setup_pkg_updateeffee($1, $2, $3, $4, $5)
`;
await client.query(callProcQuery,
[
body.P_EFFEESETUPID,
body.P_FEES,
body.P_EFFDATE,
body.P_USERID,
cursorName
]);
// 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
// 🚫 DON'T quote the cursor name in CLOSE
await client.query(`CLOSE ${cursorName}`);
await client.query('COMMIT');
checkPgUserDefinedErrors(fetchResult);
return {
statusCode: 200,
message: ResponseStatus.updated,
...fetchResult?.rows?.[0] || {}
};
} catch (error) {
if (client) await client.query('ROLLBACK');
handlePgError(error, ManageFeeService.name)
} finally {
releasePgClient(client)
}
}
// fee comm
async GETFEECOMM(body: GetFeeGeneralDTO) {
let client: PoolClient | null = null;
const cursorName = 'p_cursor';
try {
client = await this.pgDBService.getConnection();
await client.query('BEGIN');
const callProcQuery = `
CALL "CARNETSYS".managefee_setup_pkg_getfeecomm($1, $2, $3)
`;
await client.query(callProcQuery, [body.P_SPID, body.P_ACTIVE_INACTIVE, cursorName]);
// 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
// 🚫 DON'T quote the cursor name in CLOSE
await client.query(`CLOSE ${cursorName}`);
await client.query('COMMIT');
checkPgUserDefinedErrors(fetchResult);
return fetchResult?.rows ? fetchResult?.rows : []
} catch (error) {
if (client) await client.query('ROLLBACK');
handlePgError(error, ManageFeeService.name)
} finally {
releasePgClient(client)
}
}
async CREATEFEECOMM(body: CreateFeeCommDTO) {
let client: PoolClient | null = null;
const cursorName = 'p_cursor';
try {
client = await this.pgDBService.getConnection();
await client.query('BEGIN');
const callProcQuery = `
CALL "CARNETSYS".managefee_setup_pkg_createfeecomm($1, $2, $3, $4, $5, $6)
`;
await client.query(callProcQuery,
[
body.P_SPID,
body.P_PARAMID,
body.P_COMMRATE,
body.P_EFFDATE,
body.P_USERID,
cursorName
]);
// 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
// 🚫 DON'T quote the cursor name in CLOSE
await client.query(`CLOSE ${cursorName}`);
await client.query('COMMIT');
checkPgUserDefinedErrors(fetchResult);
return {
statusCode: 201,
message: ResponseStatus.created,
...fetchResult?.rows?.[0] || {}
};
} catch (error) {
if (client) await client.query('ROLLBACK');
handlePgError(error, ManageFeeService.name)
} finally {
releasePgClient(client)
}
}
async UPDATEFEECOMM(body: UpdateFeeCommDTO) {
let client: PoolClient | null = null;
const cursorName = 'p_cursor';
try {
client = await this.pgDBService.getConnection();
await client.query('BEGIN');
const callProcQuery = `
CALL "CARNETSYS".managefee_setup_pkg_updatefeecomm($1, $2, $3, $4, $5)
`;
await client.query(callProcQuery,
[
body.P_FEECOMMID,
body.P_RATE,
body.P_EFFDATE,
body.P_USERID,
cursorName
]);
// 🚫 DON'T quote the cursor name in FETCH
const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`);
// 🚫 DON'T quote the cursor name in CLOSE
await client.query(`CLOSE ${cursorName}`);
await client.query('COMMIT');
checkPgUserDefinedErrors(fetchResult);
return {
statusCode: 200,
message: ResponseStatus.updated,
...fetchResult?.rows?.[0] || {}
};
} catch (error) {
if (client) await client.query('ROLLBACK');
handlePgError(error, ManageFeeService.name)
} finally {
releasePgClient(client)
}
}
}