update value report

This commit is contained in:
Albani Rajata Malik
2025-12-18 13:26:48 +07:00
parent 5e7de6d144
commit c112ff165a
3 changed files with 506 additions and 215 deletions

View File

@@ -1,4 +1,11 @@
const { getHistoryAlarmDb, getHistoryEventDb, checkTableNamedDb, getHistoryValueReportDb, getHistoryValueReportPivotDb, getHistoryValueTrendingPivotDb } = require('../db/history_value.db');
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');
@@ -7,94 +14,128 @@ class HistoryValue {
static async getAllHistoryAlarm(param) {
try {
const results = await getHistoryAlarmDb(param);
results.data.map(element => {
});
return results
return results;
} catch (error) {
throw new ErrorHandler(error.statusCode, error.message);
throw new ErrorHandler(error.statusCode || 500, error.message || 'Error fetching alarm history');
}
}
static async getAllHistoryEvent(param) {
try {
const results = await getHistoryEventDb(param);
results.data.map(element => {
});
return results
return results;
} catch (error) {
throw new ErrorHandler(error.statusCode, error.message);
throw new ErrorHandler(error.statusCode || 500, error.message || 'Error fetching event history');
}
}
static async getHistoryValueReport(param) {
try {
if (!param.plant_sub_section_id) {
throw new ErrorHandler(400, 'plant_sub_section_id is required');
}
const plantSubSection = await getSubSectionByIdDb(param.plant_sub_section_id);
if (plantSubSection.length < 1) throw new ErrorHandler(404, 'Plant sub section not found');
if (!plantSubSection || plantSubSection.length < 1) {
throw new ErrorHandler(404, 'Plant sub section not found');
}
const tabelExist = await checkTableNamedDb(plantSubSection[0]?.table_name_value);
const tableNameValue = plantSubSection[0]?.table_name_value;
if (!tableNameValue) {
throw new ErrorHandler(404, 'Table name not configured for this sub section');
}
if (tabelExist.length < 1) throw new ErrorHandler(404, 'Value not found');
const tableExist = await checkTableNamedDb(tableNameValue);
const results = await getHistoryValueReportDb(tabelExist[0]?.TABLE_NAME, param);
if (!tableExist || tableExist.length < 1) {
throw new ErrorHandler(404, `Value table '${tableNameValue}' not found`);
}
results.data.map(element => {
});
return results
const results = await getHistoryValueReportDb(tableExist[0].TABLE_NAME, param);
return results;
} catch (error) {
throw new ErrorHandler(error.statusCode, error.message);
throw new ErrorHandler(
error.statusCode || 500,
error.message || 'Error fetching history value report'
);
}
}
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);
try {
if (!param.plant_sub_section_id) {
throw new ErrorHandler(400, 'plant_sub_section_id is required');
}
if (!param.from || !param.to) {
throw new ErrorHandler(400, 'from and to date parameters are required');
}
const plantSubSection = await getSubSectionByIdDb(param.plant_sub_section_id);
if (!plantSubSection || plantSubSection.length < 1) {
throw new ErrorHandler(404, 'Plant sub section not found');
}
const tableNameValue = plantSubSection[0]?.table_name_value;
if (!tableNameValue) {
throw new ErrorHandler(404, 'Table name not configured for this sub section');
}
const tableExist = await checkTableNamedDb(tableNameValue);
if (!tableExist || tableExist.length < 1) {
throw new ErrorHandler(404, `Value table '${tableNameValue}' not found`);
}
const results = await getHistoryValueReportPivotDb(tableExist[0].TABLE_NAME, param);
return results;
} catch (error) {
throw new ErrorHandler(
error.statusCode || 500,
error.message || 'Error fetching history value report pivot'
);
}
}
static async getHistoryValueTrendingPivot(param) {
try {
if (!param.plant_sub_section_id) {
throw new ErrorHandler(400, 'plant_sub_section_id is required');
}
if (!param.from || !param.to) {
throw new ErrorHandler(400, 'from and to date parameters are required');
}
const plantSubSection = await getSubSectionByIdDb(param.plant_sub_section_id);
if (plantSubSection.length < 1) throw new ErrorHandler(404, 'Plant sub section not found');
if (!plantSubSection || plantSubSection.length < 1) {
throw new ErrorHandler(404, 'Plant sub section not found');
}
const tabelExist = await checkTableNamedDb(plantSubSection[0]?.table_name_value);
const tableNameValue = plantSubSection[0]?.table_name_value;
if (!tableNameValue) {
throw new ErrorHandler(404, 'Table name not configured for this sub section');
}
if (tabelExist.length < 1) throw new ErrorHandler(404, 'Value not found');
const tableExist = await checkTableNamedDb(tableNameValue);
const results = await getHistoryValueTrendingPivotDb(tabelExist[0]?.TABLE_NAME, param);
if (!tableExist || tableExist.length < 1) {
throw new ErrorHandler(404, `Value table '${tableNameValue}' not found`);
}
results.data.map(element => {
});
return results
const results = await getHistoryValueTrendingPivotDb(tableExist[0].TABLE_NAME, param);
return results;
} catch (error) {
throw new ErrorHandler(error.statusCode, error.message);
throw new ErrorHandler(
error.statusCode || 500,
error.message || 'Error fetching history value trending pivot'
);
}
}
}
module.exports = HistoryValue;
module.exports = HistoryValue;