49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { Connection, Request } from 'mssql';
|
|
import { MssqlDBService } from 'src/db/db.service';
|
|
import { getSelectedServiceproviderDTO } from 'src/oracle/uscib-managed-sp/sp/sp.dto';
|
|
import * as mssql from 'mssql'
|
|
|
|
@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');
|
|
return { data: result.recordset };
|
|
|
|
} catch (error) {
|
|
console.error('Error executing stored procedure:', error);
|
|
} finally {
|
|
if (connection) {
|
|
connection.close();
|
|
}
|
|
}
|
|
}
|
|
|
|
async getSpBySpid(body:getSelectedServiceproviderDTO) {
|
|
|
|
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');
|
|
return { data: result.recordset };
|
|
|
|
} catch (error) {
|
|
console.error('Error executing stored procedure:', error);
|
|
} finally {
|
|
if (connection) {
|
|
connection.close();
|
|
}
|
|
}
|
|
}
|
|
}
|