Skip to content

Instantly share code, notes, and snippets.

@josx
Last active August 29, 2015 14:27
Show Gist options
  • Save josx/bf6f2aa44e8cf95f9651 to your computer and use it in GitHub Desktop.
Save josx/bf6f2aa44e8cf95f9651 to your computer and use it in GitHub Desktop.
Simple remote method
'use strict';
module.exports = function(Coupon) {
Coupon.isGrabbedASIN = isGrabbedASIN;
function isGrabbedASIN(productId, userId, cb) {
Coupon.findOne(
{ where:
{
and: [
{ productId: productId },
{ isGrabbed: true },
{ userId: userId }
]
}
},
function(err, coupon) {
if(err || !coupon) {
cb(null, false);
}
cb(null, true);
});
}
Coupon.remoteMethod('isGrabbedASIN', {
isStatic: true,
accepts: [
{ arg: 'productId', type: 'string' },
{ arg: 'userId', type: 'string' }
],
returns:{ arg: 'isGrabbed', type: 'boolean' }
});
};
@josx
Copy link
Author

josx commented Aug 17, 2015

Using

    "loopback": "2.12.1",
    "loopback-connector-mongodb": "1.7.0",
    "loopback-datasource-juggler": "2.16.0",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment