Added site getOne/Assign/getImage JSON schemas
ADD
src/assets/server/rest/v1/schemas/site/site-get-image.json
+{
+ "$id": "site-get-image",
+ "title": "Get site image Request",
+ "type": "object",
+ "properties": {
+ "ID": {
+ "$ref": "common#/definitions/id"
+ },
+ "TenantID": {
+ "$ref": "common#/definitions/id"
+ }
+ },
+ "required": [
+ "ID"
+ ]
+}

ADD
src/assets/server/rest/v1/schemas/site/site-get.json
+{
+ "$id": "site-get",
+ "title": "Get site Request",
+ "type": "object",
+ "properties": {
+ "ID": {
+ "$ref": "common#/definitions/id"
+ },
+ "WithCompany": {
+ "type": "boolean",
+ "sanitize": "mongo"
+ }
+ },
+ "required": [
+ "ID"
+ ]
+}

ADD
src/assets/server/rest/v1/schemas/site/site-users-assign.json
+{
+ "$id": "site-assign",
+ "title": "Assign / unassign users Request",
+ "type": "object",
+ "properties": {
+ "siteID": {
+ "$ref": "site#/definitions/id"
+ },
+ "userIDs": {
+ "type": "array",
+ "items": {
+ "$ref": "user#/definitions/id"
+ }
+ }
+ },
+ "required": [
+ "siteID",
+ "userIDs"
+ ]
+}

MODIFY
src/assets/server/rest/v1/schemas/site/sites-get.json
src/assets/server/rest/v1/schemas/site/sites-get.json
"$ref": "user#/definitions/id"
},
"CompanyID": {
- "$ref": "company#/definitions/id"
+ "$ref": "common#/definitions/ids"
},
"SiteID": {
- "$ref": "site#/definitions/id"
+ "$ref": "common#/definitions/ids"
},
"ExcludeSitesOfUserID": {
"type": "boolean",

MODIFY
src/server/rest/v1/service/SiteService.ts
src/server/rest/v1/service/SiteService.ts
@@ -139,7 +139,7 @@ export default class SiteService {
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.ORGANIZATION,
Action.UPDATE, Entity.SITE, MODULE_NAME, 'handleAssignUsersToSite');
// Filter request
- const filteredRequest = SiteSecurity.filterAssignSiteUsers(req.body);
+ const filteredRequest = SiteValidator.getInstance().validateSiteAssignUsersReq(req.body);
// Check and Get Site
const site = await UtilsService.checkAndGetSiteAuthorization(
req.tenant, req.user, filteredRequest.siteID, Action.READ, action);
@@ -210,7 +210,7 @@ export default class SiteService {
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.ORGANIZATION,
Action.DELETE, Entity.SITE, MODULE_NAME, 'handleDeleteSite');
// Filter request
- const siteID = SiteSecurity.filterSiteRequestByID(req.query);
+ const siteID = SiteValidator.getInstance().validateSiteGetReq(req.query).ID;
// Check and Get Site
const site = await UtilsService.checkAndGetSiteAuthorization(
req.tenant, req.user, siteID, Action.DELETE, action);
@@ -233,7 +233,7 @@ export default class SiteService {
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.ORGANIZATION,
Action.READ, Entity.SITE, MODULE_NAME, 'handleGetSite');
// Filter request
- const filteredRequest = SiteSecurity.filterSiteRequest(req.query);
+ const filteredRequest = SiteValidator.getInstance().validateSiteGetReq(req.query);
// Check and Get Site
const site = await UtilsService.checkAndGetSiteAuthorization(
req.tenant, req.user, filteredRequest.ID, Action.READ, action, null, {
@@ -302,7 +302,7 @@ export default class SiteService {
public static async handleGetSiteImage(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// This endpoint is not protected, so no need to check user's access
// Filter
- const filteredRequest = SiteSecurity.filterSiteImageRequest(req.query);
+ const filteredRequest = SiteValidator.getInstance().validateSiteGetImageReq(req.query);
UtilsService.assertIdIsProvided(action, filteredRequest.ID, MODULE_NAME, 'handleGetSiteImage', req.user);
if (!filteredRequest.TenantID) {
// Object does not exist

MODIFY
src/server/rest/v1/validator/SiteValidator.ts
src/server/rest/v1/validator/SiteValidator.ts
-import { HttpSiteOwnerRequest, HttpSiteUserAdminRequest, HttpSitesRequest } from '../../../../types/requests/HttpSiteRequest';
+import { HttpSiteAssignUsersRequest, HttpSiteImageRequest, HttpSiteOwnerRequest, HttpSiteRequest, HttpSiteUserAdminRequest, HttpSitesRequest } from '../../../../types/requests/HttpSiteRequest';
+import HttpByIDRequest from '../../../../types/requests/HttpByIDRequest';
import Schema from '../../../../types/validator/Schema';
import SchemaValidator from '../../../../validator/SchemaValidator';
import Site from '../../../../types/Site';
@@ -12,6 +13,9 @@ export default class SiteValidator extends SchemaValidator {
private siteAdmin: Schema;
private siteOwner: Schema;
private sitesGet: Schema;
+ private siteAssignUsers: Schema;
+ private siteGet: Schema;
+ private siteGetImage: Schema;
private constructor() {
super('SiteValidator');
@@ -19,6 +23,9 @@ export default class SiteValidator extends SchemaValidator {
this.siteAdmin = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/site/site-admin.json`, 'utf8'));
this.siteOwner = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/site/site-owner.json`, 'utf8'));
this.sitesGet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/site/sites-get.json`, 'utf8'));
+ this.siteAssignUsers = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/site/site-users-assign.json`, 'utf8'));
+ this.siteGet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/site/site-get.json`, 'utf8'));
+ this.siteGetImage = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/site/site-get-image.json`, 'utf8'));
}
public static getInstance(): SiteValidator {
@@ -43,4 +50,16 @@ export default class SiteValidator extends SchemaValidator {
public validateSitesGetReq(data: Record<string, unknown>): HttpSitesRequest {
return this.validate(this.sitesGet, data);
}
+
+ public validateSiteAssignUsersReq(data: Record<string, unknown>): HttpSiteAssignUsersRequest {
+ return this.validate(this.siteAssignUsers, data);
+ }
+
+ public validateSiteGetReq(data: Record<string, unknown>): HttpSiteRequest {
+ return this.validate(this.siteGet, data);
+ }
+
+ public validateSiteGetImageReq(data: Record<string, unknown>): HttpSiteImageRequest {
+ return this.validate(this.siteGetImage, data);
+ }
}

MODIFY
test/api/context/ContextProvider.ts
test/api/context/ContextProvider.ts
@@ -96,8 +96,6 @@ export default class ContextProvider {
if (tenantEntity.components && tenantEntity.components[TenantComponents.ORGANIZATION] &&
tenantEntity.components[TenantComponents.ORGANIZATION].active) {
siteAreaList = (await defaultAdminCentralServiceService.siteAreaApi.readAll({}, { limit: 0, skip: 0 })).data.result;
- const asiteList = await defaultAdminCentralServiceService.siteApi.readAll({}, { limit: 0, skip: 0 });
-
siteList = (await defaultAdminCentralServiceService.siteApi.readAll({}, { limit: 0, skip: 0 })).data.result;
companyList = (await defaultAdminCentralServiceService.companyApi.readAll({}, { limit: 0, skip: 0 })).data.result;
chargingStationList = (await defaultAdminCentralServiceService.chargingStationApi.readAll({}, TestConstants.DEFAULT_PAGING)).data.result;

Added site getOne/Assign/getImage JSON schemas