javascriptnode.jsexpresssequelize.jsfeathersjs

Feathers js how to customize get service endpoint


So I want to attach a url to my user requests which is in another service. How to customize get request?

const { Service } = require('feathers-sequelize')

exports.Users = class Users extends Service {
  get(id, params) {
    // how to add custom data into to the get result?
    return super.get(id, params)
  }
}

Solution

  • You retrieve the value from super and return a new object:

    const { Service } = require('feathers-sequelize')
    
    exports.Users = class Users extends Service {
      async get(id, params) {
        // how to add custom data into to the get result?
        const data = await super.get(id, params)
    
        return {
          ...data,
          // when using raw: false:
          // ...data.toJSON(),
          message: 'New data here'
        }
      }
    }