2025-04-07 17:10:59 +05:30
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
|
import { Connection, Request } from 'mssql';
|
|
|
|
|
import { MssqlDBService } from 'src/db/db.service';
|
2025-04-09 11:01:35 +05:30
|
|
|
import { getSelectedServiceproviderDTO, InsertNewServiceProviderDTO, UpdateServiceProviderDTO } from 'src/oracle/uscib-managed-sp/sp/sp.dto';
|
2025-04-08 12:47:55 +05:30
|
|
|
import * as mssql from 'mssql'
|
2025-04-07 17:10:59 +05:30
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class SpService {
|
|
|
|
|
|
|
|
|
|
constructor(private readonly mssqlDBService: MssqlDBService) { }
|
|
|
|
|
|
|
|
|
|
async getAllServiceproviders() {
|
|
|
|
|
|
|
|
|
|
let connection: Connection;
|
|
|
|
|
try {
|
|
|
|
|
connection = await this.mssqlDBService.getConnection();
|
|
|
|
|
const request = new Request(connection);
|
|
|
|
|
const result = await request.execute('carnetsys.GETALLSPS');
|
2025-04-08 16:03:54 +05:30
|
|
|
return { data: result.recordset };
|
2025-04-07 17:10:59 +05:30
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error executing stored procedure:', error);
|
|
|
|
|
} finally {
|
|
|
|
|
if (connection) {
|
|
|
|
|
connection.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-04-08 12:47:55 +05:30
|
|
|
|
2025-04-09 11:01:35 +05:30
|
|
|
async getSpBySpid(body: getSelectedServiceproviderDTO) {
|
2025-04-08 12:47:55 +05:30
|
|
|
|
|
|
|
|
let connection: Connection;
|
|
|
|
|
try {
|
|
|
|
|
connection = await this.mssqlDBService.getConnection();
|
|
|
|
|
const request = new Request(connection);
|
|
|
|
|
request.input('P_SPID', mssql.Int, body.p_spid);
|
|
|
|
|
const result = await request.execute('carnetsys.GETSPBYSPID');
|
2025-04-08 16:03:54 +05:30
|
|
|
return { data: result.recordset };
|
2025-04-08 12:47:55 +05:30
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error executing stored procedure:', error);
|
|
|
|
|
} finally {
|
|
|
|
|
if (connection) {
|
|
|
|
|
connection.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-04-09 11:01:35 +05:30
|
|
|
|
|
|
|
|
async insertNewServiceProvider(body: InsertNewServiceProviderDTO) {
|
|
|
|
|
let connection: Connection;
|
|
|
|
|
try {
|
|
|
|
|
connection = await this.mssqlDBService.getConnection();
|
|
|
|
|
const request = new Request(connection);
|
|
|
|
|
request.input('P_NAME', mssql.VarChar(4000), body.p_name);
|
|
|
|
|
request.input('P_LOOKUPCODE', mssql.VarChar(4000), body.p_lookupcode);
|
|
|
|
|
request.input('P_ADDRESS1', mssql.VarChar(4000), body.p_address1);
|
|
|
|
|
request.input('P_ADDRESS2', mssql.VarChar(4000), body.p_address2);
|
|
|
|
|
request.input('P_CITY', mssql.VarChar(4000), body.p_city);
|
|
|
|
|
request.input('P_STATE', mssql.VarChar(4000), body.p_state);
|
|
|
|
|
request.input('P_ZIP', mssql.VarChar(4000), body.p_zip);
|
|
|
|
|
request.input('P_COUNTRY', mssql.VarChar(4000), body.p_country);
|
|
|
|
|
request.input('P_ISSUINGREGION', mssql.VarChar(4000), body.p_issuingregion);
|
|
|
|
|
request.input('P_REPLACEMENTREGION', mssql.VarChar(4000), body.p_replacementregion);
|
|
|
|
|
request.input('P_BONDSURETY', mssql.VarChar(4000), body.p_bondsurety);
|
|
|
|
|
request.input('P_CARGOPOLICYNO', mssql.VarChar(4000), body.p_cargopolicyno);
|
|
|
|
|
request.input('P_CARGOSURETY', mssql.VarChar(4000), body.p_cargosurety);
|
|
|
|
|
request.input('P_USER_ID', mssql.VarChar(4000), body.p_user_id);
|
|
|
|
|
request.input('P_NOTES', mssql.VarChar(4000), body.P_NOTES);
|
|
|
|
|
request.input('P_FILEIDS', mssql.VarChar(4000), body.P_FILEIDS);
|
|
|
|
|
const result = await request.execute('carnetsys.INSERTNEWSP');
|
|
|
|
|
return { data: result.recordset };
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error executing stored procedure:', error);
|
|
|
|
|
return { error: error.message }
|
|
|
|
|
} finally {
|
|
|
|
|
if (connection) {
|
|
|
|
|
connection.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async updateServiceProvider(body: UpdateServiceProviderDTO) {
|
|
|
|
|
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_NAME', mssql.VarChar(4000), body.p_name);
|
|
|
|
|
request.input('P_LOOKUPCODE', mssql.VarChar(4000), body.p_lookupcode);
|
|
|
|
|
request.input('P_ADDRESS1', mssql.VarChar(4000), body.p_address1);
|
|
|
|
|
request.input('P_ADDRESS2', mssql.VarChar(4000), body.p_address2);
|
|
|
|
|
request.input('P_CITY', mssql.VarChar(4000), body.p_city);
|
|
|
|
|
request.input('P_STATE', mssql.VarChar(4000), body.p_state);
|
|
|
|
|
request.input('P_ZIP', mssql.VarChar(4000), body.p_zip);
|
|
|
|
|
request.input('P_COUNTRY', mssql.VarChar(4000), body.p_country);
|
|
|
|
|
request.input('P_BONDSURETY', mssql.VarChar(4000), body.p_bondsurety);
|
|
|
|
|
request.input('P_CARGOPOLICYNO', mssql.VarChar(4000), body.p_cargopolicyno);
|
|
|
|
|
request.input('P_CARGOSURETY', mssql.VarChar(4000), body.p_cargosurety);
|
|
|
|
|
request.input('P_REPLACEMENTREGION', mssql.VarChar(4000), body.p_replacementregion);
|
|
|
|
|
request.input('P_ISSUINGREGION', mssql.VarChar(4000), body.p_issuingregion);
|
|
|
|
|
request.input('P_USER_ID', mssql.VarChar(4000), body.p_user_id);
|
|
|
|
|
request.input('P_NOTES', mssql.VarChar(4000), body.P_NOTES);
|
|
|
|
|
request.input('P_FILEIDS', mssql.VarChar(4000), body.P_FILEIDS);
|
|
|
|
|
const result = await request.execute('carnetsys.UPDATESP');
|
|
|
|
|
return { data: result.recordset };
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error executing stored procedure:', error);
|
|
|
|
|
return { error: error.message }
|
|
|
|
|
} finally {
|
|
|
|
|
if (connection) {
|
|
|
|
|
connection.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-04-07 17:10:59 +05:30
|
|
|
}
|