530 lines
25 KiB
TypeScript
530 lines
25 KiB
TypeScript
import { Injectable, Logger } from '@nestjs/common';
|
|
import { MssqlDBService } from 'src/db/db.service';
|
|
import { InternalServerException } from 'src/exceptions/internalServerError.exception';
|
|
import { BadRequestException } from 'src/exceptions/badRequest.exception';
|
|
import { Connection, Request } from 'mssql';
|
|
import * as mssql from 'mssql';
|
|
import {
|
|
CreateBasicFeeDTO, CreateBondRateDTO, CreateCargoRateDTO, CreateCfFeeDTO, CreateCsFeeDTO,
|
|
CreateEfFeeDTO, CreateFeeCommDTO, GetFeeGeneralDTO, UpdateBasicFeeDTO, UpdateBondRateDTO,
|
|
UpdateCargoRateDTO, UpdateCfFeeDTO, UpdateCsFeeDTO, UpdateEfFeeDTO, UpdateFeeCommDTO
|
|
} from 'src/dto/manage-fee/manage-fee.dto';
|
|
|
|
@Injectable()
|
|
export class ManageFeeService {
|
|
|
|
private readonly logger = new Logger(ManageFeeService.name);
|
|
|
|
constructor(private readonly mssqlDBService: MssqlDBService) { }
|
|
|
|
// Basic Fee Setup
|
|
|
|
async GETBASICFEERATES(body: GetFeeGeneralDTO): Promise<any[] | Object> {
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('p_spid', mssql.Int, body.P_SPID);
|
|
request.input('p_active_inactive', mssql.VarChar(8), body.P_ACTIVE_INACTIVE);
|
|
const result = await request.execute('carnetsys.GetBasicFeeRates');
|
|
if (result.recordset) {
|
|
if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`);
|
|
throw new BadRequestException(result.recordset[0].ERRORMESG);
|
|
}
|
|
return result.recordset;
|
|
}
|
|
throw new BadRequestException();
|
|
} catch (error) {
|
|
throw new InternalServerException(error.message);
|
|
}
|
|
}
|
|
|
|
async CREATEBASICFEE(body: CreateBasicFeeDTO) {
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('P_SPID', mssql.Int, body.P_SPID);
|
|
request.input('P_STARTCARNETVALUE', mssql.Int, body.P_STARTNUMBER);
|
|
request.input('P_ENDCARNETVALUE', mssql.Int, body.P_ENDNUMBER);
|
|
request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE);
|
|
request.input('P_FEES', mssql.Int, body.P_FEES);
|
|
request.input('P_USERID', mssql.VarChar(100), body.P_USERID);
|
|
const result = await request.execute('carnetsys.CreateBasicFee');
|
|
if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`);
|
|
throw new BadRequestException(result.recordset[0].ERRORMESG);
|
|
}
|
|
return { statusCode: 201, message: "Created Successfully", ...result.recordset[0] };
|
|
} catch (error) {
|
|
throw new InternalServerException(error.message);
|
|
}
|
|
}
|
|
|
|
async UPDATEBASICFEE(body: UpdateBasicFeeDTO) {
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('P_BASICFEESETUPID', mssql.Int, body.P_BASICFEESETUPID);
|
|
request.input('P_FEES', mssql.Int, body.P_FEES);
|
|
request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE);
|
|
request.input('P_USERID', mssql.VarChar(100), body.P_USERID);
|
|
const result = await request.execute('carnetsys.UpdateBasicFee');
|
|
if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`);
|
|
throw new BadRequestException(result.recordset[0].ERRORMESG);
|
|
}
|
|
return { statusCode: 200, message: "Updated Successfully", ...result.recordset[0] };
|
|
} catch (error) {
|
|
throw new InternalServerException(error.message);
|
|
}
|
|
}
|
|
|
|
// Bond Rate Setup
|
|
|
|
async GETBONDRATES(body: GetFeeGeneralDTO): Promise<any[] | object> {
|
|
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('p_spid', mssql.Int, body.P_SPID);
|
|
request.input('p_active_inactive', mssql.VarChar(8), body.P_ACTIVE_INACTIVE);
|
|
const result = await request.execute('carnetsys.GetBondRates');
|
|
if (result.recordset) {
|
|
if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`);
|
|
throw new BadRequestException(result.recordset[0].ERRORMESG);
|
|
}
|
|
return result.recordset;
|
|
}
|
|
throw new BadRequestException();
|
|
} catch (error) {
|
|
console.log(error);
|
|
|
|
throw new InternalServerException(error.message);
|
|
}
|
|
|
|
}
|
|
|
|
async CREATEBONDRATE(body: CreateBondRateDTO) {
|
|
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('P_SPID', mssql.Int, body.P_SPID);
|
|
request.input('P_HOLDERTYPE', mssql.VarChar(3), body.P_HOLDERTYPE);
|
|
request.input('P_USCIBMEMBERFLAG', mssql.VarChar(100), body.P_USCIBMEMBERFLAG);
|
|
request.input('P_SPCLCOMMODITY', mssql.VarChar(100), body.P_SPCLCOMMODITY);
|
|
request.input('P_SPCLCOUNTRY', mssql.VarChar(100), body.P_SPCLCOUNTRY);
|
|
request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE);
|
|
request.input('P_RATE', mssql.Float, body.P_RATE);
|
|
request.input('P_USERID', mssql.VarChar(100), body.P_USERID);
|
|
const result = await request.execute('carnetsys.CreateBondRate');
|
|
if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`);
|
|
throw new BadRequestException(result.recordset[0].ERRORMESG);
|
|
}
|
|
return { statusCode: 201, message: "Created Successfully", ...result.recordset[0] };
|
|
} catch (error) {
|
|
console.log(error);
|
|
throw new InternalServerException(error.message);
|
|
}
|
|
|
|
}
|
|
|
|
async UPDATEBONDRATE(body: UpdateBondRateDTO) {
|
|
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('P_BONDRATESETUPID', mssql.Int, body.P_BONDRATESETUPID);
|
|
request.input('P_RATE', mssql.Float, body.P_RATE);
|
|
request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE);
|
|
request.input('P_USERID', mssql.VarChar(100), body.P_USERID);
|
|
const result = await request.execute('carnetsys.UpdateBondRate');
|
|
if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`);
|
|
throw new BadRequestException(result.recordset[0].ERRORMESG);
|
|
}
|
|
return { statusCode: 200, message: "Updated Successfully", ...result.recordset[0] };
|
|
} catch (error) {
|
|
throw new InternalServerException(error.message);
|
|
}
|
|
|
|
}
|
|
|
|
// CArgo Rate
|
|
|
|
async GETCARGORATES(body: GetFeeGeneralDTO): Promise<any[] | object> {
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('p_spid', mssql.Int, body.P_SPID);
|
|
request.input('p_active_inactive', mssql.VarChar(8), body.P_ACTIVE_INACTIVE);
|
|
const result = await request.execute('carnetsys.GetCargoRates');
|
|
if (result.recordset) {
|
|
if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`);
|
|
throw new BadRequestException(result.recordset[0].ERRORMESG);
|
|
}
|
|
return result.recordset;
|
|
}
|
|
throw new BadRequestException();
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
throw error
|
|
}
|
|
throw new InternalServerException(error.message);
|
|
}
|
|
}
|
|
|
|
async CREATECARGORATE(body: CreateCargoRateDTO) {
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('P_SPID', mssql.Int, body.P_SPID);
|
|
request.input('P_CARNETTYPE', mssql.VarChar(20), body.P_CARNETTYPE);
|
|
request.input('P_STARTSETS', mssql.Int, body.P_STARTSETS);
|
|
request.input('P_ENDSETS', mssql.Int, body.P_ENDSETS);
|
|
request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE);
|
|
request.input('P_RATE', mssql.Float, body.P_RATE);
|
|
request.input('P_USERID', mssql.VarChar(100), body.P_USERID);
|
|
const result = await request.execute('carnetsys.CreateCargoRate');
|
|
if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`);
|
|
throw new BadRequestException(result.recordset[0].ERRORMESG);
|
|
}
|
|
return { statusCode: 201, message: "Created Successfully", ...result.recordset[0] };
|
|
} catch (error) {
|
|
console.log(error);
|
|
throw new InternalServerException(error.message);
|
|
}
|
|
}
|
|
|
|
async UPDATECARGORATE(body: UpdateCargoRateDTO) {
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('P_CARGORATESETUPID', mssql.Int, body.P_CARGORATESETUPID);
|
|
request.input('P_RATE', mssql.Float, body.P_RATE);
|
|
request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE);
|
|
request.input('P_USERID', mssql.VarChar(100), body.P_USERID);
|
|
const result = await request.execute('carnetsys.UpdateCargoRate');
|
|
if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`);
|
|
throw new BadRequestException(result.recordset[0].ERRORMESG);
|
|
}
|
|
return { statusCode: 200, message: "Updated Successfully", ...result.recordset[0] };
|
|
} catch (error) {
|
|
console.log(error);
|
|
throw new InternalServerException(error.message);
|
|
}
|
|
}
|
|
|
|
// Counter Foil
|
|
|
|
async GETCFFEERATES(body: GetFeeGeneralDTO): Promise<any[]> {
|
|
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('p_spid', mssql.Int, body.P_SPID);
|
|
request.input('p_active_inactive', mssql.VarChar(8), body.P_ACTIVE_INACTIVE);
|
|
const result = await request.execute('carnetsys.GetCFFeeRates');
|
|
if (result.recordset) {
|
|
if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`);
|
|
throw new BadRequestException(result.recordset[0].ERRORMESG);
|
|
}
|
|
return result.recordset;
|
|
}
|
|
throw new BadRequestException();
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
throw error
|
|
}
|
|
throw new InternalServerException(error.message);
|
|
}
|
|
}
|
|
|
|
async CREATECFFEE(body: CreateCfFeeDTO) {
|
|
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('P_SPID', mssql.Int, body.P_SPID);
|
|
request.input('P_STARTSETS', mssql.Int, body.P_STARTSETS);
|
|
request.input('P_ENDSETS', mssql.Int, body.P_ENDSETS);
|
|
request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE);
|
|
request.input('P_CUSTOMERTYPE', mssql.VarChar(20), body.P_CUSTOMERTYPE);
|
|
request.input('P_CARNETTYPE', mssql.VarChar(20), body.P_CARNETTYPE);
|
|
request.input('P_RATE', mssql.Float, body.P_RATE);
|
|
request.input('P_USERID', mssql.VarChar(100), body.P_USERID);
|
|
const result = await request.execute('carnetsys.CreateCFFee');
|
|
if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`);
|
|
throw new BadRequestException(result.recordset[0].ERRORMESG);
|
|
}
|
|
return { statusCode: 201, message: "Created Successfully", ...result.recordset[0] };
|
|
} catch (error) {
|
|
console.log(error);
|
|
throw new InternalServerException(error.message);
|
|
}
|
|
|
|
}
|
|
|
|
async UPDATECFFEE(body: UpdateCfFeeDTO) {
|
|
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('P_CFFEESETUPID', mssql.Int, body.P_CFFEESETUPID);
|
|
request.input('P_RATE', mssql.Float, body.P_RATE);
|
|
request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE);
|
|
request.input('P_USERID', mssql.VarChar(100), body.P_USERID);
|
|
const result = await request.execute('carnetsys.UpdateCFFee');
|
|
if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`);
|
|
throw new BadRequestException(result.recordset[0].ERRORMESG);
|
|
}
|
|
return { statusCode: 200, message: "Updated Successfully", ...result.recordset[0] };
|
|
} catch (error) {
|
|
console.log(error);
|
|
throw new InternalServerException(error.message);
|
|
}
|
|
}
|
|
|
|
// Continuation sheet
|
|
|
|
async GETCSFEERATES(body: GetFeeGeneralDTO): Promise<any[]> {
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('p_spid', mssql.Int, body.P_SPID);
|
|
request.input('p_active_inactive', mssql.VarChar(8), body.P_ACTIVE_INACTIVE);
|
|
const result = await request.execute('carnetsys.GetCSFeeRates');
|
|
if (result.recordset) {
|
|
if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`);
|
|
throw new BadRequestException(result.recordset[0].ERRORMESG);
|
|
}
|
|
return result.recordset;
|
|
}
|
|
throw new BadRequestException();
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
throw error
|
|
}
|
|
throw new InternalServerException(error.message);
|
|
}
|
|
|
|
}
|
|
|
|
async CREATECSFEE(body: CreateCsFeeDTO) {
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('P_SPID', mssql.Int, body.P_SPID);
|
|
request.input('P_CUSTOMERTYPE', mssql.VarChar(20), body.P_CUSTOMERTYPE);
|
|
request.input('P_CARNETTYPE', mssql.VarChar(20), body.P_CARNETTYPE);
|
|
request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE);
|
|
request.input('P_RATE', mssql.Float, body.P_RATE);
|
|
request.input('P_USERID', mssql.VarChar(100), body.P_USERID);
|
|
const result = await request.execute('carnetsys.CreateCSFee');
|
|
if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`);
|
|
throw new BadRequestException(result.recordset[0].ERRORMESG);
|
|
}
|
|
return { statusCode: 201, message: "Created Successfully", ...result.recordset[0] };
|
|
} catch (error) {
|
|
console.log(error);
|
|
throw new InternalServerException(error.message);
|
|
}
|
|
|
|
}
|
|
|
|
async UPDATECSFEE(body: UpdateCsFeeDTO) {
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('P_CSFEESETUPID', mssql.Int, body.P_CSFEESETUPID);
|
|
request.input('P_RATE', mssql.Float, body.P_RATE);
|
|
request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE);
|
|
request.input('P_USERID', mssql.VarChar(100), body.P_USERID);
|
|
const result = await request.execute('carnetsys.UpdateCSFee');
|
|
if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`);
|
|
throw new BadRequestException(result.recordset[0].ERRORMESG);
|
|
}
|
|
return { statusCode: 200, message: "Updated Successfully", ...result.recordset[0] };
|
|
} catch (error) {
|
|
console.log(error);
|
|
throw new InternalServerException(error.message);
|
|
}
|
|
}
|
|
|
|
// Expedited fee
|
|
|
|
async GETEFFEERATES(body: GetFeeGeneralDTO): Promise<any[]> {
|
|
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('p_spid', mssql.Int, body.P_SPID);
|
|
request.input('p_active_inactive', mssql.VarChar(8), body.P_ACTIVE_INACTIVE);
|
|
const result = await request.execute('carnetsys.GetEFFeeRates');
|
|
if (result.recordset) {
|
|
if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`);
|
|
throw new BadRequestException(result.recordset[0].ERRORMESG);
|
|
}
|
|
return result.recordset;
|
|
}
|
|
throw new BadRequestException();
|
|
} catch (error) {
|
|
if (error instanceof BadRequestException) {
|
|
throw error
|
|
}
|
|
throw new InternalServerException(error.message);
|
|
}
|
|
}
|
|
|
|
async CREATEEFFEE(body: CreateEfFeeDTO) {
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('P_SPID', mssql.Int, body.P_SPID);
|
|
request.input('P_CUSTOMERTYPE', mssql.VarChar(20), body.P_CUSTOMERTYPE);
|
|
request.input('P_DELIVERYTYPE', mssql.VarChar(20), body.P_DELIVERYTYPE);
|
|
request.input('P_STARTTIME', mssql.Int, body.P_STARTTIME);
|
|
request.input('P_ENDTIME', mssql.Int, body.P_ENDTIME);
|
|
request.input('P_TIMEZONE', mssql.VarChar(3), body.P_TIMEZONE);
|
|
request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE);
|
|
request.input('P_FEES', mssql.Float, body.P_FEES);
|
|
request.input('P_USERID', mssql.VarChar(100), body.P_USERID);
|
|
const result = await request.execute('carnetsys.CreateEFFee');
|
|
if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`);
|
|
throw new BadRequestException(result.recordset[0].ERRORMESG);
|
|
}
|
|
return { statusCode: 201, message: "Created Successfully", ...result.recordset[0] };
|
|
} catch (error) {
|
|
console.log(error);
|
|
throw new InternalServerException(error.message);
|
|
}
|
|
}
|
|
|
|
async UPDATEEFFEE(body: UpdateEfFeeDTO) {
|
|
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('P_EFFEESETUPID', mssql.Int, body.P_EFFEESETUPID);
|
|
request.input('P_FEES', mssql.Float, body.P_FEES);
|
|
request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE);
|
|
request.input('P_USERID', mssql.VarChar(100), body.P_USERID);
|
|
const result = await request.execute('carnetsys.UpdateEFFee');
|
|
if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`);
|
|
throw new BadRequestException(result.recordset[0].ERRORMESG);
|
|
}
|
|
return { statusCode: 200, message: "Updated Successfully", ...result.recordset[0] };
|
|
} catch (error) {
|
|
console.log(error);
|
|
throw new InternalServerException(error.message);
|
|
}
|
|
}
|
|
|
|
// fee comm
|
|
|
|
async GETFEECOMM(body: GetFeeGeneralDTO): Promise<any[]> {
|
|
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('p_spid', mssql.Int, body.P_SPID);
|
|
request.input('p_active_inactive', mssql.VarChar(8), body.P_ACTIVE_INACTIVE);
|
|
const result = await request.execute('carnetsys.GetFeecomm');
|
|
if (result.recordset) {
|
|
if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`);
|
|
throw new BadRequestException(result.recordset[0].ERRORMESG);
|
|
}
|
|
return result.recordset;
|
|
}
|
|
throw new BadRequestException();
|
|
} catch (error) {
|
|
console.log(error);
|
|
|
|
if (error instanceof BadRequestException) {
|
|
throw error
|
|
}
|
|
throw new InternalServerException(error.message);
|
|
}
|
|
}
|
|
|
|
async CREATEFEECOMM(body: CreateFeeCommDTO) {
|
|
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('P_SPID', mssql.Int, body.P_SPID);
|
|
request.input('P_PARAMID', mssql.Int, body.P_PARAMID);
|
|
request.input('P_COMMRATE', mssql.Float, body.P_COMMRATE);
|
|
request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE);
|
|
request.input('P_USERID', mssql.VarChar(100), body.P_USERID);
|
|
const result = await request.execute('carnetsys.CreateFeeComm');
|
|
console.log(result);
|
|
|
|
if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`);
|
|
throw new BadRequestException(result.recordset[0].ERRORMESG);
|
|
}
|
|
return { statusCode: 201, message: "Created Successfully", ...result.recordset[0] };
|
|
} catch (error) {
|
|
console.log(error);
|
|
throw new InternalServerException(error.message);
|
|
}
|
|
}
|
|
|
|
async UPDATEFEECOMM(body: UpdateFeeCommDTO) {
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('P_FEECOMMID', mssql.Int, body.P_FEECOMMID);
|
|
request.input('P_RATE', mssql.Float, body.P_RATE);
|
|
request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE);
|
|
request.input('P_USERID', mssql.VarChar(100), body.P_USERID);
|
|
const result = await request.execute('carnetsys.UpdateFeeComm');
|
|
if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) {
|
|
this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`);
|
|
throw new BadRequestException(result.recordset[0].ERRORMESG);
|
|
}
|
|
return { statusCode: 200, message: "Updated Successfully", ...result.recordset[0] };
|
|
} catch (error) {
|
|
console.log(error);
|
|
throw new InternalServerException(error.message);
|
|
}
|
|
}
|
|
}
|