Lelouch
Lelouch

Reputation: 970

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)
  }
}

Upvotes: 0

Views: 413

Answers (1)

Daff
Daff

Reputation: 44215

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'
    }
  }
}

Upvotes: 1

Related Questions