Skip to content

Custom actions support #27

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

Open
Tronix117 opened this issue Sep 11, 2017 · 3 comments
Open

Custom actions support #27

Tronix117 opened this issue Sep 11, 2017 · 3 comments
Labels
Milestone

Comments

@Tronix117
Copy link
Collaborator

Add support for deserialize/serialize for custom actions:

store.defineMapper('school', {
  endpoint: 'schools',
});

addAction('createTeacherReport', {
  pathname: 'teachers',
  method: 'POST'
})(store.getMapper('school'));

store.getMapper('school').createTeacherReport(1234, {
  data: { someAttribute: 123 }
}).then(function (response) {
  console.log('response', response.data);
});

See if in the then there should be response or directly data, in which case we can use raw: true to get the response.

@Tronix117 Tronix117 added this to the v1.1 milestone Sep 11, 2017
@phortx
Copy link

phortx commented Nov 22, 2017

Are custom actions possible currently? If yes, how? If not, how can I help?

@Tronix117
Copy link
Collaborator Author

Custom actions are working, but the adapter is not plugged into those, so it means no serialization/deserialization from/to jsonapi.

I didn't put much effort into it, because in a way custom actions are not standard calls specified by JSONApi, so the format can be anything.

In any case, we should be able to give a configuration option to the addAction to say, we want it to go through the serialization/deserialization.

I will not have time to implement before january, so if need it, you can still submit a PR.


There is a workaround though:

If you want to call a GET on /something/page/current and expect one result, do

store.getMapper('xxx').find('current', {
  endpoint: 'something/page'
})

Will work just fine, and goes through jsonapi serialization deserialization

@phortx
Copy link

phortx commented Nov 22, 2017

Sounds good. I'd love to send you a PR but I don't think I'm qualified to do a good contribution on this project due to the lack of any deeper knowledge of the adapter, so I won't to probably :)

Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants