Search code examples
node.jsloopback

particular property will update only the admin is login in loopback nodejs


  "properties": {

    "approvedDate": {
      "type": "date"
    },
    "approvedBy": {
      "type": "string"
    },
    "time": {
      "type": "string"
    },
    "status": {
      "type": "string"
    },
    "reason": {
      "type": "string"
    },
    "comments": {
      "type": "string"
    }

  }

approvedDate and approvedBy only admin can update , others users can't update. how can i do this. please help.

thanks in advance


Solution

  • You can add validations in loopback models . Take a look at the below link for validations https://loopback.io/doc/en/lb2/Validating-model-data.html

    In your case this can be handled in 2 different cases.

    1. Specify the validation in before save method of your model

      If the user have no admin rights then pass an Error in next(); https://loopback.io/doc/en/lb2/Operation-hooks.html

    2. Use ACL and block all other access. Write a remote method to create data, in which you can check the credentials

      https://loopback.io/doc/en/lb2/Controlling-data-access.html

    Hope this helped.