You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I haven't actually tried it yet. . . trying to come up with something that fits the context & makes sense. I find the static "CoffeeShop.status" example confusing, as I think most people would assume as I did: that the method checks the status of a particular coffeeshop (instance), whereas in fact it just checks whether the current time is between a hardcoded range.
Instance methods require a bit more configuration (maybe?) but they are much easier to understand the purpose of IMO.
/albums/123/complete 👉 75
Anyway here it is! Alternately it could just be a "say Hi" type method, but I think for the slides if we're going with "band app" from start to finish it would be confusing to introduce a new, different model while introducing model features.
I am wondering if it wouldn't be easier (at least in the slides) to push remote methods further back, after attendees can see the basic scaffolded stuff in action, see relationships, see how far you can get without customizing.
'use strict';module.exports=function(Album){/** * reports how complete an album record is based on not-empty fields * returns number between 0 and 100 * @param {Function(Error, number)} callback */Album.prototype.percentComplete=function(callback){varnumFields=5;varfieldsComplete=1;// assume title is completeif(this.year)fieldsComplete++;if(this['record-label'])fieldsComplete++;if(this.artwork)fieldsComplete++;if(this.tracks.length&&this.tracks.length>0)fieldsComplete++;callback(null,Math.round((fieldsComplete/numFields)*100));};Album.remoteMethod('percentComplete',{isStatic: false,description: 'Get % of album fields completed',http: {path: '/complete',verb: 'get',status: 200},returns: {root: true,type: 'number'},});};
The text was updated successfully, but these errors were encountered:
One problem with this is that it does not fit on a slide :) I just can't think of anything that relates to an album besides simply-- oh maybe a remote toString would be a reasonable example...
I haven't actually tried it yet. . . trying to come up with something that fits the context & makes sense. I find the static "CoffeeShop.status" example confusing, as I think most people would assume as I did: that the method checks the status of a particular coffeeshop (instance), whereas in fact it just checks whether the current time is between a hardcoded range.
Instance methods require a bit more configuration (maybe?) but they are much easier to understand the purpose of IMO.
/albums/123/complete
👉75
Anyway here it is! Alternately it could just be a "say Hi" type method, but I think for the slides if we're going with "band app" from start to finish it would be confusing to introduce a new, different model while introducing model features.
I am wondering if it wouldn't be easier (at least in the slides) to push remote methods further back, after attendees can see the basic scaffolded stuff in action, see relationships, see how far you can get without customizing.
The text was updated successfully, but these errors were encountered: