@alithya-oss/backstage-plugin-time-saver-backend
Version:
This plugin provides an implementation of charts and statistics related to your time savings that are coming from usage of your templates. Plugins is built from frontend and backend part. Backend plugin is responsible for scheduled stats parsing process a
102 lines (98 loc) • 3.97 kB
JavaScript
;
var utils = require('../utils.cjs.js');
var backstagePluginTimeSaverCommon = require('@alithya-oss/backstage-plugin-time-saver-common');
const DEFAULT_DB_CREATED_AT_VALUE = "";
class TemplateTimeSavingsMap {
static toPersistence(templateTimeSavings) {
return {
team: templateTimeSavings.team,
role: templateTimeSavings.role,
created_at: utils.isoDateFromDateTime(templateTimeSavings.createdAt) || DEFAULT_DB_CREATED_AT_VALUE,
created_by: templateTimeSavings.createdBy,
time_saved: templateTimeSavings.timeSaved,
template_name: templateTimeSavings.templateName,
template_task_id: templateTimeSavings.templateTaskId,
template_task_status: templateTimeSavings.templateTaskStatus
};
}
static toDTO(templateTimeSavingsDbRow) {
return {
id: templateTimeSavingsDbRow.id,
team: templateTimeSavingsDbRow.team,
role: templateTimeSavingsDbRow.role,
createdAt: utils.dateTimeFromIsoDate(templateTimeSavingsDbRow.created_at),
createdBy: templateTimeSavingsDbRow.created_by,
timeSaved: utils.roundNumericValues(templateTimeSavingsDbRow.time_saved),
templateName: templateTimeSavingsDbRow.template_name,
templateTaskId: templateTimeSavingsDbRow.template_task_id,
templateTaskStatus: templateTimeSavingsDbRow.template_task_status
};
}
}
class TemplateTimeSavingsCollectionMap {
static toDTO(templateTimeSavingsDbRows) {
return templateTimeSavingsDbRows.map((e) => TemplateTimeSavingsMap.toDTO(e));
}
static distinctToDTO(templateTimeSavingsDbRows) {
if (!(templateTimeSavingsDbRows && templateTimeSavingsDbRows.length)) {
return undefined;
}
const key = Object.keys(templateTimeSavingsDbRows[0])[0];
const values = templateTimeSavingsDbRows.map((e) => Object.values(e)[0]);
return {
[key]: [...values]
};
}
}
class TimeSavedStatisticsMap {
static toDTO(timeSavedStatisticsDbRow) {
if (backstagePluginTimeSaverCommon.isTimeSavedStatisticsDbRow(timeSavedStatisticsDbRow)) {
return {
team: timeSavedStatisticsDbRow.team,
templateName: timeSavedStatisticsDbRow.template_name,
timeSaved: parseInt(timeSavedStatisticsDbRow.time_saved || "0", 10)
};
} else if (backstagePluginTimeSaverCommon.isTimeSavedStatisticsPerTeamDbRow(timeSavedStatisticsDbRow)) {
return {
team: timeSavedStatisticsDbRow.team,
timeSaved: parseInt(timeSavedStatisticsDbRow.time_saved || "0", 10)
};
} else if (backstagePluginTimeSaverCommon.isTimeSavedStatisticsPerTemplateNameDbRow(timeSavedStatisticsDbRow)) {
return {
templateName: timeSavedStatisticsDbRow.template_name,
timeSaved: parseInt(timeSavedStatisticsDbRow.time_saved || "0", 10)
};
}
throw new Error("Wrong type");
}
}
class GroupSavingsDivisionMap {
static toDTO(groupSavingsDivisionDbRow) {
return {
team: groupSavingsDivisionDbRow?.team,
percentage: utils.roundNumericValues(groupSavingsDivisionDbRow.percentage)
};
}
}
class TimeSummaryMap {
static timeSummaryByTeamNameToDTO(timeSummaryDbRow) {
return {
team: timeSummaryDbRow.team,
date: utils.dateTimeFromIsoDate(timeSummaryDbRow.date),
totalTimeSaved: utils.roundNumericValues(timeSummaryDbRow.total_time_saved) || 0
};
}
static timeSummaryByTemplateNameToDTO(timeSummaryDbRow) {
return {
templateName: timeSummaryDbRow.template_name,
date: utils.dateTimeFromIsoDate(timeSummaryDbRow.date),
totalTimeSaved: utils.roundNumericValues(timeSummaryDbRow.total_time_saved) || 0
};
}
}
exports.GroupSavingsDivisionMap = GroupSavingsDivisionMap;
exports.TemplateTimeSavingsCollectionMap = TemplateTimeSavingsCollectionMap;
exports.TemplateTimeSavingsMap = TemplateTimeSavingsMap;
exports.TimeSavedStatisticsMap = TimeSavedStatisticsMap;
exports.TimeSummaryMap = TimeSummaryMap;
//# sourceMappingURL=mappers.cjs.js.map