Skip to content

Commit

Permalink
Merge branch 'master-qa' of github.com:LucasBrazi06/ev-server into ma…
Browse files Browse the repository at this point in the history
…ster-qa
  • Loading branch information
LucasBrazi06 committed Dec 7, 2021
2 parents 85991a2 + d4f8fca commit 4642bdb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
38 changes: 26 additions & 12 deletions src/server/rest/v1/service/PricingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class PricingService {
pricingDefinitions.projectFields = authorizationPricingDefinitionsFilter.projectFields;
}
// Add Auth flags
await AuthorizationService.addPricingDefinitionsAuthorizations(req.tenant, req.user, pricingDefinitions , authorizationPricingDefinitionsFilter);
await AuthorizationService.addPricingDefinitionsAuthorizations(req.tenant, req.user, pricingDefinitions, authorizationPricingDefinitionsFilter);
// Alter the canCreate flag according to the pricing definition context
pricingDefinitions.canCreate = await PricingService.alterCanCreate(req, action, filteredRequest.EntityType, filteredRequest.EntityID, pricingDefinitions.canCreate);
res.json(pricingDefinitions);
Expand All @@ -95,6 +95,10 @@ export default class PricingService {
}
// Check authorization and get the site ID depending on the entity type
const siteID = await PricingService.checkAuthorizationAndGetSiteID(req, action, filteredRequest.entityType, filteredRequest.entityID);
// Check that the pricing definitions can be changed for that site
if (siteID) {
await UtilsService.checkAndGetSiteAuthorization(req.tenant, req.user, siteID, Action.MAINTAIN_PRICING_DEFINITIONS, action);
}
// Create pricing
const newPricingDefinition: PricingDefinition = {
...filteredRequest,
Expand Down Expand Up @@ -126,21 +130,25 @@ export default class PricingService {
// Check Mandatory fields
UtilsService.checkIfPricingDefinitionValid(filteredRequest, req);
// Check and Get Pricing
const pricingDefinition = await UtilsService.checkAndGetPricingDefinitionAuthorization(
let pricingDefinition = await UtilsService.checkAndGetPricingDefinitionAuthorization(
req.tenant, req.user, filteredRequest.id, Action.UPDATE, action, filteredRequest);
// Update timestamp
const lastChangedBy = { id: req.user.id };
const lastChangedOn = new Date();
// Check authorization and get the site ID depending on the entity type
const siteID = await PricingService.checkAuthorizationAndGetSiteID(req, action, filteredRequest.entityType, filteredRequest.entityID);
// Check that the pricing definitions can be changed for that site
if (siteID) {
await UtilsService.checkAndGetSiteAuthorization(req.tenant, req.user, siteID, Action.MAINTAIN_PRICING_DEFINITIONS, action);
}
// Update
pricingDefinition.entityID = filteredRequest.entityID;
pricingDefinition.entityType = filteredRequest.entityType;
pricingDefinition.name = filteredRequest.name;
pricingDefinition.description = filteredRequest.description;
pricingDefinition.staticRestrictions = filteredRequest.staticRestrictions;
pricingDefinition.restrictions = filteredRequest.restrictions;
pricingDefinition.dimensions = filteredRequest.dimensions;
pricingDefinition.lastChangedBy = { 'id': req.user.id };
pricingDefinition.lastChangedOn = new Date();
pricingDefinition.siteID = siteID;
pricingDefinition = {
...pricingDefinition,
...filteredRequest,
lastChangedBy,
lastChangedOn,
siteID
};
// Update Pricing
await PricingStorage.savePricingDefinition(req.tenant, pricingDefinition);
// Log
Expand All @@ -164,6 +172,12 @@ export default class PricingService {
// Check and Get Pricing
const pricingDefinition = await UtilsService.checkAndGetPricingDefinitionAuthorization(
req.tenant, req.user, pricingDefinitionID, Action.DELETE, action);
// Check authorization and get the site ID depending on the entity type
const siteID = await PricingService.checkAuthorizationAndGetSiteID(req, action, pricingDefinition.entityType, pricingDefinition.entityID);
// Check that the pricing definitions can be changed for that site
if (siteID) {
await UtilsService.checkAndGetSiteAuthorization(req.tenant, req.user, siteID, Action.MAINTAIN_PRICING_DEFINITIONS, action);
}
// Delete
await PricingStorage.deletePricingDefinition(req.tenant, pricingDefinition.id);
// Log
Expand Down
1 change: 1 addition & 0 deletions src/storage/mongodb/CarStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ export default class CarStorage {
$concat: [
`${Utils.buildRestServerURL()}/v1/util/car-catalogs/`,
'$carCatalog.id',
'/image',
{
$ifNull: [{ $concat: ['?LastChangedOn=', { $toString: '$carCatalog.lastChangedOn' }] }, ''] // Only concat 'lastChangedOn' if not null
}
Expand Down

0 comments on commit 4642bdb

Please sign in to comment.