added tag id and desc to exported transactions csv
MODIFY
src/assets/i18n/de.json
src/assets/i18n/de.json
"usage": "Usage (Hours)"
},
"tags": {
+ "id": "Badge ID",
+ "description": "Badge Description",
"virtualBadge": "Virtual Badge"
},
"transactions": {

MODIFY
src/assets/i18n/en.json
src/assets/i18n/en.json
"usage": "Usage (Hours)"
},
"tags": {
+ "id": "Badge ID",
+ "description": "Badge Description",
"virtualBadge": "Virtual Badge"
},
"transactions": {

MODIFY
src/assets/i18n/es.json
src/assets/i18n/es.json
"usage": "Usage (Hours)"
},
"tags": {
+ "id": "Badge ID",
+ "description": "Badge Description",
"virtualBadge": "Virtual Badge"
},
"transactions": {

MODIFY
src/assets/i18n/fr.json
src/assets/i18n/fr.json
"usage": "Utilisation (Heures)"
},
"tags": {
+ "id": "ID du badge",
+ "description": "Description du badge",
"virtualBadge": "Badge virtuel"
},
"transactions": {

MODIFY
src/assets/i18n/it.json
src/assets/i18n/it.json
"usage": "Usage (Hours)"
},
"tags": {
+ "id": "Badge ID",
+ "description": "Badge Description",
"virtualBadge": "Virtual Badge"
},
"transactions": {

MODIFY
src/assets/i18n/pt.json
src/assets/i18n/pt.json
"usage": "Usage (Hours)"
},
"tags": {
+ "id": "Badge ID",
+ "description": "Badge Description",
"virtualBadge": "Virtual Badge"
},
"transactions": {

MODIFY
src/server/rest/v1/service/TransactionService.ts
src/server/rest/v1/service/TransactionService.ts
@@ -61,7 +61,7 @@ export default class TransactionService {
res.json(response);
next();
} catch (error) {
- Logging.logActionExceptionMessageAndSendResponse(action, error, req, res, next);
+ await Logging.logActionExceptionMessageAndSendResponse(action, error, req, res, next);
}
}
@@ -86,7 +86,7 @@ export default class TransactionService {
for (const transactionId of filteredRequest.transactionIds) {
const transaction = await TransactionStorage.getTransaction(req.user.tenantID, transactionId);
if (!transaction) {
- Logging.logError({
+ await Logging.logError({
tenantID: req.user.tenantID,
user: req.user, actionOnUser: (transaction.user ? transaction.user : null),
module: MODULE_NAME, method: 'handleRefundTransactions',
@@ -97,7 +97,7 @@ export default class TransactionService {
continue;
}
if (transaction.refundData && !!transaction.refundData.refundId && transaction.refundData.status !== RefundStatus.CANCELLED) {
- Logging.logError({
+ await Logging.logError({
tenantID: req.user.tenantID,
user: req.user, actionOnUser: (transaction.user ? transaction.user : null),
module: MODULE_NAME, method: 'handleRefundTransactions',
@@ -222,7 +222,7 @@ export default class TransactionService {
// Save
await TransactionStorage.saveTransaction(req.user.tenantID, transaction);
// Ok
- Logging.logInfo({
+ await Logging.logInfo({
tenantID: req.user.tenantID,
action: action,
user: req.user, actionOnUser: (transaction.user ? transaction.user : null),
@@ -447,7 +447,7 @@ export default class TransactionService {
true
);
// Log
- Logging.logSecurityInfo({
+ await Logging.logSecurityInfo({
tenantID: req.user.tenantID,
source: chargingStation.id,
user: req.user, actionOnUser: user,
@@ -570,7 +570,7 @@ export default class TransactionService {
'currentTotalDurationSecs', 'currentTotalInactivitySecs', 'currentInstantWatts', 'currentTotalConsumptionWh', 'currentStateOfCharge',
'currentCumulatedPrice', 'currentInactivityStatus', 'price', 'roundedPrice', 'signedData',
'stop.price', 'stop.priceUnit', 'stop.inactivityStatus', 'stop.stateOfCharge', 'stop.timestamp', 'stop.totalConsumptionWh', 'stop.meterStop',
- 'stop.totalDurationSecs', 'stop.totalInactivitySecs', 'stop.pricingSource', 'stop.roundedPrice', 'stop.signedData', 'stop.tagID'
+ 'stop.totalDurationSecs', 'stop.totalInactivitySecs', 'stop.pricingSource', 'stop.roundedPrice', 'stop.signedData', 'stop.tagID', 'tagID.description'
]);
UtilsService.assertObjectExists(action, transaction, `Transaction with ID '${filteredRequest.ID}' does not exist`,
MODULE_NAME, 'handleGetTransaction', req.user);
@@ -719,10 +719,10 @@ export default class TransactionService {
public static async getCompletedTransactionsToExport(req: Request): Promise<DataResult<Transaction>> {
// Get transaction
- return TransactionService.getTransactions(req, ServerAction.TRANSACTIONS_EXPORT, { completedTransactions: true }, [
+ return TransactionService.getTransactions(req, ServerAction.TRANSACTIONS_EXPORT, { completedTransactions: true, withTag: true }, [
'id', 'chargeBoxID', 'timestamp', 'issuer', 'stateOfCharge', 'timezone', 'connectorId', 'meterStart', 'siteAreaID', 'siteID',
'stop.price', 'stop.priceUnit', 'stop.inactivityStatus', 'stop.stateOfCharge', 'stop.timestamp', 'stop.totalConsumptionWh',
- 'stop.totalDurationSecs', 'stop.totalInactivitySecs', 'billingData.invoiceID', 'ocpi', 'ocpiWithCdr', 'tagID', 'stop.tagID',
+ 'stop.totalDurationSecs', 'stop.totalInactivitySecs', 'billingData.invoiceID', 'ocpi', 'ocpiWithCdr', 'tagID', 'stop.tagID', 'tag.description'
]);
}
@@ -822,6 +822,8 @@ export default class TransactionService {
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;
@@ -840,6 +842,8 @@ export default class TransactionService {
csv += transaction.connectorId + Constants.CSV_SEPARATOR;
csv += (transaction.user ? Cypher.hash(transaction.user.id) : '') + Constants.CSV_SEPARATOR;
csv += (transaction.user ? Utils.buildUserFullName(transaction.user, false) : '') + Constants.CSV_SEPARATOR;
+ csv += transaction.tagID + Constants.CSV_SEPARATOR;
+ csv += (transaction.tag?.description || '') + Constants.CSV_SEPARATOR;
csv += (transaction.timezone || 'N/A (UTC by default)') + Constants.CSV_SEPARATOR;
csv += (transaction.timezone ? moment(transaction.timestamp).tz(transaction.timezone) : moment.utc(transaction.timestamp)).format('YYYY-MM-DD') + Constants.CSV_SEPARATOR;
csv += (transaction.timezone ? moment(transaction.timestamp).tz(transaction.timezone) : moment.utc(transaction.timestamp)).format('HH:mm:ss') + Constants.CSV_SEPARATOR;
@@ -869,7 +873,7 @@ export default class TransactionService {
// Not Found
if (!transaction) {
result.inError++;
- Logging.logError({
+ await Logging.logError({
tenantID: loggedUser.tenantID,
user: loggedUser,
module: MODULE_NAME, method: 'handleDeleteTransactions',
@@ -880,7 +884,7 @@ export default class TransactionService {
// Already Refunded
} else if (refundConnector && !refundConnector.canBeDeleted(transaction)) {
result.inError++;
- Logging.logError({
+ await Logging.logError({
tenantID: loggedUser.tenantID,
user: loggedUser,
module: MODULE_NAME, method: 'handleDeleteTransactions',
@@ -891,7 +895,7 @@ export default class TransactionService {
// Billed
} else if (billingImpl && transaction.billingData && transaction.billingData.invoiceID) {
result.inError++;
- Logging.logError({
+ await Logging.logError({
tenantID: loggedUser.tenantID,
user: loggedUser,
module: MODULE_NAME, method: 'handleDeleteTransactions',
@@ -922,7 +926,7 @@ export default class TransactionService {
// Delete All Transactions
result.inSuccess = await TransactionStorage.deleteTransactions(loggedUser.tenantID, transactionsIDsToDelete);
// Log
- Logging.logActionsResponse(loggedUser.tenantID,
+ await Logging.logActionsResponse(loggedUser.tenantID,
ServerAction.TRANSACTIONS_DELETE,
MODULE_NAME, 'deleteTransactions', result,
'{{inSuccess}} transaction(s) were successfully deleted',
@@ -933,7 +937,7 @@ export default class TransactionService {
return result;
}
- private static async getTransactions(req: Request, action: ServerAction, params: { completedTransactions?: boolean } = {}, projectFields): Promise<DataResult<Transaction>> {
+ private static async getTransactions(req: Request, action: ServerAction, params: { completedTransactions?: boolean, withTag?: boolean } = {}, projectFields): Promise<DataResult<Transaction>> {
// Check Transactions
if (!Authorizations.canListTransactions(req.user)) {
throw new AppAuthError({
@@ -979,6 +983,9 @@ export default class TransactionService {
if (Utils.objectHasProperty(params, 'completedTransactions')) {
extrafilters.stop = params.completedTransactions ? { $exists: true } : { $exists: false };
}
+ if (Utils.objectHasProperty(params, 'withTag')) {
+ extrafilters.withTag = params.withTag;
+ }
// Get the transactions
const transactions = await TransactionStorage.getTransactions(req.user.tenantID,
{

MODIFY
src/storage/mongodb/TransactionStorage.ts
src/storage/mongodb/TransactionStorage.ts
import RefundReport, { RefundStatus } from '../../types/Refund';
-import Transaction, { OcpiData } from '../../types/Transaction';
import { TransactionInError, TransactionInErrorType } from '../../types/InError';
import global, { FilterParams } from './../../types/GlobalType';
@@ -11,6 +10,7 @@ import DbParams from '../../types/database/DbParams';
import Logging from '../../utils/Logging';
import { NotifySessionNotStarted } from '../../types/UserNotifications';
import { ServerAction } from '../../types/Server';
+import Transaction from '../../types/Transaction';
import Utils from '../../utils/Utils';
import moment from 'moment';
@@ -261,7 +261,7 @@ export default class TransactionStorage {
endDateTime?: Date; stop?: any; minimalPrice?: boolean; reportIDs?: string[]; tagIDs?: string[]; inactivityStatus?: string[];
ocpiSessionID?: string; ocpiSessionDateFrom?: Date; ocpiSessionDateTo?: Date; ocpiCdrDateFrom?: Date; ocpiCdrDateTo?: Date;
ocpiSessionChecked?: boolean; ocpiCdrChecked?: boolean;
- statistics?: 'refund' | 'history'; refundStatus?: string[];
+ statistics?: 'refund' | 'history'; refundStatus?: string[]; withTag?: boolean;
},
dbParams: DbParams, projectFields?: string[]):
Promise<{
@@ -571,6 +571,13 @@ export default class TransactionStorage {
}
});
}
+ // Transaction tag
+ if (params.withTag) {
+ DatabaseUtils.pushTagLookupInAggregation({
+ tenantID, aggregation: aggregation, asField: 'tag', localField: 'tagID',
+ foreignField: '_id', oneToOneCardinality: true
+ });
+ }
// Charge Box
DatabaseUtils.pushChargingStationLookupInAggregation({
tenantID, aggregation: aggregation, localField: 'chargeBoxID', foreignField: '_id',
@@ -1032,7 +1039,7 @@ export default class TransactionStorage {
const id = Utils.getRandomIntSafe();
existingTransaction = await TransactionStorage.getTransaction(tenantID, id);
if (existingTransaction) {
- Logging.logWarning({
+ await Logging.logWarning({
tenantID: tenantID,
module: MODULE_NAME, method: '_findAvailableID',
action: ServerAction.TRANSACTION_STARTED,

MODIFY
src/types/Transaction.ts
src/types/Transaction.ts
@@ -7,6 +7,7 @@ import ChargingStation from '../types/ChargingStation';
import { OCPICdr } from './ocpi/OCPICdr';
import { OCPISession } from './ocpi/OCPISession';
import { RefundTransactionData } from './Refund';
+import Tag from './Tag';
import User from './User';
export type InactivityStatusLevel =
@@ -40,6 +41,7 @@ export default interface Transaction extends AbstractCurrentConsumption {
issuer: boolean;
connectorId: number;
tagID: string;
+ tag?: Tag;
userID: string;
chargeBoxID: string;
signedData?: string;

added tag id and desc to exported transactions csv