Giter Site home page Giter Site logo

workshop-band-app's Issues

Remote method for album?

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) {
    var numFields = 5;
    var fieldsComplete = 1; // assume title is complete

    if (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'},
  });
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.