Remove CSV translation. Added a constant for CRLF.
MODIFY
src/server/rest/v1/service/ChargingStationService.ts
src/server/rest/v1/service/ChargingStationService.ts
@@ -1540,14 +1540,13 @@ export default class ChargingStationService {
private static convertOCPPParamsToCSV(ocppParams: OCPPParams, userLocale: string, writeHeader = true): string {
let csv = '';
- const i18nManager = I18nManager.getInstanceForLocale(userLocale);
// Header
if (writeHeader) {
- csv = i18nManager.translate('chargers.chargingStation') + Constants.CSV_SEPARATOR;
- csv += i18nManager.translate('general.name') + Constants.CSV_SEPARATOR;
- csv += i18nManager.translate('general.value') + Constants.CSV_SEPARATOR;
- csv += i18nManager.translate('general.siteArea') + Constants.CSV_SEPARATOR;
- csv += i18nManager.translate('general.site') + '\r\n';
+ csv = 'chargingStation' + Constants.CSV_SEPARATOR;
+ csv += 'name' + Constants.CSV_SEPARATOR;
+ csv += 'value' + Constants.CSV_SEPARATOR;
+ csv += 'siteArea' + Constants.CSV_SEPARATOR;
+ csv += 'site' + Constants.CR_LF;
}
// Content
for (const param of ocppParams.params) {
@@ -1555,7 +1554,7 @@ export default class ChargingStationService {
csv += param.key + Constants.CSV_SEPARATOR;
csv += Utils.replaceSpecialCharsInCSVValueParam(param.value) + Constants.CSV_SEPARATOR;
csv += ocppParams.siteAreaName + Constants.CSV_SEPARATOR;
- csv += ocppParams.siteName + '\r\n';
+ csv += ocppParams.siteName + Constants.CR_LF;
}
return csv;
}
@@ -1581,7 +1580,7 @@ export default class ChargingStationService {
csv += 'lastSeen' + Constants.CSV_SEPARATOR;
csv += 'lastReboot' + Constants.CSV_SEPARATOR;
csv += 'maxPower' + Constants.CSV_SEPARATOR;
- csv += 'powerLimitUnit' + '\r\n';
+ csv += 'powerLimitUnit' + Constants.CR_LF;
}
// Content
for (const chargingStation of chargingStations) {
@@ -1610,7 +1609,7 @@ export default class ChargingStationService {
csv += i18nManager.formatDateTime(chargingStation.lastSeen, 'L') + ' ' + i18nManager.formatDateTime(chargingStation.lastSeen, 'LT') + Constants.CSV_SEPARATOR;
csv += i18nManager.formatDateTime(chargingStation.lastReboot, 'L') + ' ' + i18nManager.formatDateTime(chargingStation.lastReboot, 'LT') + Constants.CSV_SEPARATOR;
csv += chargingStation.maximumPower + Constants.CSV_SEPARATOR;
- csv += chargingStation.powerLimitUnit + '\r\n';
+ csv += chargingStation.powerLimitUnit + Constants.CR_LF;
}
return csv;
}

MODIFY
src/server/rest/v1/service/LoggingService.ts
src/server/rest/v1/service/LoggingService.ts
@@ -68,7 +68,7 @@ export default class LoggingService {
csv += 'module' + Constants.CSV_SEPARATOR;
csv += 'source' + Constants.CSV_SEPARATOR;
csv += 'host' + Constants.CSV_SEPARATOR;
- csv += 'process' + '\r\n';
+ csv += 'process' + Constants.CR_LF;
}
// Content
for (const log of loggings) {
@@ -82,7 +82,7 @@ export default class LoggingService {
csv += log.module + Constants.CSV_SEPARATOR;
csv += log.source + Constants.CSV_SEPARATOR;
csv += log.host + Constants.CSV_SEPARATOR;
- csv += log.process + '\r\n';
+ csv += log.process + Constants.CR_LF;
}
return csv;
}

MODIFY
src/server/rest/v1/service/StatisticService.ts
src/server/rest/v1/service/StatisticService.ts
@@ -491,20 +491,20 @@ export default class StatisticService {
}
switch (dataType) {
case 'Consumption':
- csv += 'consumption' + '\r\n';
+ csv += 'consumption' + Constants.CR_LF;
break;
case 'Usage':
- csv += 'usage' + '\r\n';
+ csv += 'usage' + Constants.CR_LF;
break;
case 'Inactivity':
- csv += 'inactivity' + '\r\n';
+ csv += 'inactivity' + Constants.CR_LF;
break;
case 'Transactions':
- csv += 'numberOfSessions' + '\r\n';
+ csv += 'numberOfSessions' + Constants.CR_LF;
break;
case 'Pricing':
csv += 'price' + Constants.CSV_SEPARATOR;
- csv += 'priceUnit' + '\r\n';
+ csv += 'priceUnit' + Constants.CR_LF;
break;
default:
return csv;
@@ -651,12 +651,12 @@ export default class StatisticService {
// const supportedLocales = Intl.NumberFormat.supportedLocalesOf(['fr-FR', 'en-US', 'de-DE']);
if (dataType === 'Pricing') {
if (transaction._id.unit) {
- csv += number.toString() + Constants.CSV_SEPARATOR + transaction._id.unit + '\r\n';
+ csv += number.toString() + Constants.CSV_SEPARATOR + transaction._id.unit + Constants.CR_LF;
} else {
- csv += number.toString() + Constants.CSV_SEPARATOR + ' ' + '\r\n';
+ csv += number.toString() + Constants.CSV_SEPARATOR + ' ' + Constants.CR_LF;
}
} else {
- csv += number.toString() + '\r\n';
+ csv += number.toString() + Constants.CR_LF;
}
}
}

MODIFY
src/server/rest/v1/service/TransactionService.ts
src/server/rest/v1/service/TransactionService.ts
@@ -890,26 +890,25 @@ export default class TransactionService {
public static convertToCSV(req: Request, transactions: Transaction[], writeHeader = true): string {
let csv = '';
- const i18nManager = I18nManager.getInstanceForLocale(req.user.locale);
// Header
if (writeHeader) {
- csv = i18nManager.translate('users.id') + Constants.CSV_SEPARATOR;
- csv += i18nManager.translate('chargers.chargingStation') + Constants.CSV_SEPARATOR;
- csv += i18nManager.translate('chargers.connector') + Constants.CSV_SEPARATOR;
- csv += i18nManager.translate('users.userID') + Constants.CSV_SEPARATOR;
- csv += i18nManager.translate('users.user') + Constants.CSV_SEPARATOR;
- csv += i18nManager.translate('tags.id') + Constants.CSV_SEPARATOR;
- csv += i18nManager.translate('tags.description') + Constants.CSV_SEPARATOR;
- csv += i18nManager.translate('chargers.timezone') + Constants.CSV_SEPARATOR;
- csv += i18nManager.translate('general.startDate') + Constants.CSV_SEPARATOR;
- csv += i18nManager.translate('general.startTime') + Constants.CSV_SEPARATOR;
- csv += i18nManager.translate('general.endDate') + Constants.CSV_SEPARATOR;
- csv += i18nManager.translate('general.endTime') + Constants.CSV_SEPARATOR;
- csv += i18nManager.translate('transactions.totalConsumption') + Constants.CSV_SEPARATOR;
- csv += i18nManager.translate('transactions.totalDuration') + Constants.CSV_SEPARATOR;
- csv += i18nManager.translate('transactions.totalInactivity') + Constants.CSV_SEPARATOR;
- csv += i18nManager.translate('general.price') + Constants.CSV_SEPARATOR;
- csv += i18nManager.translate('general.priceUnit') + '\r\n';
+ csv = 'id' + Constants.CSV_SEPARATOR;
+ csv += 'chargingStationID' + Constants.CSV_SEPARATOR;
+ csv += 'connector' + Constants.CSV_SEPARATOR;
+ csv += 'userID' + Constants.CSV_SEPARATOR;
+ csv += 'user' + Constants.CSV_SEPARATOR;
+ csv += 'tagID' + Constants.CSV_SEPARATOR;
+ csv += 'tagDescription' + Constants.CSV_SEPARATOR;
+ csv += 'timezone' + Constants.CSV_SEPARATOR;
+ csv += 'startDate' + Constants.CSV_SEPARATOR;
+ csv += 'startTime' + Constants.CSV_SEPARATOR;
+ csv += 'endDate' + Constants.CSV_SEPARATOR;
+ csv += 'endTime' + Constants.CSV_SEPARATOR;
+ csv += 'totalConsumption' + Constants.CSV_SEPARATOR;
+ csv += 'totalDuration' + Constants.CSV_SEPARATOR;
+ csv += 'totalInactivity' + Constants.CSV_SEPARATOR;
+ csv += 'price' + Constants.CSV_SEPARATOR;
+ csv += 'priceUnit' + Constants.CR_LF;
}
// Content
for (const transaction of transactions) {
@@ -929,7 +928,7 @@ export default class TransactionService {
csv += (transaction.stop ? Math.round(transaction.stop.totalDurationSecs ? transaction.stop.totalDurationSecs / 60 : 0) : '') + Constants.CSV_SEPARATOR;
csv += (transaction.stop ? Math.round(transaction.stop.totalInactivitySecs ? transaction.stop.totalInactivitySecs / 60 : 0) : '') + Constants.CSV_SEPARATOR;
csv += (transaction.stop ? transaction.stop.roundedPrice : '') + Constants.CSV_SEPARATOR;
- csv += (transaction.stop ? transaction.stop.priceUnit : '') + '\r\n';
+ csv += (transaction.stop ? transaction.stop.priceUnit : '') + Constants.CR_LF;
}
return csv;
}

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -1343,7 +1343,7 @@ export default class UserService {
csv += 'eulaAcceptedOn' + Constants.CSV_SEPARATOR;
csv += 'createdOn' + Constants.CSV_SEPARATOR;
csv += 'changedOn' + Constants.CSV_SEPARATOR;
- csv += 'changedBy' + '\r\n';
+ csv += 'changedBy' + Constants.CR_LF;
}
// Content
for (const user of users) {
@@ -1357,7 +1357,7 @@ export default class UserService {
csv += moment(user.eulaAcceptedOn).format('YYYY-MM-DD') + Constants.CSV_SEPARATOR;
csv += moment(user.createdOn).format('YYYY-MM-DD') + Constants.CSV_SEPARATOR;
csv += moment(user.lastChangedOn).format('YYYY-MM-DD') + Constants.CSV_SEPARATOR;
- csv += (user.lastChangedBy ? Utils.buildUserFullName(user.lastChangedBy as User, false) : '') + '\r\n';
+ csv += (user.lastChangedBy ? Utils.buildUserFullName(user.lastChangedBy as User, false) : '') + Constants.CR_LF;
}
return csv;
}

MODIFY
src/utils/Constants.ts
src/utils/Constants.ts
@@ -7,7 +7,8 @@ import Tenant from '../types/Tenant';
export default class Constants {
public static readonly BOOT_NOTIFICATION_WAIT_TIME = 60;
- public static readonly CSV_SEPARATOR = ','; // Cannot store regex in enum
+ public static readonly CSV_SEPARATOR = ',';
+ public static readonly CR_LF = '\r\n';
public static readonly PERF_MAX_DATA_VOLUME_KB = 128;
public static readonly PERF_MAX_RESPONSE_TIME_MILLIS = 500;

MODIFY
test/api/TestUtils.ts
test/api/TestUtils.ts
@@ -4,7 +4,7 @@ export default class TestUtils {
}
public static convertExportFileToRawArray(fileData: string): Array<string> {
- let fileArray = fileData.split('\r\n');
+ let fileArray = fileData.split(Constants.CR_LF);
fileArray = fileArray.filter((record: string) => record.length > 0);
return fileArray;
}

Remove CSV translation. Added a constant for CRLF.