Added user-update-mobile-token schema
ADD
src/assets/server/rest/v1/schemas/user/user-update-mobile-token.json
+{
+ "title": "Update User mobile token",
+ "type": "object",
+ "definitions": {
+ "id": {
+ "$ref": "user.json#/definitions/id"
+ },
+ "mobileToken": {
+ "type": "string",
+ "sanitize": "mongo"
+ },
+ "mobileOS": {
+ "type": "string",
+ "sanitize": "mongo"
+ }
+ },
+ "required": [
+ "id",
+ "mobileToken"
+ ]
+}

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -259,7 +259,7 @@ export default class UserService {
public static async handleUpdateUserMobileToken(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = UserSecurity.filterUserUpdateMobileTokenRequest({ ...req.params, ...req.body });
+ const filteredRequest = UserValidator.getInstance().validateUserUpdateMobileToken({ ...req.params, ...req.body });
// Check Mandatory fields
if (!filteredRequest.mobileToken) {
throw new AppError({

MODIFY
src/server/rest/v1/validator/UserValidator.ts
src/server/rest/v1/validator/UserValidator.ts
+import { HttpUserMobileTokenRequest, HttpUserSitesRequest } from '../../../../types/requests/HttpUserRequest';
import User, { ImportedUser } from '../../../../types/User';
-import { HttpUserSitesRequest } from '../../../../types/requests/HttpUserRequest';
import Schema from '../../../../types/validator/Schema';
import SchemaValidator from './SchemaValidator';
import fs from 'fs';
@@ -12,6 +12,7 @@ export default class UserValidator extends SchemaValidator {
private userCreate: Schema;
private userGetSites: Schema;
private userUpdate: Schema;
+ private userUpdateMobileToken: Schema;
private constructor() {
super('UserValidator');
@@ -19,6 +20,7 @@ export default class UserValidator extends SchemaValidator {
this.userCreate = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/user/user-create.json`, 'utf8'));
this.userGetSites = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/user/user-get-sites.json`, 'utf8'));
this.userUpdate = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/user/user-update.json`, 'utf8'));
+ this.userUpdateMobileToken = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/user/user-update-mobile-token.json`, 'utf8'));
}
public static getInstance(): UserValidator {
@@ -47,4 +49,9 @@ export default class UserValidator extends SchemaValidator {
this.validate(this.userUpdate, data);
return data;
}
+
+ validateUserUpdateMobileToken(data: any): HttpUserMobileTokenRequest {
+ this.validate(this.userUpdateMobileToken, data);
+ return data;
+ }
}

Added user-update-mobile-token schema