简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM