Factorized transaction service coding
MODIFY
src/server/rest/service/ChargingStationService.ts
src/server/rest/service/ChargingStationService.ts
-import { Action, Entity } from '../../../types/Authorization';
-import ChargingStation, { Command, OCPPParams, StaticLimitAmps } from '../../../types/ChargingStation';
-import { HTTPAuthError, HTTPError } from '../../../types/HTTPError';
-import { HttpChargingStationCommandRequest, HttpIsAuthorizedRequest } from '../../../types/requests/HttpChargingStationRequest';
+import fs from 'fs';
+
import { NextFunction, Request, Response } from 'express';
-import { OCPPConfigurationStatus, OCPPGetCompositeScheduleCommandResult, OCPPStatus } from '../../../types/ocpp/OCPPClient';
+import sanitize from 'mongo-sanitize';
+import Authorizations from '../../../authorization/Authorizations';
+import ChargingStationClientFactory from '../../../client/ocpp/ChargingStationClientFactory';
import AppAuthError from '../../../exception/AppAuthError';
import AppError from '../../../exception/AppError';
-import Authorizations from '../../../authorization/Authorizations';
import BackendError from '../../../exception/BackendError';
-import { ChargingProfile } from '../../../types/ChargingProfile';
-import ChargingStationClientFactory from '../../../client/ocpp/ChargingStationClientFactory';
-import { ChargingStationInErrorType } from '../../../types/InError';
-import ChargingStationSecurity from './security/ChargingStationSecurity';
-import ChargingStationStorage from '../../../storage/mongodb/ChargingStationStorage';
import ChargingStationVendorFactory from '../../../integration/charging-station-vendor/ChargingStationVendorFactory';
-import Constants from '../../../utils/Constants';
-import { DataResult } from '../../../types/DataResult';
-import I18nManager from '../../../utils/I18nManager';
+import SmartChargingFactory from '../../../integration/smart-charging/SmartChargingFactory';
import LockingHelper from '../../../locking/LockingHelper';
import LockingManager from '../../../locking/LockingManager';
-import Logging from '../../../utils/Logging';
+import ChargingStationStorage from '../../../storage/mongodb/ChargingStationStorage';
import OCPPStorage from '../../../storage/mongodb/OCPPStorage';
-import OCPPUtils from '../../ocpp/utils/OCPPUtils';
-import { ServerAction } from '../../../types/Server';
-import SiteArea from '../../../types/SiteArea';
import SiteAreaStorage from '../../../storage/mongodb/SiteAreaStorage';
import SiteStorage from '../../../storage/mongodb/SiteStorage';
-import SmartChargingFactory from '../../../integration/smart-charging/SmartChargingFactory';
-import TenantComponents from '../../../types/TenantComponents';
import TransactionStorage from '../../../storage/mongodb/TransactionStorage';
+import { Action, Entity } from '../../../types/Authorization';
+import { ChargingProfile } from '../../../types/ChargingProfile';
+import ChargingStation, { Command, OCPPParams, StaticLimitAmps } from '../../../types/ChargingStation';
+import { DataResult } from '../../../types/DataResult';
+import { HTTPAuthError, HTTPError } from '../../../types/HTTPError';
+import { ChargingStationInErrorType } from '../../../types/InError';
+import { OCPPConfigurationStatus, OCPPGetCompositeScheduleCommandResult, OCPPStatus } from '../../../types/ocpp/OCPPClient';
+import { HttpChargingStationCommandRequest, HttpIsAuthorizedRequest } from '../../../types/requests/HttpChargingStationRequest';
+import { ServerAction } from '../../../types/Server';
+import SiteArea from '../../../types/SiteArea';
+import TenantComponents from '../../../types/TenantComponents';
import UserToken from '../../../types/UserToken';
+import Constants from '../../../utils/Constants';
+import I18nManager from '../../../utils/I18nManager';
+import Logging from '../../../utils/Logging';
import Utils from '../../../utils/Utils';
+import OCPPUtils from '../../ocpp/utils/OCPPUtils';
+import ChargingStationSecurity from './security/ChargingStationSecurity';
import UtilsService from './UtilsService';
-import fs from 'fs';
-import sanitize from 'mongo-sanitize';
const MODULE_NAME = 'ChargingStationService';
@@ -1236,7 +1237,7 @@ export default class ChargingStationService {
action: Action.LIST,
entity: Entity.CHARGING_STATIONS,
module: MODULE_NAME,
- method: 'handleGetChargingStations',
+ method: 'getChargingStations',
});
}
// Filter
@@ -1261,12 +1262,9 @@ export default class ChargingStationService {
onlyRecordCount: filteredRequest.OnlyRecordCount
}
);
- // Build the result
- if (chargingStations.result && chargingStations.result.length > 0) {
// Filter
ChargingStationSecurity.filterChargingStationsResponse(
chargingStations, req.user, Utils.isComponentActiveFromToken(req.user, TenantComponents.ORGANIZATION));
- }
return chargingStations;
}

MODIFY
src/server/rest/service/TransactionService.ts
src/server/rest/service/TransactionService.ts
-import { Action, Entity } from '../../../types/Authorization';
-import { HTTPAuthError, HTTPError } from '../../../types/HTTPError';
+import fs from 'fs';
+
import { NextFunction, Request, Response } from 'express';
+import moment from 'moment';
-import { ActionsResponse } from '../../../types/GlobalType';
+import Authorizations from '../../../authorization/Authorizations';
import AppAuthError from '../../../exception/AppAuthError';
import AppError from '../../../exception/AppError';
-import Authorizations from '../../../authorization/Authorizations';
+import RefundFactory from '../../../integration/refund/RefundFactory';
+import SynchronizeRefundTransactionsTask from '../../../scheduler/tasks/SynchronizeRefundTransactionsTask';
+import OCPPService from '../../../server/ocpp/services/OCPPService';
import ChargingStationStorage from '../../../storage/mongodb/ChargingStationStorage';
-import Configuration from '../../../utils/Configuration';
-import Constants from '../../../utils/Constants';
-import Consumption from '../../../types/Consumption';
import ConsumptionStorage from '../../../storage/mongodb/ConsumptionStorage';
-import Cypher from '../../../utils/Cypher';
-import I18nManager from '../../../utils/I18nManager';
-import Logging from '../../../utils/Logging';
-import OCPPService from '../../../server/ocpp/services/OCPPService';
-import OCPPUtils from '../../ocpp/utils/OCPPUtils';
-import RefundFactory from '../../../integration/refund/RefundFactory';
+import TenantStorage from '../../../storage/mongodb/TenantStorage';
+import TransactionStorage from '../../../storage/mongodb/TransactionStorage';
+import UserStorage from '../../../storage/mongodb/UserStorage';
+import { Action, Entity } from '../../../types/Authorization';
+import Consumption from '../../../types/Consumption';
+import { ActionsResponse } from '../../../types/GlobalType';
+import { HTTPAuthError, HTTPError } from '../../../types/HTTPError';
+import { TransactionInErrorType } from '../../../types/InError';
import { RefundStatus } from '../../../types/Refund';
import { ServerAction } from '../../../types/Server';
-import SynchronizeRefundTransactionsTask from '../../../scheduler/tasks/SynchronizeRefundTransactionsTask';
import TenantComponents from '../../../types/TenantComponents';
-import TenantStorage from '../../../storage/mongodb/TenantStorage';
import Transaction from '../../../types/Transaction';
-import { TransactionInErrorType } from '../../../types/InError';
-import TransactionSecurity from './security/TransactionSecurity';
-import TransactionStorage from '../../../storage/mongodb/TransactionStorage';
import User from '../../../types/User';
-import UserStorage from '../../../storage/mongodb/UserStorage';
import UserToken from '../../../types/UserToken';
+import Configuration from '../../../utils/Configuration';
+import Constants from '../../../utils/Constants';
+import Cypher from '../../../utils/Cypher';
+import I18nManager from '../../../utils/I18nManager';
+import Logging from '../../../utils/Logging';
import Utils from '../../../utils/Utils';
+import OCPPUtils from '../../ocpp/utils/OCPPUtils';
+import TransactionSecurity from './security/TransactionSecurity';
import UtilsService from './UtilsService';
-import fs from 'fs';
-import moment from 'moment';
const MODULE_NAME = 'TransactionService';
@@ -451,189 +452,22 @@ export default class TransactionService {
}
public static async handleGetTransactionsActive(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
- // Check auth
- if (!Authorizations.canListTransactions(req.user)) {
- throw new AppAuthError({
- errorCode: HTTPAuthError.ERROR,
- user: req.user,
- action: Action.LIST,
- entity: Entity.TRANSACTIONS,
- module: MODULE_NAME,
- method: 'handleGetTransactionsActive'
- });
- }
- const filter: any = { stop: { $exists: false } };
- // Filter
- const filteredRequest = TransactionSecurity.filterTransactionsActiveRequest(req.query);
- filter.issuer = filteredRequest.Issuer;
- if (filteredRequest.ChargeBoxID) {
- filter.chargeBoxIDs = filteredRequest.ChargeBoxID.split('|');
- }
- if (filteredRequest.UserID) {
- filter.userIDs = filteredRequest.UserID.split('|');
- }
- if (Authorizations.isBasic(req.user)) {
- filter.ownerID = req.user.id;
- }
- if (Utils.isComponentActiveFromToken(req.user, TenantComponents.ORGANIZATION)) {
- if (filteredRequest.SiteAreaID) {
- filter.siteAreaIDs = filteredRequest.SiteAreaID.split('|');
- }
- if (filteredRequest.SiteID) {
- filter.siteIDs = Authorizations.getAuthorizedSiteIDs(req.user, filteredRequest.SiteID.split('|'));
- }
- if (Authorizations.isSiteAdmin(req.user)) {
- filter.siteAdminIDs = req.user.sitesAdmin;
- }
- }
- if (filteredRequest.ConnectorId) {
- filter.connectorId = filteredRequest.ConnectorId;
- }
- filter.withChargeBoxes = true;
- if (filteredRequest.Search) {
- filter.search = filteredRequest.Search;
- }
- // Get Transactions
- const transactions = await TransactionStorage.getTransactions(req.user.tenantID, filter,
- { limit: filteredRequest.Limit, skip: filteredRequest.Skip, sort: filteredRequest.Sort, onlyRecordCount: filteredRequest.OnlyRecordCount }
- );
- // Filter
- TransactionSecurity.filterTransactionsResponse(transactions, req.user);
// Return
- res.json(transactions);
+ res.json(await TransactionService.getTransactions(req, false));
next();
}
public static async handleGetTransactionsCompleted(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
- // Check auth
- if (!Authorizations.canListTransactions(req.user)) {
- throw new AppAuthError({
- errorCode: HTTPAuthError.ERROR,
- user: req.user,
- action: Action.LIST,
- entity: Entity.TRANSACTIONS,
- module: MODULE_NAME,
- method: 'handleGetTransactionsCompleted'
- });
- }
- const filter: any = { stop: { $exists: true } };
- // Filter
- const filteredRequest = TransactionSecurity.filterTransactionsRequest(req.query);
- filter.issuer = filteredRequest.Issuer;
- if (filteredRequest.ChargeBoxID) {
- filter.chargeBoxIDs = filteredRequest.ChargeBoxID.split('|');
- }
- if (filteredRequest.UserID) {
- filter.userIDs = filteredRequest.UserID.split('|');
- }
- if (Authorizations.isBasic(req.user)) {
- filter.ownerID = req.user.id;
- }
- // Check Organization
- if (Utils.isComponentActiveFromToken(req.user, TenantComponents.ORGANIZATION)) {
- if (filteredRequest.SiteAreaID) {
- filter.siteAreaIDs = filteredRequest.SiteAreaID.split('|');
- }
- if (filteredRequest.SiteID) {
- filter.siteIDs = Authorizations.getAuthorizedSiteIDs(req.user, filteredRequest.SiteID.split('|'));
- }
- if (Authorizations.isSiteAdmin(req.user)) {
- filter.siteAdminIDs = req.user.sitesAdmin;
- }
- }
- if (filteredRequest.StartDateTime) {
- filter.startDateTime = filteredRequest.StartDateTime;
- }
- if (filteredRequest.EndDateTime) {
- filter.endDateTime = filteredRequest.EndDateTime;
- }
- if (filteredRequest.RefundStatus) {
- filter.refundStatus = filteredRequest.RefundStatus.split('|');
- }
- if (filteredRequest.MinimalPrice) {
- filter.minimalPrice = filteredRequest.MinimalPrice;
- }
- if (filteredRequest.Statistics) {
- filter.statistics = filteredRequest.Statistics;
- }
- if (filteredRequest.Search) {
- filter.search = filteredRequest.Search;
- }
- if (filteredRequest.InactivityStatus) {
- filter.inactivityStatus = filteredRequest.InactivityStatus.split('|');
- }
- const transactions = await TransactionStorage.getTransactions(req.user.tenantID, filter,
- { limit: filteredRequest.Limit, skip: filteredRequest.Skip, sort: filteredRequest.Sort, onlyRecordCount: filteredRequest.OnlyRecordCount }
- );
- // Filter
- TransactionSecurity.filterTransactionsResponse(transactions, req.user);
// Return
- res.json(transactions);
+ res.json(await TransactionService.getTransactions(req));
next();
}
public static async handleGetTransactionsToRefund(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
- // Check auth
- if (!Authorizations.canListTransactions(req.user)) {
- throw new AppAuthError({
- errorCode: HTTPAuthError.ERROR,
- user: req.user,
- action: Action.LIST,
- entity: Entity.TRANSACTIONS,
- module: MODULE_NAME,
- method: 'handleGetTransactionsToRefund'
- });
- }
- const filter: any = { stop: { $exists: true } };
- // Filter
- const filteredRequest = TransactionSecurity.filterTransactionsRequest(req.query);
- filter.issuer = true;
- if (filteredRequest.ChargeBoxID) {
- filter.chargeBoxIDs = filteredRequest.ChargeBoxID.split('|');
- }
- if (filteredRequest.UserID) {
- filter.userIDs = filteredRequest.UserID.split('|');
- }
- if (Authorizations.isBasic(req.user)) {
- filter.ownerID = req.user.id;
- }
- if (Utils.isComponentActiveFromToken(req.user, TenantComponents.ORGANIZATION)) {
- if (filteredRequest.SiteAreaID) {
- filter.siteAreaIDs = filteredRequest.SiteAreaID.split('|');
- }
- if (filteredRequest.SiteID) {
- filter.siteID = Authorizations.getAuthorizedSiteAdminIDs(req.user, filteredRequest.SiteID.split('|'));
- }
- filter.siteAdminIDs = Authorizations.getAuthorizedSiteAdminIDs(req.user);
- }
- if (filteredRequest.StartDateTime) {
- filter.startDateTime = filteredRequest.StartDateTime;
- }
- if (filteredRequest.EndDateTime) {
- filter.endDateTime = filteredRequest.EndDateTime;
- }
- if (filteredRequest.RefundStatus) {
- filter.refundStatus = filteredRequest.RefundStatus.split('|');
- }
- if (filteredRequest.MinimalPrice) {
- filter.minimalPrice = filteredRequest.MinimalPrice;
- }
- if (filteredRequest.Statistics) {
- filter.statistics = filteredRequest.Statistics;
- }
- if (filteredRequest.Search) {
- filter.search = filteredRequest.Search;
- }
- if (filteredRequest.ReportIDs) {
- filter.reportIDs = filteredRequest.ReportIDs.split('|');
- }
- const transactions = await TransactionStorage.getTransactions(req.user.tenantID, filter,
- { limit: filteredRequest.Limit, skip: filteredRequest.Skip, sort: filteredRequest.Sort, onlyRecordCount: filteredRequest.OnlyRecordCount }
- );
- // Filter
- TransactionSecurity.filterTransactionsResponse(transactions, req.user);
+ // Only e-Mobility transactions
+ req.query.issuer = 'true';
// Return
- res.json(transactions);
+ res.json(await TransactionService.getTransactions(req));
next();
}
@@ -679,61 +513,9 @@ export default class TransactionService {
}
public static async handleGetTransactionsExport(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
- // Check auth
- if (!Authorizations.canListTransactions(req.user)) {
- throw new AppAuthError({
- errorCode: HTTPAuthError.ERROR,
- user: req.user,
- action: Action.LIST,
- entity: Entity.TRANSACTIONS,
- module: MODULE_NAME,
- method: 'handleGetTransactionsExport'
- });
- }
- const filter: any = { stop: { $exists: true } };
- // Filter
- const filteredRequest = TransactionSecurity.filterTransactionsRequest(req.query);
- if (filteredRequest.ChargeBoxID) {
- filter.chargeBoxIDs = filteredRequest.ChargeBoxID.split('|');
- }
- if (filteredRequest.UserID) {
- filter.userIDs = filteredRequest.UserID.split('|');
- }
- if (Authorizations.isBasic(req.user)) {
- filter.ownerID = req.user.id;
- }
- if (Utils.isComponentActiveFromToken(req.user, TenantComponents.ORGANIZATION)) {
- if (filteredRequest.SiteAreaID) {
- filter.siteAreaIDs = filteredRequest.SiteAreaID.split('|');
- }
- if (filteredRequest.SiteID) {
- filter.siteID = Authorizations.getAuthorizedSiteIDs(req.user, filteredRequest.SiteID.split('|'));
- }
- if (Authorizations.isSiteAdmin(req.user)) {
- filter.siteAdminIDs = req.user.sitesAdmin;
- }
- }
- // Date
- if (filteredRequest.StartDateTime) {
- filter.startDateTime = filteredRequest.StartDateTime;
- }
- if (filteredRequest.EndDateTime) {
- filter.endDateTime = filteredRequest.EndDateTime;
- }
- if (filteredRequest.RefundStatus) {
- filter.refundStatus = filteredRequest.RefundStatus.split('|');
- }
- if (filteredRequest.Search) {
- filter.search = filteredRequest.Search;
- }
- if (filteredRequest.SiteID) {
- filter.siteID = filteredRequest.SiteID;
- }
- const transactions = await TransactionStorage.getTransactions(req.user.tenantID, filter,
- { limit: filteredRequest.Limit, skip: filteredRequest.Skip, sort: filteredRequest.Sort, onlyRecordCount: filteredRequest.OnlyRecordCount }
- );
- // Filter
- TransactionSecurity.filterTransactionsResponse(transactions, req.user);
+ // Get transactions
+ const transactions = await TransactionService.getTransactions(req);
+ // Create the file
const filename = 'exported-transactions.csv';
fs.writeFile(filename, TransactionService.convertToCSV(req.user, transactions.result), (err) => {
if (err) {
@@ -753,71 +535,9 @@ export default class TransactionService {
}
public static async handleGetTransactionsToRefundExport(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
- // Check auth
- if (!Authorizations.canListTransactions(req.user)) {
- throw new AppAuthError({
- errorCode: HTTPAuthError.ERROR,
- user: req.user,
- action: Action.LIST,
- entity: Entity.TRANSACTIONS,
- module: MODULE_NAME,
- method: 'handleGetTransactionsToRefundExport'
- });
- }
- const filter: any = { stop: { $exists: true } };
- // Filter
- const filteredRequest = TransactionSecurity.filterTransactionsRequest(req.query);
- if (filteredRequest.ChargeBoxID) {
- filter.chargeBoxIDs = filteredRequest.ChargeBoxID.split('|');
- }
- if (filteredRequest.UserID) {
- filter.userIDs = filteredRequest.UserID.split('|');
- }
- if (Authorizations.isBasic(req.user)) {
- filter.ownerID = req.user.id;
- }
- if (Utils.isComponentActiveFromToken(req.user, TenantComponents.ORGANIZATION)) {
- if (filteredRequest.SiteAreaID) {
- filter.siteAreaIDs = filteredRequest.SiteAreaID.split('|');
- }
- if (filteredRequest.SiteID) {
- filter.siteID = Authorizations.getAuthorizedSiteAdminIDs(req.user, filteredRequest.SiteID.split('|'));
- }
- filter.siteAdminIDs = Authorizations.getAuthorizedSiteAdminIDs(req.user);
- }
- if (filteredRequest.StartDateTime) {
- filter.startDateTime = filteredRequest.StartDateTime;
- }
- if (filteredRequest.EndDateTime) {
- filter.endDateTime = filteredRequest.EndDateTime;
- }
- if (filteredRequest.RefundStatus) {
- filter.refundStatus = filteredRequest.RefundStatus.split('|');
- }
- if (filteredRequest.MinimalPrice) {
- filter.minimalPrice = filteredRequest.MinimalPrice;
- }
- if (filteredRequest.Statistics) {
- filter.statistics = filteredRequest.Statistics;
- }
- if (filteredRequest.Search) {
- filter.search = filteredRequest.Search;
- }
- if (filteredRequest.ReportIDs) {
- filter.reportIDs = filteredRequest.ReportIDs.split('|');
- }
- const transactions = await TransactionStorage.getTransactions(req.user.tenantID, filter,
- { limit: filteredRequest.Limit, skip: filteredRequest.Skip, sort: filteredRequest.Sort, onlyRecordCount: filteredRequest.OnlyRecordCount }
- );
- // Filter
- TransactionSecurity.filterTransactionsResponse(transactions, req.user);
- // Hash userId and tagId for confidentiality purposes
- for (const transaction of transactions.result) {
- if (transaction.user) {
- transaction.user.id = transaction.user ? Cypher.hash(transaction.user.id) : '';
- }
- transaction.tagID = transaction.tagID ? Cypher.hash(transaction.tagID) : '';
- }
+ // Get transactions
+ const transactions = await TransactionService.getTransactions(req);
+ // Create the file
const filename = 'exported-refund-transactions.csv';
fs.writeFile(filename, TransactionService.convertToCSV(req.user, transactions.result), (err) => {
if (err) {
@@ -851,6 +571,7 @@ export default class TransactionService {
const filter: any = {};
// Filter
const filteredRequest = TransactionSecurity.filterTransactionsInErrorRequest(req.query);
+ // For only charging station in e-Mobility (not the ones from the roaming)
filter.issuer = true;
if (filteredRequest.ChargeBoxID) {
filter.chargeBoxIDs = filteredRequest.ChargeBoxID.split('|');
@@ -994,4 +715,46 @@ export default class TransactionService {
}
return result;
}
+
+ private static async getTransactions(req: Request, completedTransactions = true): Promise<DataResult<ChargingStation>> {
+ // Check auth
+ if (!Authorizations.canListTransactions(req.user)) {
+ throw new AppAuthError({
+ errorCode: HTTPAuthError.ERROR,
+ user: req.user,
+ action: Action.LIST,
+ entity: Entity.TRANSACTIONS,
+ module: MODULE_NAME,
+ method: 'handleGetTransactionsToRefund'
+ });
+ }
+ // Filter
+ const filteredRequest = TransactionSecurity.filterTransactionsRequest(req.query);
+ // Get the transactions
+ const transactions = await TransactionStorage.getTransactions(req.user.tenantID,
+ {
+ stop: completedTransactions ? { $exists: true } : { $exists: false },
+ chargeBoxIDs: filteredRequest.ChargeBoxID ? filteredRequest.ChargeBoxID.split('|') : null,
+ issuer: Utils.objectHasProperty(filteredRequest, 'Issuer') ? filteredRequest.Issuer : null,
+ userIDs: filteredRequest.UserID ? filteredRequest.UserID.split('|') : null,
+ ownerID: Authorizations.isBasic(req.user) ? req.user.id : null,
+ siteAreaIDs: filteredRequest.SiteAreaID ? filteredRequest.SiteAreaID.split('|') : null,
+ siteIDs: filteredRequest.SiteID ? Authorizations.getAuthorizedSiteAdminIDs(req.user, filteredRequest.SiteID.split('|')) : null,
+ siteAdminIDs: Authorizations.getAuthorizedSiteAdminIDs(req.user),
+ startDateTime: filteredRequest.StartDateTime ? filteredRequest.StartDateTime : null,
+ endDateTime: filteredRequest.EndDateTime ? filteredRequest.EndDateTime : null,
+ refundStatus: filteredRequest.RefundStatus ? filteredRequest.RefundStatus.split('|') : null,
+ minimalPrice: filteredRequest.MinimalPrice ? filteredRequest.MinimalPrice : null,
+ statistics: filteredRequest.Statistics ? filteredRequest.Statistics : null,
+ search: filteredRequest.Search ? filteredRequest.Search : null,
+ reportIDs: filteredRequest.ReportIDs ? filteredRequest.ReportIDs.split('|') : null,
+ connectorId: filteredRequest.ConnectorId ? filteredRequest.ConnectorId : null,
+ inactivityStatus: filteredRequest.InactivityStatus ? filteredRequest.InactivityStatus.split('|') : null,
+ },
+ { limit: filteredRequest.Limit, skip: filteredRequest.Skip, sort: filteredRequest.Sort, onlyRecordCount: filteredRequest.OnlyRecordCount }
+ );
+ // Filter
+ TransactionSecurity.filterTransactionsResponse(transactions, req.user);
+ return transactions;
+ }
}

MODIFY
src/server/rest/service/security/TransactionSecurity.ts
src/server/rest/service/security/TransactionSecurity.ts
-import { HttpAssignTransactionsToUserRequest, HttpConsumptionFromTransactionRequest, HttpTransactionRequest, HttpTransactionsRefundRequest, HttpTransactionsRequest } from '../../../../types/requests/HttpTransactionRequest';
-import Transaction, { TransactionConsumption } from '../../../../types/Transaction';
+import moment from 'moment';
+import sanitize from 'mongo-sanitize';
import Authorizations from '../../../../authorization/Authorizations';
-import Constants from '../../../../utils/Constants';
import Consumption from '../../../../types/Consumption';
import { DataResult } from '../../../../types/DataResult';
-import RefundReport from '../../../../types/Refund';
import { TransactionInError } from '../../../../types/InError';
+import RefundReport from '../../../../types/Refund';
+import { HttpAssignTransactionsToUserRequest, HttpConsumptionFromTransactionRequest, HttpTransactionRequest, HttpTransactionsRefundRequest, HttpTransactionsRequest } from '../../../../types/requests/HttpTransactionRequest';
+import Transaction, { TransactionConsumption } from '../../../../types/Transaction';
import User from '../../../../types/User';
import UserToken from '../../../../types/UserToken';
+import Constants from '../../../../utils/Constants';
import Utils from '../../../../utils/Utils';
import UtilsSecurity from './UtilsSecurity';
-import moment from 'moment';
-import sanitize from 'mongo-sanitize';
export default class TransactionSecurity {
public static filterTransactionsRefund(request: any): HttpTransactionsRefundRequest {
@@ -67,7 +67,7 @@ export default class TransactionSecurity {
public static filterTransactionsRequest(request: any): HttpTransactionsRequest {
const filteredRequest: HttpTransactionsRequest = {} as HttpTransactionsRequest;
// Handle picture
- if (request.Issuer) {
+ if (Utils.objectHasProperty(request, 'Issuer')) {
filteredRequest.Issuer = UtilsSecurity.filterBoolean(request.Issuer);
}
filteredRequest.ChargeBoxID = sanitize(request.ChargeBoxID);

MODIFY
src/server/rest/service/security/UserSecurity.ts
src/server/rest/service/security/UserSecurity.ts
-import { HttpSitesAssignUserRequest, HttpUserMobileTokenRequest, HttpUserRequest, HttpUserSitesRequest, HttpUsersRequest } from '../../../../types/requests/HttpUserRequest';
-import User, { UserRole } from '../../../../types/User';
+import sanitize from 'mongo-sanitize';
import Authorizations from '../../../../authorization/Authorizations';
import { DataResult } from '../../../../types/DataResult';
-import Tag from '../../../../types/Tag';
import { UserInError } from '../../../../types/InError';
+import { HttpSitesAssignUserRequest, HttpUserMobileTokenRequest, HttpUserRequest, HttpUserSitesRequest, HttpUsersRequest } from '../../../../types/requests/HttpUserRequest';
+import Tag from '../../../../types/Tag';
+import User, { UserRole } from '../../../../types/User';
import UserNotifications from '../../../../types/UserNotifications';
import UserToken from '../../../../types/UserToken';
import Utils from '../../../../utils/Utils';
import UtilsSecurity from './UtilsSecurity';
-import sanitize from 'mongo-sanitize';
export default class UserSecurity {
@@ -113,7 +113,9 @@ export default class UserSecurity {
if (request.email) {
filteredRequest.email = sanitize(request.email);
}
+ if (Utils.objectHasProperty(request, 'issuer')) {
filteredRequest.issuer = UtilsSecurity.filterBoolean(request.issuer);
+ }
if (Utils.objectHasProperty(request, 'notificationsActive')) {
filteredRequest.notificationsActive = sanitize(request.notificationsActive);
}

MODIFY
src/storage/mongodb/TransactionStorage.ts
src/storage/mongodb/TransactionStorage.ts
-import RefundReport, { RefundStatus } from '../../types/Refund';
-import Transaction, { InactivityStatus } from '../../types/Transaction';
-import { TransactionInError, TransactionInErrorType } from '../../types/InError';
+import moment from 'moment';
-import Constants from '../../utils/Constants';
-import ConsumptionStorage from './ConsumptionStorage';
-import { DataResult } from '../../types/DataResult';
-import DatabaseUtils from './DatabaseUtils';
+import global from './../../types/GlobalType';
import DbParams from '../../types/database/DbParams';
-import Logging from '../../utils/Logging';
+import { DataResult } from '../../types/DataResult';
+import { TransactionInError, TransactionInErrorType } from '../../types/InError';
import { NotifySessionNotStarted } from '../../types/Notification';
+import RefundReport, { RefundStatus } from '../../types/Refund';
import { ServerAction } from '../../types/Server';
+import Transaction, { InactivityStatus } from '../../types/Transaction';
import User from '../../types/User';
+import Constants from '../../utils/Constants';
+import Logging from '../../utils/Logging';
import Utils from '../../utils/Utils';
-import global from './../../types/GlobalType';
-import moment from 'moment';
+import ConsumptionStorage from './ConsumptionStorage';
+import DatabaseUtils from './DatabaseUtils';
const MODULE_NAME = 'TransactionStorage';
@@ -234,7 +234,7 @@ export default class TransactionStorage {
params: {
transactionId?: number; issuer?: boolean; search?: string; ownerID?: string; userIDs?: string[]; siteAdminIDs?: string[];
chargeBoxIDs?: string[]; siteAreaIDs?: string[]; siteIDs?: string[]; connectorId?: number; startDateTime?: Date;
- endDateTime?: Date; stop?: any; minimalPrice?: boolean; reportIDs?: string[]; inactivityStatus?: InactivityStatus[];
+ endDateTime?: Date; stop?: any; minimalPrice?: boolean; reportIDs?: string[]; inactivityStatus?: string[];
ocpiSessionId?: string; ocpiSessionDateFrom?: Date; ocpiSessionDateTo?: Date; ocpiCdrDateFrom?: Date; ocpiCdrDateTo?: Date;
ocpiSessionChecked?: boolean; ocpiCdrChecked?: boolean;
statistics?: 'refund' | 'history'; refundStatus?: string[];

Factorized transaction service coding