Added update-user schema
ADD
src/assets/server/rest/v1/schemas/user/user-update.json
+{
+ "title": "Update a User",
+ "type": "object",
+ "definitions": {
+ "id": {
+ "$ref": "user.json#/definitions/id"
+ },
+ "name": {
+ "$ref": "user.json#/definitions/name"
+ },
+ "firstName": {
+ "$ref": "user.json#/definitions/firstName"
+ },
+ "email": {
+ "$ref": "user.json#/definitions/email"
+ },
+ "costCenter": {
+ "$ref": "user.json#/definitions/costCenter"
+ },
+ "iNumber": {
+ "$ref": "user.json#/definitions/iNumber"
+ },
+ "image": {
+ "$ref": "user.json#/definitions/image"
+ },
+ "mobile": {
+ "$ref": "user.json#/definitions/mobile"
+ },
+ "locale": {
+ "$ref": "user.json#/definitions/locale"
+ },
+ "address": {
+ "$ref": "user.json#/definitions/address"
+ },
+ "passwords": {
+ "$ref": "user.json#/definitions/passwords"
+ },
+ "phone": {
+ "$ref": "user.json#/definitions/phone"
+ },
+ "issuer": {
+ "$ref": "user.json#/definitions/issuer"
+ },
+ "notificationsActive": {
+ "$ref": "user.json#/definitions/notificationsActive"
+ },
+ "notifications": {
+ "$ref": "user.json#/definitions/notifications"
+ },
+ "status": {
+ "$ref": "user.json#/definitions/status"
+ },
+ "plateID": {
+ "$ref": "user.json#/definitions/plateID"
+ },
+ "role": {
+ "$ref": "user.json#/definitions/role"
+ }
+ },
+ "required": [
+ "id",
+ "name",
+ "email"
+ ]
+}

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -163,7 +163,7 @@ export default class UserService {
public static async handleUpdateUser(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
let statusHasChanged = false;
// Filter
- const filteredRequest = UserSecurity.filterUserUpdateRequest({ ...req.params, ...req.body }, req.user);
+ const filteredRequest = UserValidator.getInstance().validateUserUpdate({ ...req.params, ...req.body });
// Check and Get User
let user = await UtilsService.checkAndGetUserAuthorization(
req.tenant, req.user, filteredRequest.id, Action.UPDATE, action);

MODIFY
src/server/rest/v1/validator/UserValidator.ts
src/server/rest/v1/validator/UserValidator.ts
@@ -11,12 +11,14 @@ export default class UserValidator extends SchemaValidator {
private importedUserCreation: Schema;
private userCreate: Schema;
private userGetSites: Schema;
+ private userUpdate: 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.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'));
}
public static getInstance(): UserValidator {
@@ -40,4 +42,9 @@ export default class UserValidator extends SchemaValidator {
this.validate(this.userGetSites, data);
return data;
}
+
+ validateUserUpdate(data: any): Partial<User> {
+ this.validate(this.userUpdate, data);
+ return data;
+ }
}

MODIFY
test/api/UserTest.ts
test/api/UserTest.ts
@@ -166,7 +166,7 @@ describe('User', function() {
// Update
await testData.userService.updateEntity(
testData.userService.userApi,
- testData.newUser
+ { ...testData.newUser, passwords: { password: testData.newUser.password } }
);
});

Added update-user schema