Added setting getById/getMany/getByIdentifier schemas
ADD
src/assets/server/rest/v1/schemas/setting/setting-by-id.json
+{
+ "$id": "setting-by-id",
+ "title": "Setting by id Request",
+ "description": "",
+ "type": "object",
+ "properties": {
+ "ID": {
+ "$ref": "setting#/definitions/id"
+ }
+ },
+ "required": [
+ "ID"
+ ]
+}

ADD
src/assets/server/rest/v1/schemas/setting/setting-by-identifier.json
+{
+ "$id": "setting-by-identifier",
+ "title": "Setting by identifier Request",
+ "description": "",
+ "type": "object",
+ "properties": {
+ "Identifier": {
+ "$ref": "setting#/definitions/identifier"
+ }
+ },
+ "required": [
+ "Identifier"
+ ]
+}

ADD
src/assets/server/rest/v1/schemas/setting/settings-get.json
+{
+ "$id": "settings-get",
+ "title": "Settings get Request",
+ "description": "",
+ "type": "object",
+ "properties": {
+ "Identifier": {
+ "$ref": "setting#/definitions/identifier"
+ },
+ "ContentFilter": {
+ "type": "boolean",
+ "sanitize": "mongo"
+ },
+ "Limit": {
+ "$ref": "common#/definitions/limit"
+ },
+ "SortFields": {
+ "$ref": "common#/definitions/sortFields"
+ },
+ "Skip": {
+ "$ref": "common#/definitions/skip"
+ },
+ "OnlyRecordCount": {
+ "$ref": "common#/definitions/onlyRecordCount"
+ },
+ "ProjectFields": {
+ "$ref": "common#/definitions/projectFields"
+ }
+ },
+ "required": [
+ "Limit"
+ ]
+}

MODIFY
src/server/rest/v1/service/SettingService.ts
src/server/rest/v1/service/SettingService.ts
@@ -23,7 +23,7 @@ const MODULE_NAME = 'SettingService';
export default class SettingService {
public static async handleDeleteSetting(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const settingID = SettingSecurity.filterSettingRequestByID(req.query);
+ const settingID = SettingValidator.getInstance().validateSettingGetByIDReq(req.query).ID;
UtilsService.assertIdIsProvided(action, settingID, MODULE_NAME, 'handleDeleteSetting', req.user);
// Check auth
if (!await Authorizations.canDeleteSetting(req.user)) {
@@ -55,7 +55,7 @@ export default class SettingService {
public static async handleGetSetting(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const settingID = SettingSecurity.filterSettingRequestByID(req.query);
+ const settingID = SettingValidator.getInstance().validateSettingGetByIDReq(req.query).ID;
UtilsService.assertIdIsProvided(action, settingID, MODULE_NAME, 'handleGetSetting', req.user);
// Check auth
if (!await Authorizations.canReadSetting(req.user)) {
@@ -84,7 +84,7 @@ export default class SettingService {
public static async handleGetSettingByIdentifier(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const settingID = SettingSecurity.filterSettingRequestByID(req.query);
+ const settingID = SettingValidator.getInstance().validateSettingGetByIdentifierReq(req.query).Identifier;
UtilsService.assertIdIsProvided(action, settingID, MODULE_NAME, 'handleGetSettingByIdentifier', req.user);
// Check auth
if (!await Authorizations.canReadSetting(req.user)) {
@@ -122,7 +122,7 @@ export default class SettingService {
});
}
// Filter
- const filteredRequest = SettingSecurity.filterSettingsRequest(req.query);
+ const filteredRequest = SettingValidator.getInstance().validateSettingsGetReq(req.query);
// Get the all settings identifier
const settings = await SettingStorage.getSettings(req.tenant,
{ identifier: filteredRequest.Identifier },

MODIFY
src/server/rest/v1/service/security/SettingSecurity.ts
src/server/rest/v1/service/security/SettingSecurity.ts
@@ -11,13 +11,6 @@ export default class SettingSecurity {
return sanitize(request.ID);
}
- public static filterSettingRequest(request: any): HttpSettingRequest {
- return {
- ID: sanitize(request.ID),
- ContentFilter: UtilsSecurity.filterBoolean(request.ContentFilter)
- };
- }
-
public static filterSettingsRequest(request: any): HttpSettingsRequest {
const filteredRequest: HttpSettingsRequest = {} as HttpSettingsRequest;
filteredRequest.Identifier = sanitize(request.Identifier);

MODIFY
src/server/rest/v1/validator/SettingValidator.ts
src/server/rest/v1/validator/SettingValidator.ts
-import { HttpSettingAssetSetRequest, HttpSettingBillingSetRequest, HttpSettingCarConnectorSetRequest, HttpSettingCryptoSetRequest, HttpSettingOCPISetRequest, HttpSettingOICPSetRequest, HttpSettingPricingSetRequest, HttpSettingRefundSetRequest, HttpSettingSacSetRequest, HttpSettingSmartChargingSetRequest, HttpSettingUserSetRequest } from '../../../../types/requests/HttpSettingRequest';
+import { HttpSettingAssetSetRequest, HttpSettingBillingSetRequest, HttpSettingByIdentifierRequest, HttpSettingCarConnectorSetRequest, HttpSettingCryptoSetRequest, HttpSettingOCPISetRequest, HttpSettingOICPSetRequest, HttpSettingPricingSetRequest, HttpSettingRefundSetRequest, HttpSettingRequest, HttpSettingSacSetRequest, HttpSettingSmartChargingSetRequest, HttpSettingUserSetRequest, HttpSettingsRequest } from '../../../../types/requests/HttpSettingRequest';
import Schema from '../../../../types/validator/Schema';
import SchemaValidator from '../../../../validator/SchemaValidator';
@@ -7,6 +7,9 @@ import global from '../../../../types/GlobalType';
export default class SettingValidator extends SchemaValidator {
private static instance: SettingValidator|null = null;
+ private settingGetByID: Schema;
+ private settingGetByIdentifier: Schema;
+ private settingsGet: Schema;
private settingOCPISet: Schema;
private settingUserSet: Schema;
private settingSmartChargingSet: Schema;
@@ -21,6 +24,9 @@ export default class SettingValidator extends SchemaValidator {
private constructor() {
super('SettingValidator');
+ this.settingGetByID = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/setting/setting-by-id.json`, 'utf8'));
+ this.settingGetByIdentifier = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/setting/setting-by-identifier.json`, 'utf8'));
+ this.settingsGet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/setting/settings-get.json`, 'utf8'));
this.settingOCPISet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/setting/setting-ocpi-set.json`, 'utf8'));
this.settingSmartChargingSet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/setting/setting-smart-charging-set.json`, 'utf8'));
this.settingUserSet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/setting/setting-user-set.json`, 'utf8'));
@@ -41,6 +47,18 @@ export default class SettingValidator extends SchemaValidator {
return SettingValidator.instance;
}
+ public validateSettingGetByIDReq(data: Record<string, unknown>): HttpSettingRequest {
+ return this.validate(this.settingGetByID, data);
+ }
+
+ public validateSettingGetByIdentifierReq(data: Record<string, unknown>): HttpSettingByIdentifierRequest {
+ return this.validate(this.settingGetByIdentifier, data);
+ }
+
+ public validateSettingsGetReq(data: Record<string, unknown>): HttpSettingsRequest {
+ return this.validate(this.settingsGet, data);
+ }
+
public validateSettingOCPISetReq(data: Record<string, unknown>): HttpSettingOCPISetRequest {
return this.validate(this.settingOCPISet, data);
}

MODIFY
src/types/requests/HttpSettingRequest.ts
src/types/requests/HttpSettingRequest.ts
@@ -4,7 +4,11 @@ import HttpByIDRequest from './HttpByIDRequest';
import HttpDatabaseRequest from './HttpDatabaseRequest';
export interface HttpSettingRequest extends HttpByIDRequest {
- ContentFilter: boolean;
+ ID: string;
+}
+
+export interface HttpSettingByIdentifierRequest {
+ Identifier: string;
}
export interface HttpSettingsRequest extends HttpDatabaseRequest {

Added setting getById/getMany/getByIdentifier schemas