129 lines
5.6 KiB
TypeScript
129 lines
5.6 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { MssqlDBService } from 'src/db/db.service';
|
|
import * as mssql from 'mssql';
|
|
import { Request } from 'mssql';
|
|
import {
|
|
ActivateOrInactivateParamRecordDTO,
|
|
CreateParamRecordDTO,
|
|
CreateTableRecordDTO,
|
|
getParamValuesDTO,
|
|
UpdateParamRecordDTO,
|
|
} from '../../oracle/param-table/param-table.dto';
|
|
import { Connection } from 'mssql';
|
|
|
|
@Injectable()
|
|
export class ParamTableService {
|
|
constructor(private readonly mssqlDBService: MssqlDBService) { }
|
|
|
|
async GETPARAMVALUES(body: getParamValuesDTO) {
|
|
const finalBody = {
|
|
P_SPID: body.P_SPID === 0 ? body.P_SPID : body.P_SPID ? body.P_SPID : null,
|
|
P_PARAMTYPE: body.P_PARAMTYPE ? body.P_PARAMTYPE : null,
|
|
};
|
|
|
|
console.log(finalBody);
|
|
|
|
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('P_SPID', mssql.Int, finalBody.P_SPID);
|
|
request.input('P_PARAMTYPE', mssql.VarChar(100), finalBody.P_PARAMTYPE);
|
|
const result = await request.execute('carnetsys.GETPARAMVALUES');
|
|
return { data: result.recordset };
|
|
} catch (error) {
|
|
return { error: error.message };
|
|
}
|
|
|
|
}
|
|
|
|
async CREATETABLERECORD(body: CreateTableRecordDTO) {
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('P_USERID', mssql.VarChar(100), body.P_USERID);
|
|
request.input('P_TABLEFULLDESC', mssql.NVarChar, body.P_TABLEFULLDESC);
|
|
const result = await request.execute('carnetsys.CREATETABLERECORD');
|
|
return { data: result.recordset };
|
|
} catch (error) {
|
|
return { error: error.message };
|
|
}
|
|
}
|
|
|
|
async CREATEPARAMRECORD(body: CreateParamRecordDTO) {
|
|
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_PARAMTYPE', mssql.VarChar(255), body.P_PARAMTYPE);
|
|
request.input('P_PARAMDESC', mssql.VarChar(255), body.P_PARAMDESC);
|
|
request.input('P_PARAMVALUE', mssql.VarChar(255), body.P_PARAMVALUE);
|
|
request.input('P_ADDLPARAMVALUE1', mssql.VarChar(255), body.P_ADDLPARAMVALUE1);
|
|
request.input('P_ADDLPARAMVALUE2', mssql.VarChar(255), body.P_ADDLPARAMVALUE2);
|
|
request.input('P_ADDLPARAMVALUE3', mssql.VarChar(255), body.P_ADDLPARAMVALUE3);
|
|
request.input('P_ADDLPARAMVALUE4', mssql.VarChar(255), body.P_ADDLPARAMVALUE4);
|
|
request.input('P_ADDLPARAMVALUE5', mssql.VarChar(255), body.P_ADDLPARAMVALUE5);
|
|
request.input('P_SORTSEQ', mssql.Int, body.P_SORTSEQ);
|
|
request.input('P_USERID', mssql.VarChar(100), body.P_USERID);
|
|
const result = await request.execute('carnetsys.CREATEPARAMRECORD');
|
|
return { data: result.recordset };
|
|
} catch (error) {
|
|
return { error: error.message };
|
|
}
|
|
}
|
|
|
|
async UPDATEPARAMRECORD(body: UpdateParamRecordDTO) {
|
|
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_PARAMDESC', mssql.VarChar(255), body.P_PARAMDESC);
|
|
request.input('P_ADDLPARAMVALUE1', mssql.VarChar(255), body.P_ADDLPARAMVALUE1);
|
|
request.input('P_ADDLPARAMVALUE2', mssql.VarChar(255), body.P_ADDLPARAMVALUE2);
|
|
request.input('P_ADDLPARAMVALUE3', mssql.VarChar(255), body.P_ADDLPARAMVALUE3);
|
|
request.input('P_ADDLPARAMVALUE4', mssql.VarChar(255), body.P_ADDLPARAMVALUE4);
|
|
request.input('P_ADDLPARAMVALUE5', mssql.VarChar(255), body.P_ADDLPARAMVALUE5);
|
|
request.input('P_SORTSEQ', mssql.Int, body.P_SORTSEQ);
|
|
request.input('P_USERID', mssql.VarChar(100), body.P_USERID);
|
|
const result = await request.execute('carnetsys.UPDATEPARAMRECORD');
|
|
return { data: result.recordset };
|
|
} catch (error) {
|
|
return { error: error.message };
|
|
}
|
|
}
|
|
|
|
async INACTIVATEPARAMRECORD(body: ActivateOrInactivateParamRecordDTO) {
|
|
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('P_PARAMID', mssql.Int, body.P_PARAMID);
|
|
request.input('P_USERID', mssql.VarChar(100), body.P_USERID);
|
|
const result = await request.execute('carnetsys.INACTIVATEPARAMRECORD');
|
|
return { data: result.recordset };
|
|
} catch (error) {
|
|
return { error: error.message };
|
|
}
|
|
}
|
|
|
|
async REACTIVATEPARAMRECORD(body: ActivateOrInactivateParamRecordDTO) {
|
|
let connection: Connection;
|
|
try {
|
|
connection = await this.mssqlDBService.getConnection();
|
|
const request = new Request(connection);
|
|
request.input('P_PARAMID', mssql.Int, body.P_PARAMID);
|
|
request.input('P_USERID', mssql.VarChar(100), body.P_USERID);
|
|
const result = await request.execute('carnetsys.REACTIVATEPARAMRECORD');
|
|
return { data: result.recordset };
|
|
} catch (error) {
|
|
return { error: error.message };
|
|
}
|
|
}
|
|
}
|