pricing - renaming pricings term
MODIFY
src/authorization/Authorizations.ts
src/authorization/Authorizations.ts
@@ -612,12 +612,12 @@ export default class Authorizations {
return Authorizations.canPerformAction(loggedUser, Entity.CONNECTIONS, Action.LIST);
}
- public static async canReadPricing(loggedUser: UserToken): Promise<boolean> {
- return Authorizations.canPerformAction(loggedUser, Entity.PRICING, Action.READ);
+ public static async canReadPricingModel(loggedUser: UserToken): Promise<boolean> {
+ return Authorizations.canPerformAction(loggedUser, Entity.PRICING_MODEL, Action.READ);
}
- public static async canUpdatePricing(loggedUser: UserToken): Promise<boolean> {
- return Authorizations.canPerformAction(loggedUser, Entity.PRICING, Action.UPDATE);
+ public static async canUpdatePricingModel(loggedUser: UserToken): Promise<boolean> {
+ return Authorizations.canPerformAction(loggedUser, Entity.PRICING_MODEL, Action.UPDATE);
}
public static async canClearBillingTestData(loggedUser: UserToken): Promise<boolean> {

MODIFY
src/server/rest/v1/service/AuthorizationService.ts
src/server/rest/v1/service/AuthorizationService.ts
@@ -19,8 +19,8 @@ import DynamicAuthorizationFactory from '../../../../authorization/DynamicAuthor
import { EntityDataType } from '../../../../types/GlobalType';
import { HTTPAuthError } from '../../../../types/HTTPError';
import { HttpAssetsRequest } from '../../../../types/requests/HttpAssetRequest';
-import { HttpPricingRequest } from '../../../../types/requests/HttpPricingRequest';
-import Pricing from '../../../../types/Pricing';
+import { HttpPricingModelRequest } from '../../../../types/requests/HttpPricingRequest';
+import PricingModel from '../../../../types/Pricing';
import { ServerAction } from '../../../../types/Server';
import Site from '../../../../types/Site';
import SiteArea from '../../../../types/SiteArea';
@@ -387,8 +387,8 @@ export default class AuthorizationService {
tenant, Entity.COMPANY, userToken, filteredRequest, filteredRequest.ID ? { CompanyID: filteredRequest.ID } : {}, authAction, entityData);
}
- public static async checkAndGetPricingsAuthorizations(tenant: Tenant, userToken: UserToken,
- filteredRequest: Partial<HttpPricingRequest>): Promise<AuthorizationFilter> {
+ public static async checkAndGetPricingModelsAuthorizations(tenant: Tenant, userToken: UserToken,
+ filteredRequest: Partial<HttpPricingModelRequest>): Promise<AuthorizationFilter> {
const authorizationFilters: AuthorizationFilter = {
filters: {},
dataSources: new Map(),
@@ -396,35 +396,35 @@ export default class AuthorizationService {
authorized: false,
};
// Check static & dynamic authorization
- await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.PRICINGS, Action.LIST,
+ await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.PRICING_MODELS, Action.LIST,
authorizationFilters, filteredRequest);
return authorizationFilters;
}
- public static async addPricingsAuthorizations(tenant: Tenant, userToken: UserToken, pricings: PricingDataResult, authorizationFilter: AuthorizationFilter): Promise<void> {
+ public static async addPricingModelsAuthorizations(tenant: Tenant, userToken: UserToken, dataResult: PricingDataResult, authorizationFilter: AuthorizationFilter): Promise<void> {
// Add canCreate flag to root
- pricings.canCreate = await AuthorizationService.canPerformAuthorizationAction(
- tenant, userToken, Entity.PRICING, Action.CREATE, authorizationFilter);
+ dataResult.canCreate = await AuthorizationService.canPerformAuthorizationAction(
+ tenant, userToken, Entity.PRICING_MODEL, Action.CREATE, authorizationFilter);
// Enrich
- for (const pricing of pricings.result) {
- await AuthorizationService.addPricingAuthorizations(tenant, userToken, pricing, authorizationFilter);
+ for (const pricingModel of dataResult.result) {
+ await AuthorizationService.addPricingAuthorizations(tenant, userToken, pricingModel, authorizationFilter);
}
}
- public static async addPricingAuthorizations(tenant: Tenant, userToken: UserToken, pricing: Pricing, authorizationFilter: AuthorizationFilter): Promise<void> {
+ public static async addPricingAuthorizations(tenant: Tenant, userToken: UserToken, pricingModel: PricingModel, authorizationFilter: AuthorizationFilter): Promise<void> {
// Enrich
- pricing.canRead = await AuthorizationService.canPerformAuthorizationAction(
- tenant, userToken, Entity.PRICING, Action.READ, authorizationFilter, { CompanyID: pricing.id }, pricing);
- pricing.canDelete = await AuthorizationService.canPerformAuthorizationAction(
- tenant, userToken, Entity.PRICING, Action.DELETE, authorizationFilter, { CompanyID: pricing.id }, pricing);
- pricing.canUpdate = await AuthorizationService.canPerformAuthorizationAction(
- tenant, userToken, Entity.PRICING, Action.UPDATE, authorizationFilter, { CompanyID: pricing.id }, pricing);
+ pricingModel.canRead = await AuthorizationService.canPerformAuthorizationAction(
+ tenant, userToken, Entity.PRICING_MODEL, Action.READ, authorizationFilter, { CompanyID: pricingModel.id }, pricingModel);
+ pricingModel.canDelete = await AuthorizationService.canPerformAuthorizationAction(
+ tenant, userToken, Entity.PRICING_MODEL, Action.DELETE, authorizationFilter, { CompanyID: pricingModel.id }, pricingModel);
+ pricingModel.canUpdate = await AuthorizationService.canPerformAuthorizationAction(
+ tenant, userToken, Entity.PRICING_MODEL, Action.UPDATE, authorizationFilter, { CompanyID: pricingModel.id }, pricingModel);
}
- public static async checkAndGetPricingAuthorizations(tenant: Tenant, userToken: UserToken,
+ public static async checkAndGetPricingModelAuthorizations(tenant: Tenant, userToken: UserToken,
filteredRequest: Partial<HttpCompanyRequest>, authAction: Action, entityData?: EntityDataType): Promise<AuthorizationFilter> {
return AuthorizationService.checkAndGetEntityAuthorizations(
- tenant, Entity.PRICING, userToken, filteredRequest, filteredRequest.ID ? { PricingID: filteredRequest.ID } : {}, authAction, entityData);
+ tenant, Entity.PRICING_MODEL, userToken, filteredRequest, filteredRequest.ID ? { PricingID: filteredRequest.ID } : {}, authAction, entityData);
}
public static async checkAndGetSiteAreaAuthorizations(tenant: Tenant, userToken: UserToken,

MODIFY
src/server/rest/v1/service/PricingService.ts
src/server/rest/v1/service/PricingService.ts
@@ -6,8 +6,8 @@ import AuthorizationService from './AuthorizationService';
import Constants from '../../../../utils/Constants';
import { HTTPAuthError } from '../../../../types/HTTPError';
import Logging from '../../../../utils/Logging';
-import Pricing from '../../../../types/Pricing';
import { PricingDataResult } from '../../../../types/DataResult';
+import PricingModel from '../../../../types/Pricing';
import PricingSecurity from './security/PricingSecurity';
import PricingStorage from '../../../../storage/mongodb/PricingStorage';
import { ServerAction } from '../../../../types/Server';
@@ -18,24 +18,24 @@ const MODULE_NAME = 'PricingService';
export default class PricingService {
- public static async handleDeletePricing(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
+ public static async handleDeletePricingModel(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Check if component is active
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.ORGANIZATION,
- Action.DELETE, Entity.COMPANY, MODULE_NAME, 'handleDeletePricing');
+ Action.DELETE, Entity.COMPANY, MODULE_NAME, 'handleDeletePricingModel');
// Filter
- const pricingID = PricingSecurity.filterPricingRequestByID(req.query);
- UtilsService.assertIdIsProvided(action, pricingID, MODULE_NAME, 'handleDeletePricing', req.user);
+ const pricingModelID = PricingSecurity.filterPricingModelRequestByID(req.query);
+ UtilsService.assertIdIsProvided(action, pricingModelID, MODULE_NAME, 'handleDeletePricingModel', req.user);
// Check and Get Pricing
- const pricing = await UtilsService.checkAndGetPricingAuthorization(
- req.tenant, req.user, pricingID, Action.DELETE, action);
+ const pricing = await UtilsService.checkAndGetPricingModelAuthorization(
+ req.tenant, req.user, pricingModelID, Action.DELETE, action);
// Delete
- await PricingStorage.deletePricing(req.tenant, pricing.id);
+ await PricingStorage.deletePricingModel(req.tenant, pricing.id);
// Log
await Logging.logSecurityInfo({
tenantID: req.user.tenantID,
- user: req.user, module: MODULE_NAME, method: 'handleDeletePricing',
+ user: req.user, module: MODULE_NAME, method: 'handleDeletePricingModel',
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
- message: `Pricing '${pricingID}' has been deleted successfully`,
+ message: `Pricing model '${pricingModelID}' has been deleted successfully`,
action: action,
detailedMessages: { pricing }
});
@@ -44,15 +44,15 @@ export default class PricingService {
next();
}
- public static async handleGetPricing(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
+ public static async handleGetPricingModel(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Check if component is active
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.ORGANIZATION,
- Action.READ, Entity.COMPANY, MODULE_NAME, 'handleGetPricing');
+ Action.READ, Entity.COMPANY, MODULE_NAME, 'handleGetPricingModel');
// Filter
const filteredRequest = PricingSecurity.filterPricingRequest(req.query);
- UtilsService.assertIdIsProvided(action, filteredRequest.ID, MODULE_NAME, 'handleGetPricing', req.user);
+ UtilsService.assertIdIsProvided(action, filteredRequest.ID, MODULE_NAME, 'handleGetPricingModel', req.user);
// Check and Get Pricing
- const pricing = await UtilsService.checkAndGetPricingAuthorization(
+ const pricing = await UtilsService.checkAndGetPricingModelAuthorization(
req.tenant, req.user, filteredRequest.ID, Action.READ, action, null, {
withLogo: true
}, true);
@@ -60,24 +60,24 @@ export default class PricingService {
next();
}
- public static async handleGetPricings(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
+ public static async handleGetPricingModels(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Check if component is active
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.ORGANIZATION,
- Action.LIST, Entity.PRICINGS, MODULE_NAME, 'handleGetPricings');
+ Action.LIST, Entity.PRICING_MODELS, MODULE_NAME, 'handleGetPricingModels');
// Filter
- const filteredRequest = PricingSecurity.filterPricingsRequest(req.query);
+ const filteredRequest = PricingSecurity.filterPricingModelsRequest(req.query);
// Check dynamic auth
- const authorizationPricingsFilter = await AuthorizationService.checkAndGetPricingsAuthorizations(
+ const authorizationPricingModelsFilter = await AuthorizationService.checkAndGetPricingModelsAuthorizations(
req.tenant, req.user, filteredRequest);
- if (!authorizationPricingsFilter.authorized) {
+ if (!authorizationPricingModelsFilter.authorized) {
UtilsService.sendEmptyDataResult(res, next);
return;
}
// Get the companies
- const pricings = await PricingStorage.getPricings(req.tenant,
+ const pricingModels = await PricingStorage.getPricingModels(req.tenant,
{
// search: filteredRequest.Search,
- ...authorizationPricingsFilter.filters
+ ...authorizationPricingModelsFilter.filters
},
{
limit: filteredRequest.Limit,
@@ -85,79 +85,79 @@ export default class PricingService {
sort: filteredRequest.SortFields,
onlyRecordCount: filteredRequest.OnlyRecordCount
},
- authorizationPricingsFilter.projectFields
+ authorizationPricingModelsFilter.projectFields
);
// Add Auth flags
- await AuthorizationService.addPricingsAuthorizations(req.tenant, req.user, pricings as PricingDataResult, authorizationPricingsFilter);
+ await AuthorizationService.addPricingModelsAuthorizations(req.tenant, req.user, pricingModels as PricingDataResult, authorizationPricingModelsFilter);
// Return
- res.json(pricings);
+ res.json(pricingModels);
next();
}
- public static async handleCreatePricing(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
+ public static async handleCreatePricingModel(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Check if component is active
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.ORGANIZATION,
- Action.CREATE, Entity.COMPANY, MODULE_NAME, 'handleCreatePricing');
+ Action.CREATE, Entity.COMPANY, MODULE_NAME, 'handleCreatePricingModel');
// Filter
- const filteredRequest = PricingSecurity.filterPricingCreateRequest(req.body);
+ const filteredRequest = PricingSecurity.filterPricingModelCreateRequest(req.body);
// Check
UtilsService.checkIfPricingValid(filteredRequest, req);
// Get dynamic auth
- const authorizationFilter = await AuthorizationService.checkAndGetPricingAuthorizations(
- req.tenant, req.user, {}, Action.CREATE, filteredRequest as Pricing);
+ const authorizationFilter = await AuthorizationService.checkAndGetPricingModelAuthorizations(
+ req.tenant, req.user, {}, Action.CREATE, filteredRequest as PricingModel);
if (!authorizationFilter.authorized) {
throw new AppAuthError({
errorCode: HTTPAuthError.FORBIDDEN,
user: req.user,
action: Action.CREATE, entity: Entity.COMPANY,
- module: MODULE_NAME, method: 'handleCreatePricing'
+ module: MODULE_NAME, method: 'handleCreatePricingModel'
});
}
// Create pricing
- const newPricing: Pricing = {
+ const newPricingModel: PricingModel = {
...filteredRequest,
issuer: true,
createdBy: { id: req.user.id },
createdOn: new Date()
- } as Pricing;
+ } as PricingModel;
// Save
- newPricing.id = await PricingStorage.savePricing(req.tenant, newPricing);
+ newPricingModel.id = await PricingStorage.savePricingModel(req.tenant, newPricingModel);
// Log
await Logging.logSecurityInfo({
tenantID: req.user.tenantID,
- user: req.user, module: MODULE_NAME, method: 'handleCreatePricing',
- message: `Pricing '${newPricing.id}' has been created successfully`,
+ user: req.user, module: MODULE_NAME, method: 'handleCreatePricingModel',
+ message: `Pricing model '${newPricingModel.id}' has been created successfully`,
action: action,
- detailedMessages: { pricing: newPricing }
+ detailedMessages: { pricingModel: newPricingModel }
});
// Ok
- res.json(Object.assign({ id: newPricing.id }, Constants.REST_RESPONSE_SUCCESS));
+ res.json(Object.assign({ id: newPricingModel.id }, Constants.REST_RESPONSE_SUCCESS));
next();
}
- public static async handleUpdatePricing(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
+ public static async handleUpdatePricingModel(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Check if component is active
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.ORGANIZATION,
- Action.UPDATE, Entity.COMPANY, MODULE_NAME, 'handleUpdatePricing');
+ Action.UPDATE, Entity.COMPANY, MODULE_NAME, 'handleUpdatePricingModel');
// Filter
- const filteredRequest = PricingSecurity.filterPricingUpdateRequest(req.body);
+ const filteredRequest = PricingSecurity.filterPricingModelUpdateRequest(req.body);
// Check Mandatory fields
UtilsService.checkIfPricingValid(filteredRequest, req);
// Check and Get Pricing
- const pricing = await UtilsService.checkAndGetPricingAuthorization(
- req.tenant, req.user, filteredRequest.id, Action.UPDATE, action, filteredRequest as Pricing);
+ const pricingModel = await UtilsService.checkAndGetPricingModelAuthorization(
+ req.tenant, req.user, filteredRequest.id, Action.UPDATE, action, filteredRequest as PricingModel);
// Update
- pricing.lastChangedBy = { 'id': req.user.id };
- pricing.lastChangedOn = new Date();
+ pricingModel.lastChangedBy = { 'id': req.user.id };
+ pricingModel.lastChangedOn = new Date();
// Update Pricing
- await PricingStorage.savePricing(req.tenant, pricing);
+ await PricingStorage.savePricingModel(req.tenant, pricingModel);
// Log
await Logging.logSecurityInfo({
tenantID: req.user.tenantID,
- user: req.user, module: MODULE_NAME, method: 'handleUpdatePricing',
- message: `Pricing '${pricing.id}' has been updated successfully`,
+ user: req.user, module: MODULE_NAME, method: 'handleUpdatePricingModel',
+ message: `Pricing model '${pricingModel.id}' has been updated successfully`,
action: action,
- detailedMessages: { pricing }
+ detailedMessages: { pricingModel: pricingModel }
});
// Ok
res.json(Constants.REST_RESPONSE_SUCCESS);

MODIFY
src/server/rest/v1/service/UtilsService.ts
src/server/rest/v1/service/UtilsService.ts
@@ -25,7 +25,7 @@ import Logging from '../../../../utils/Logging';
import OCPIEndpoint from '../../../../types/ocpi/OCPIEndpoint';
import OICPEndpoint from '../../../../types/oicp/OICPEndpoint';
import PDFDocument from 'pdfkit';
-import Pricing from '../../../../types/Pricing';
+import PricingModel from '../../../../types/Pricing';
import PricingStorage from '../../../../storage/mongodb/PricingStorage';
import { ServerAction } from '../../../../types/Server';
import Site from '../../../../types/Site';
@@ -108,46 +108,46 @@ export default class UtilsService {
return chargingStation;
}
- public static async checkAndGetPricingAuthorization(tenant: Tenant, userToken: UserToken, pricingID: string, authAction: Action,
- action: ServerAction, entityData?: EntityDataType, additionalFilters: Record<string, any> = {}, applyProjectFields = false, checkIssuer = true): Promise<Pricing> {
+ public static async checkAndGetPricingModelAuthorization(tenant: Tenant, userToken: UserToken, pricingID: string, authAction: Action,
+ action: ServerAction, entityData?: EntityDataType, additionalFilters: Record<string, any> = {}, applyProjectFields = false, checkIssuer = true): Promise<PricingModel> {
// Check mandatory fields
- UtilsService.assertIdIsProvided(action, pricingID, MODULE_NAME, 'checkAndGetPricingAuthorization', userToken);
+ UtilsService.assertIdIsProvided(action, pricingID, MODULE_NAME, 'checkAndGetPricingModelAuthorization', userToken);
// Get dynamic auth
- const authorizationFilter = await AuthorizationService.checkAndGetPricingAuthorizations(
+ const authorizationFilter = await AuthorizationService.checkAndGetPricingModelAuthorizations(
tenant, userToken, { ID: pricingID }, authAction, entityData);
if (!authorizationFilter.authorized) {
throw new AppAuthError({
errorCode: HTTPAuthError.FORBIDDEN,
user: userToken,
action: authAction, entity: Entity.COMPANY,
- module: MODULE_NAME, method: 'checkAndGetPricingAuthorization',
+ module: MODULE_NAME, method: 'checkAndGetPricingModelAuthorization',
value: pricingID
});
}
// Get Pricing
- const pricing = await PricingStorage.getPricing(tenant, pricingID,
+ const pricingModel = await PricingStorage.getPricingModel(tenant, pricingID,
{
...additionalFilters,
...authorizationFilter.filters
},
applyProjectFields ? authorizationFilter.projectFields : null
);
- UtilsService.assertObjectExists(action, pricing, `Pricing ID '${pricingID}' does not exist`,
- MODULE_NAME, 'checkAndGetPricingAuthorization', userToken);
+ UtilsService.assertObjectExists(action, pricingModel, `Pricing ID '${pricingID}' does not exist`,
+ MODULE_NAME, 'checkAndGetPricingModelAuthorization', userToken);
// Add actions
- await AuthorizationService.addPricingAuthorizations(tenant, userToken, pricing, authorizationFilter);
+ await AuthorizationService.addPricingAuthorizations(tenant, userToken, pricingModel, authorizationFilter);
// Check
- const authorized = AuthorizationService.canPerformAction(pricing, authAction);
+ const authorized = AuthorizationService.canPerformAction(pricingModel, authAction);
if (!authorized) {
throw new AppAuthError({
errorCode: HTTPAuthError.FORBIDDEN,
user: userToken,
action: authAction, entity: Entity.COMPANY,
- module: MODULE_NAME, method: 'checkAndGetPricingAuthorization',
+ module: MODULE_NAME, method: 'checkAndGetPricingModelAuthorization',
value: pricingID
});
}
- return pricing;
+ return pricingModel;
}
public static async checkAndGetCompanyAuthorization(tenant: Tenant, userToken: UserToken, companyID: string, authAction: Action,
@@ -1330,7 +1330,7 @@ export default class UtilsService {
}
}
- public static checkIfPricingValid(pricing: Partial<Pricing>, req: Request): void {
+ public static checkIfPricingValid(pricing: Partial<PricingModel>, req: Request): void {
if (req.method !== 'POST' && !pricing.id) {
throw new AppError({
source: Constants.CENTRAL_SERVER,

MODIFY
src/server/rest/v1/service/security/PricingSecurity.ts
src/server/rest/v1/service/security/PricingSecurity.ts
-import { HttpPricingRequest, HttpPricingsRequest } from '../../../../../types/requests/HttpPricingRequest';
+import { HttpPricingModelRequest, HttpPricingModelsRequest } from '../../../../../types/requests/HttpPricingRequest';
-import Pricing from '../../../../../types/Pricing';
+import PricingModel from '../../../../../types/Pricing';
import UtilsSecurity from './UtilsSecurity';
import sanitize from 'mongo-sanitize';
export default class PricingSecurity {
- public static filterPricingRequestByID(request: any): string {
+ public static filterPricingModelRequestByID(request: any): string {
return sanitize(request.ID);
}
- public static filterPricingRequest(request: any): HttpPricingRequest {
+ public static filterPricingRequest(request: any): HttpPricingModelRequest {
return {
ID: sanitize(request.ID)
};
}
- public static filterPricingsRequest(request: any): HttpPricingsRequest {
- const filteredRequest: HttpPricingsRequest = {
+ public static filterPricingModelsRequest(request: any): HttpPricingModelsRequest {
+ const filteredRequest: HttpPricingModelsRequest = {
Search: sanitize(request.Search),
- } as HttpPricingsRequest;
+ } as HttpPricingModelsRequest;
UtilsSecurity.filterSkipAndLimit(request, filteredRequest);
UtilsSecurity.filterSort(request, filteredRequest);
return filteredRequest;
}
- static filterPricingUpdateRequest(request: any): Partial<Pricing> {
- const filteredRequest = PricingSecurity._filterPricingRequest(request);
+ static filterPricingModelUpdateRequest(request: any): Partial<PricingModel> {
+ const filteredRequest = PricingSecurity._filterPricingModelRequest(request);
return {
id: sanitize(request.id),
...filteredRequest
};
}
- public static filterPricingCreateRequest(request: any): Partial<Pricing> {
- return PricingSecurity._filterPricingRequest(request);
+ public static filterPricingModelCreateRequest(request: any): Partial<PricingModel> {
+ return PricingSecurity._filterPricingModelRequest(request);
}
- public static _filterPricingRequest(request: any): Partial<Pricing> {
+ public static _filterPricingModelRequest(request: any): Partial<PricingModel> {
const filteredRequest = {
name: sanitize(request.name),
address: UtilsSecurity.filterAddressRequest(request.address)
- } as Partial<Pricing>;
+ } as Partial<PricingModel>;
return filteredRequest;
}
}

MODIFY
src/storage/mongodb/PricingStorage.ts
src/storage/mongodb/PricingStorage.ts
@@ -5,7 +5,7 @@ import { DataResult } from '../../types/DataResult';
import DatabaseUtils from './DatabaseUtils';
import DbParams from '../../types/database/DbParams';
import Logging from '../../utils/Logging';
-import Pricing from '../../types/Pricing';
+import PricingModel from '../../types/Pricing';
import Tenant from '../../types/Tenant';
import Utils from '../../utils/Utils';
@@ -13,9 +13,9 @@ const MODULE_NAME = 'PricingStorage';
export default class PricingStorage {
- public static async savePricing(tenant: Tenant, pricing: Pricing): Promise<string> {
+ public static async savePricingModel(tenant: Tenant, pricing: PricingModel): Promise<string> {
// Debug
- const uniqueTimerID = Logging.traceStart(tenant.id, MODULE_NAME, 'savePricing');
+ const uniqueTimerID = Logging.traceStart(tenant.id, MODULE_NAME, 'savePricingModel');
// Check Tenant
DatabaseUtils.checkTenantObject(tenant);
const pricingMDB = {
@@ -26,44 +26,44 @@ export default class PricingStorage {
// Check Created/Last Changed By
DatabaseUtils.addLastChangedCreatedProps(pricingMDB, pricing);
// Save
- await global.database.getCollection<any>(tenant.id, 'pricings').findOneAndUpdate(
+ await global.database.getCollection<any>(tenant.id, 'pricingmodels').findOneAndUpdate(
{ '_id': pricing.id },
{ $set: pricingMDB },
{ upsert: true, returnDocument: 'after' });
// Debug
- await Logging.traceEnd(tenant.id, MODULE_NAME, 'savePricing', uniqueTimerID, pricingMDB);
+ await Logging.traceEnd(tenant.id, MODULE_NAME, 'savePricingModel', uniqueTimerID, pricingMDB);
return pricingMDB._id.toString();
}
- public static async deletePricing(tenant: Tenant, pricingID: string): Promise<void> {
+ public static async deletePricingModel(tenant: Tenant, pricingID: string): Promise<void> {
// Debug
const uniqueTimerID = Logging.traceStart(tenant.id, MODULE_NAME, 'deletePricing');
// Check Tenant
DatabaseUtils.checkTenantObject(tenant);
// Delete
- await global.database.getCollection<any>(tenant.id, 'pricings').deleteOne(
+ await global.database.getCollection<any>(tenant.id, 'pricingmodels').deleteOne(
{
'_id': pricingID,
}
);
// Debug
- await Logging.traceEnd(tenant.id, MODULE_NAME, 'deletePricing', uniqueTimerID, { id: pricingID });
+ await Logging.traceEnd(tenant.id, MODULE_NAME, 'deletePricingModel', uniqueTimerID, { id: pricingID });
}
- public static async getPricing(tenant: Tenant, id: string,
- params: { contextIDs?: string[]; } = {}, projectFields?: string[]): Promise<Pricing> {
- const pricingMDB = await PricingStorage.getPricings(tenant, {
+ public static async getPricingModel(tenant: Tenant, id: string,
+ params: { contextIDs?: string[]; } = {}, projectFields?: string[]): Promise<PricingModel> {
+ const pricingMDB = await PricingStorage.getPricingModels(tenant, {
contextIDs: params.contextIDs,
}, Constants.DB_PARAMS_SINGLE_RECORD, projectFields);
return pricingMDB.count === 1 ? pricingMDB.result[0] : null;
}
- public static async getPricings(tenant: Tenant,
+ public static async getPricingModels(tenant: Tenant,
params: {
contextIDs?: string[];
},
- dbParams: DbParams, projectFields?: string[]): Promise<DataResult<Pricing>> {
- const uniqueTimerID = Logging.traceStart(tenant.id, MODULE_NAME, 'getPricings');
+ dbParams: DbParams, projectFields?: string[]): Promise<DataResult<PricingModel>> {
+ const uniqueTimerID = Logging.traceStart(tenant.id, MODULE_NAME, 'getPricingModels');
// Check Tenant
DatabaseUtils.checkTenantObject(tenant);
// Clone before updating the values
@@ -79,19 +79,19 @@ export default class PricingStorage {
filters.deleted = { '$ne': true };
// Limit records?
if (!dbParams.onlyRecordCount) {
- // Always limit the nbr of record to avoid perfs issues
+ // Always limit the nbr of record to avoid performances issues
aggregation.push({ $limit: Constants.DB_RECORD_COUNT_CEIL });
}
// Count Records
- const pricingsCountMDB = await global.database.getCollection<any>(tenant.id, 'pricings')
+ const pricingModelsCountMDB = await global.database.getCollection<any>(tenant.id, 'pricingmodels')
.aggregate([...aggregation, { $count: 'count' }], { allowDiskUse: true })
.toArray();
// Check if only the total count is requested
if (dbParams.onlyRecordCount) {
// Return only the count
- await Logging.traceEnd(tenant.id, MODULE_NAME, 'getPricings', uniqueTimerID, pricingsCountMDB);
+ await Logging.traceEnd(tenant.id, MODULE_NAME, 'getPricingModels', uniqueTimerID, pricingModelsCountMDB);
return {
- count: (pricingsCountMDB.length > 0 ? pricingsCountMDB[0].count : 0),
+ count: (pricingModelsCountMDB.length > 0 ? pricingModelsCountMDB[0].count : 0),
result: []
};
}
@@ -120,18 +120,18 @@ export default class PricingStorage {
// Project
DatabaseUtils.projectFields(aggregation, projectFields);
// Read DB
- const pricingsMDB = await global.database.getCollection<Pricing>(tenant.id, 'pricings')
+ const pricingModelMDB = await global.database.getCollection<PricingModel>(tenant.id, 'pricingmodels')
.aggregate(aggregation, {
allowDiskUse: true
})
.toArray();
// Debug
- await Logging.traceEnd(tenant.id, MODULE_NAME, 'getPricings', uniqueTimerID, pricingsMDB);
+ await Logging.traceEnd(tenant.id, MODULE_NAME, 'getPricingModels', uniqueTimerID, pricingModelMDB);
// Ok
return {
- count: (pricingsCountMDB.length > 0 ?
- (pricingsCountMDB[0].count === Constants.DB_RECORD_COUNT_CEIL ? -1 : pricingsCountMDB[0].count) : 0),
- result: pricingsMDB,
+ count: (pricingModelsCountMDB.length > 0 ?
+ (pricingModelsCountMDB[0].count === Constants.DB_RECORD_COUNT_CEIL ? -1 : pricingModelsCountMDB[0].count) : 0),
+ result: pricingModelMDB,
projectedFields: projectFields
};
}

MODIFY
src/types/Authorization.ts
src/types/Authorization.ts
@@ -69,7 +69,8 @@ export enum Entity {
LOGGINGS = 'Loggings',
LOGGING = 'Logging',
PRICING = 'Pricing',
- PRICINGS = 'Pricings',
+ PRICING_MODEL = 'PricingModel',
+ PRICING_MODELS = 'PricingModels',
BILLING = 'Billing',
SETTING = 'Setting',
SETTINGS = 'Settings',

MODIFY
src/types/DataResult.ts
src/types/DataResult.ts
import { Car, CarCatalog } from './Car';
import Company from './Company';
-import Pricing from './Pricing';
+import PricingModel from './Pricing';
import Site from './Site';
import SiteArea from './SiteArea';
import Tag from './Tag';
@@ -18,7 +18,7 @@ export interface DataResult<T> {
projectedFields?: string[];
}
-export interface PricingDataResult extends DataResult<Pricing>{
+export interface PricingDataResult extends DataResult<PricingModel>{
canCreate: boolean;
}

MODIFY
src/types/GlobalType.ts
src/types/GlobalType.ts
@@ -4,7 +4,7 @@ import ChargingStation from './ChargingStation';
import Company from './Company';
import JsonCentralSystemServer from '../server/ocpp/json/JsonCentralSystemServer';
import MongoDBStorage from '../storage/mongodb/MongoDBStorage';
-import Pricing from './Pricing';
+import PricingModel from './Pricing';
import Site from './Site';
import SiteArea from './SiteArea';
import SoapCentralSystemServer from '../server/ocpp/soap/SoapCentralSystemServer';
@@ -49,7 +49,7 @@ export enum ImportStatus {
ERROR = 'E',
}
-export type EntityDataType = Car|User|Company|Site|SiteArea|Tag|CarCatalog|ChargingStation|Pricing;
+export type EntityDataType = Car|User|Company|Site|SiteArea|Tag|CarCatalog|ChargingStation|PricingModel;
interface TSGlobal extends Global {
database: MongoDBStorage;

MODIFY
src/types/Pricing.ts
src/types/Pricing.ts
import { AuthorizationActions } from './Authorization';
import CreatedUpdatedProps from './CreatedUpdatedProps';
-export default interface Pricing extends CreatedUpdatedProps, AuthorizationActions {
+export default interface PricingModel extends CreatedUpdatedProps, AuthorizationActions {
id: string;
contextID: string; // id of the entity the pricing definition belongs to!
pricingDefinitions: PricingDefinition[];

MODIFY
src/types/Transaction.ts
src/types/Transaction.ts
@@ -8,7 +8,7 @@ import { OCPICdr } from './ocpi/OCPICdr';
import { OCPISession } from './ocpi/OCPISession';
import { OICPChargeDetailRecord } from './oicp/OICPChargeDetailRecord';
import { OICPSession } from './oicp/OICPSession';
-import Pricing from './Pricing';
+import PricingModel from './Pricing';
import Site from './Site';
import SiteArea from './SiteArea';
import Tag from './Tag';
@@ -82,7 +82,7 @@ export default interface Transaction extends AbstractCurrentConsumption {
roundedPrice?: number;
priceUnit?: string;
pricingSource?: string;
- pricing?: Pricing,
+ pricing?: PricingModel,
stateOfCharge: number;
timezone: string;
currentTimestamp?: Date;

MODIFY
src/types/requests/HttpPricingRequest.ts
src/types/requests/HttpPricingRequest.ts
import HttpByIDRequest from './HttpByIDRequest';
import HttpDatabaseRequest from './HttpDatabaseRequest';
-export interface HttpPricingRequest extends HttpByIDRequest {
+export interface HttpPricingModelRequest extends HttpByIDRequest {
ID: string;
}
-export interface HttpPricingsRequest extends HttpDatabaseRequest {
+export interface HttpPricingModelsRequest extends HttpDatabaseRequest {
Search?: string;
}

pricing - renaming pricings term