Added user-by-id schema validation
ADD
src/assets/server/rest/v1/schemas/user/user-get-by-id.json
+{
+ "title": "Get a user by id",
+ "type": "object",
+ "definitions": {
+ "ID": {
+ "$ref": "common.json#/definitions/id"
+ }
+ },
+ "required": [
+ "ID"
+ ]
+}

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -51,7 +51,7 @@ export default class UserService {
public static async handleGetUserDefaultTagCar(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const userID = UserSecurity.filterDefaultTagCarRequestByUserID(req.query);
+ const userID = UserValidator.getInstance().validateUserGetByID(req.query).ID as string;
UtilsService.assertIdIsProvided(action, userID, MODULE_NAME, 'handleGetUserDefaultTagCar', req.user);
// Check and Get User
const user = await UtilsService.checkAndGetUserAuthorization(

MODIFY
src/server/rest/v1/validator/UserValidator.ts
src/server/rest/v1/validator/UserValidator.ts
import User, { ImportedUser } from '../../../../types/User';
+import HttpByIDRequest from '../../../../types/requests/HttpByIDRequest';
import { HttpUserAssignSitesRequest } from '../../../../types/requests/HttpUserRequest';
import Schema from '../../../../types/validator/Schema';
import SchemaValidator from './SchemaValidator';
-import UserToken from '../../../../types/UserToken';
import fs from 'fs';
import global from '../../../../types/GlobalType';
@@ -12,12 +12,14 @@ export default class UserValidator extends SchemaValidator {
private importedUserCreation: Schema;
private userCreate: Schema;
private userAssignSites: Schema;
+ private userGetByID: Schema;
private constructor() {
super('UserValidator');
this.importedUserCreation = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/user/imported-user-create-req.json`, 'utf8'));
this.userCreate = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/user/user-create.json`, 'utf8'));
this.userAssignSites = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/user/user-assign-sites.json`, 'utf8'));
+ this.userGetByID = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/user/user-get-by-id.json`, 'utf8'));
}
public static getInstance(): UserValidator {
@@ -41,4 +43,9 @@ export default class UserValidator extends SchemaValidator {
this.validate(this.userAssignSites, data);
return data;
}
+
+ validateUserGetByID(data: any): HttpByIDRequest {
+ this.validate(this.userGetByID, data);
+ return data;
+ }
}

Added user-by-id schema validation