Welcome
Login
Sign up
Home
Solutions
Forums
How can we help you today?
Enter your search term here...
Search
Login
or
Signup
to submit a new ticket
Check ticket status
Start a new topic
Discussions
Kinvey Forums
Business Logic
Share code between custom endpoints
Gilles Haiat
started a topic
almost 7 years ago
Hello
Is there a way to share code between different endpoints in order to avoid duplicating the code?
6 Comments
Oldest First
Popular
Newest First
Sorted by
Oldest First
M
Michael
said
almost 7 years ago
Yes, if you use the Business Logic CLI to manage your BL, you can upload common code to be used across endpoints and collection hooks.
http://devcenter.kinvey.com/ios/tutorials/business-logic-revisions#Addingcommoncode
Gilles Haiat
said
almost 7 years ago
Thanks for the prompt answer. I am facing another issue :
i am porting some client side code to a custom endpoint where i was linking a collection object to a user using :
mission.owner=user;
return $kinvey.DataStore.save('missions', mission, { exclude : ['owner'], relations : { owner : 'user' } });
on the custom end point i try to do this:
collectionAccess.collection('missions').save(mission, { exclude : ['owner'], relations : { owner : 'user' } });
but it was saving the entire user object inside the mission so i tried to do this:
mission.owner={"_type":"KinveyRef","_collection":"user","_id":user._id};
collectionAccess.collection('missions').save(mission);
But when i do the this, any query for the client side will not retrieve my mission based on the owner._id ...
Any idea on how to port the relation to a custom endpoint?
M
Michael
said
almost 7 years ago
Try setting the "id" property to user.id.toString().
Are you trying to resolve the reference on the client, or in the endpoint?
Gilles Haiat
said
almost 7 years ago
I m trying to set the reference in the endpoint
M
Michael
said
almost 7 years ago
Right, but where are you trying to actually view/retrieve the reference?
Gilles Haiat
said
almost 7 years ago
i m trying to query the reference client side using :
var query = new $kinvey.Query();
query.equalTo('owner._id', user._id);
return $kinvey.DataStore.find('missions', query);
using user.id.toString(), made it work ! Thanks and congrats for the awesome platform and the prompt support :)
Login
or
Signup
to post a comment
More topics in
Business Logic
How do I access query string values for GET and DELETE requests?
Basic Authentication in Business Logic
How do I cascade delete entities from related collections?
All BL failing with Violation Error
How do I send push notifications?
Whenever I try to query by _id, I get zero results
receiving SOCKETTIMEDOUT when requesting external http response
Unique Constraints on a collection column?
Need some help with grouping
Accessing Endpoint from Collection Hook
See all 342 topics
Gilles Haiat
Is there a way to share code between different endpoints in order to avoid duplicating the code?