first version without Validators
MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -149,7 +149,7 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
resource: Entity.SITE, action: Action.READ,
attributes: [
'id', 'name', 'address', 'companyID', 'company.name', 'autoUserSiteAssignment', 'issuer',
- 'autoUserSiteAssignment', 'distanceMeters', 'public', 'createdOn', 'lastChangedOn'
+ 'autoUserSiteAssignment', 'distanceMeters', 'public', 'createdOn', 'lastChangedOn', 'tariffID'
]
},
{

MODIFY
src/server/rest/v1/service/SiteService.ts
src/server/rest/v1/service/SiteService.ts
@@ -414,6 +414,10 @@ export default class SiteService {
}
site.public = filteredRequest.public;
}
+ if (Utils.objectHasProperty(filteredRequest, 'tariffID') &&
+ filteredRequest.tariffID !== '') {
+ site.tariffID = filteredRequest.tariffID;
+ }
if (Utils.objectHasProperty(filteredRequest, 'autoUserSiteAssignment')) {
site.autoUserSiteAssignment = filteredRequest.autoUserSiteAssignment;
}

MODIFY
src/server/rest/v1/service/security/SiteSecurity.ts
src/server/rest/v1/service/security/SiteSecurity.ts
@@ -112,6 +112,7 @@ export default class SiteSecurity {
name: sanitize(request.name),
address: UtilsSecurity.filterAddressRequest(request.address),
public: UtilsSecurity.filterBoolean(request.public),
+ tariffID: request.tariffID ? sanitize(request.tariffID) : null,
autoUserSiteAssignment: UtilsSecurity.filterBoolean(request.autoUserSiteAssignment),
companyID: sanitize(request.companyID),
} as Partial<Site>;

MODIFY
src/storage/mongodb/SiteStorage.ts
src/storage/mongodb/SiteStorage.ts
@@ -271,6 +271,9 @@ export default class SiteStorage {
(coordinate) => Utils.convertToFloat(coordinate)) : [],
};
}
+ if (siteToSave.tariffID) {
+ siteMDB.tariffID = siteToSave.tariffID;
+ }
// Add Last Changed/Created props
DatabaseUtils.addLastChangedCreatedProps(siteMDB, siteToSave);
// Modify and return the modified document

MODIFY
src/types/Site.ts
src/types/Site.ts
@@ -20,6 +20,7 @@ export default interface Site extends CreatedUpdatedProps, SiteAuthorizationActi
distanceMeters?: number;
public?: boolean;
openingTimes?: OpeningTimes;
+ tariffID?: string;
}
export interface SiteUser {

first version without Validators