2025-04-08 12:47:55 +05:30
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
|
import { MssqlDBService } from 'src/db/db.service';
|
|
|
|
|
import * as mssql from 'mssql'
|
|
|
|
|
import { Connection , Request} from 'mssql';
|
|
|
|
|
import { getSPAllContactsDTO, getSPDefaultcontactDTO, inactivateSPContactDTO } from 'src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.dto';
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class SpContactsService {
|
|
|
|
|
|
|
|
|
|
constructor(private readonly mssqlDBService: MssqlDBService) { }
|
|
|
|
|
|
|
|
|
|
async getSpAllContacts(body:getSPAllContactsDTO) {
|
|
|
|
|
|
|
|
|
|
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.GETSPALLCONTACTS');
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getSPDefaultcontacts(body:getSPDefaultcontactDTO) {
|
|
|
|
|
|
|
|
|
|
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.GETSPDEFAULTCONTACTS');
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async inactivateSPContact(body:inactivateSPContactDTO) {
|
|
|
|
|
|
|
|
|
|
let connection: Connection;
|
|
|
|
|
try {
|
|
|
|
|
connection = await this.mssqlDBService.getConnection();
|
|
|
|
|
const request = new Request(connection);
|
|
|
|
|
request.input('P_SPCONTACTID', mssql.Int, body.p_spcontactid);
|
|
|
|
|
const result = await request.execute('carnetsys.INACTIVATESPCONTACTS');
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|