Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overriding knex-adapter default post-create behaviour #207

Closed
naorzr opened this issue Jun 16, 2019 · 4 comments
Closed

Overriding knex-adapter default post-create behaviour #207

naorzr opened this issue Jun 16, 2019 · 4 comments

Comments

@naorzr
Copy link

naorzr commented Jun 16, 2019

Hey there,

After inserting an item using the 'create' service method knex-adapter automatically gets the item inserted from the table.
Is there a way to override this 'get' behaviour?
I for example have a special object i return to the user, and not the database fields directly.

Ultimately it would be best if it could use the service get method, instead of a query get.

@daffl
Copy link
Member

daffl commented Jun 16, 2019

You can extend the adapter and return the get result.

const { Service } = require( 'feathers-knex');

class MyService extends Service {
  async create(data, params) {
    const created = await super.create(data, params);

    return this.get(created.id, params);
  }
}

@naorzr
Copy link
Author

naorzr commented Jun 17, 2019

Thanks but this aint working, and it's impossible to debug, I'm only recieving

{
    "name": "GeneralError",
    "message": "Not Acceptable",
    "code": 500,
    "className": "general-error",
    "data": {},
    "errors": {}
}

even though this.get(created.id,params); returns a valid response.
I've even tried this , but it's still fail with the same ambiguous error

const { Service } = require( 'feathers-knex');

class MyService extends Service {
  async create(data, params) {
    return Promise.resolve({test: 'test'})
  }
}

@daffl
Copy link
Member

daffl commented Jun 17, 2019

I can't reproduce this. A Not Acceptable error usually happens when you don't set a Content-Type header for a POST request.

@naorzr
Copy link
Author

naorzr commented Jun 17, 2019

Content-Type was set, but it was an additional header Accept which was set(a leftover from a duplicate in postman) that caused it.
Thanks for all the help, much appreciated!

@naorzr naorzr closed this as completed Jun 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants