Files
cod-api/services/history_value.service.js
2025-10-27 10:29:16 +07:00

101 lines
2.9 KiB
JavaScript

const { getHistoryAlarmDb, getHistoryEventDb, checkTableNamedDb, getHistoryValueReportDb, getHistoryValueReportPivotDb, getHistoryValueTrendingPivotDb } = require('../db/history_value.db');
const { getSubSectionByIdDb } = require('../db/plant_sub_section.db');
const { ErrorHandler } = require('../helpers/error');
class HistoryValue {
static async getAllHistoryAlarm(param) {
try {
const results = await getHistoryAlarmDb(param);
results.data.map(element => {
});
return results
} catch (error) {
throw new ErrorHandler(error.statusCode, error.message);
}
}
static async getAllHistoryEvent(param) {
try {
const results = await getHistoryEventDb(param);
results.data.map(element => {
});
return results
} catch (error) {
throw new ErrorHandler(error.statusCode, error.message);
}
}
static async getHistoryValueReport(param) {
try {
const plantSubSection = await getSubSectionByIdDb(param.plant_sub_section_id);
if (plantSubSection.length < 1) throw new ErrorHandler(404, 'Plant sub section not found');
const tabelExist = await checkTableNamedDb(plantSubSection[0]?.table_name_value);
if (tabelExist.length < 1) throw new ErrorHandler(404, 'Value not found');
const results = await getHistoryValueReportDb(tabelExist[0]?.TABLE_NAME, param);
results.data.map(element => {
});
return results
} catch (error) {
throw new ErrorHandler(error.statusCode, error.message);
}
}
static async getHistoryValueReportPivot(param) {
try {
const plantSubSection = await getSubSectionByIdDb(param.plant_sub_section_id);
if (plantSubSection.length < 1) throw new ErrorHandler(404, 'Plant sub section not found');
const tabelExist = await checkTableNamedDb(plantSubSection[0]?.table_name_value);
if (tabelExist.length < 1) throw new ErrorHandler(404, 'Value not found');
const results = await getHistoryValueReportPivotDb(tabelExist[0]?.TABLE_NAME, param);
results.data.map(element => {
});
return results
} catch (error) {
throw new ErrorHandler(error.statusCode, error.message);
}
}
static async getHistoryValueTrendingPivot(param) {
try {
const plantSubSection = await getSubSectionByIdDb(param.plant_sub_section_id);
if (plantSubSection.length < 1) throw new ErrorHandler(404, 'Plant sub section not found');
const tabelExist = await checkTableNamedDb(plantSubSection[0]?.table_name_value);
if (tabelExist.length < 1) throw new ErrorHandler(404, 'Value not found');
const results = await getHistoryValueTrendingPivotDb(tabelExist[0]?.TABLE_NAME, param);
results.data.map(element => {
});
return results
} catch (error) {
throw new ErrorHandler(error.statusCode, error.message);
}
}
}
module.exports = HistoryValue;