1

I try to make a custom endpoint, which adds a bonus to all employee. And retorns all the employee records, just like the get endpoint. Something like /employees/bonus

As I understand; I should make a remote method for this:

common/models/employee.js

Employee.bonus = function(cb){
  // logic comes here
  cb(null,"")
}

Employee.remoteMethod(
  'bonus',{}
)

This makes the endpoint, but how can request all the employees, to loop them through and increase their salary property?

user3568719
  • 1,036
  • 15
  • 33

1 Answers1

1

Query your Employee model, apply filter if you need, then loop through results.

Employee.find(
  filter, 
  function(err,employees) {
    if(err){
      console.log(err);
    }
    employees.forEach(
      function(employee){
         fnIncSalary(employee.salary);
        //do something with employee instance
      }
    );
  }
);

http://docs.strongloop.com/display/public/LB/Querying+data

A.Z.
  • 1,638
  • 2
  • 18
  • 27