Added sites getMany validation
MODIFY
src/assets/server/rest/v1/schemas/site/sites-get.json
src/assets/server/rest/v1/schemas/site/sites-get.json
"sanitize": "mongo",
"exclusiveMinimum": 0
},
+ "Search": {
+ "$ref": "common#/definitions/search"
+ },
"Limit": {
"$ref": "common#/definitions/limit"
},

MODIFY
src/server/rest/v1/service/SiteService.ts
src/server/rest/v1/service/SiteService.ts
@@ -250,7 +250,14 @@ export default class SiteService {
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.ORGANIZATION,
Action.LIST, Entity.SITE, MODULE_NAME, 'handleGetSites');
// Filter request
- const filteredRequest = SiteSecurity.filterSitesRequest(req.query);
+ const filteredRequest = SiteValidator.getInstance().validateSitesGetReq(req.query);
+ // Create GPS Coordinates
+ if (filteredRequest.LocLongitude && filteredRequest.LocLatitude) {
+ filteredRequest.LocCoordinates = [
+ Utils.convertToFloat(filteredRequest.LocLongitude),
+ Utils.convertToFloat(filteredRequest.LocLatitude)
+ ];
+ }
// Check dynamic auth
const authorizationSitesFilter = await AuthorizationService.checkAndGetSitesAuthorizations(
req.tenant, req.user, filteredRequest);
@@ -276,7 +283,7 @@ export default class SiteService {
{
limit: filteredRequest.Limit,
skip: filteredRequest.Skip,
- sort: filteredRequest.SortFields,
+ sort: UtilsService.httpSortFieldsToMongoDB(filteredRequest.SortFields),
onlyRecordCount: filteredRequest.OnlyRecordCount
},
authorizationSitesFilter.projectFields

MODIFY
src/server/rest/v1/validator/SiteValidator.ts
src/server/rest/v1/validator/SiteValidator.ts
-import { HttpSiteOwnerRequest, HttpSiteUserAdminRequest } from '../../../../types/requests/HttpSiteRequest';
+import { HttpSiteOwnerRequest, HttpSiteUserAdminRequest, HttpSitesRequest } from '../../../../types/requests/HttpSiteRequest';
import Schema from '../../../../types/validator/Schema';
import SchemaValidator from '../../../../validator/SchemaValidator';
@@ -11,12 +11,14 @@ export default class SiteValidator extends SchemaValidator {
private siteCreate: Schema;
private siteAdmin: Schema;
private siteOwner: Schema;
+ private sitesGet: Schema;
private constructor() {
super('SiteValidator');
this.siteCreate = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/site/site-create.json`, 'utf8'));
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'));
}
public static getInstance(): SiteValidator {
@@ -37,4 +39,8 @@ export default class SiteValidator extends SchemaValidator {
public validateSiteOwnerReq(data: Record<string, unknown>): HttpSiteOwnerRequest {
return this.validate(this.siteOwner, data);
}
+
+ public validateSitesGetReq(data: Record<string, unknown>): HttpSitesRequest {
+ return this.validate(this.sitesGet, data);
+ }
}

MODIFY
src/types/requests/HttpSiteRequest.ts
src/types/requests/HttpSiteRequest.ts
@@ -16,6 +16,8 @@ export interface HttpSitesRequest extends HttpDatabaseRequest {
CompanyID: string;
SiteID: string;
ExcludeSitesOfUserID: boolean;
+ LocLongitude?: number;
+ LocLatitude?: number;
LocCoordinates?: number[];
LocMaxDistanceMeters?: number;
}

Added sites getMany validation