From 0a4d3acb4ce37b29359e45e1564f021e7b3c37b6 Mon Sep 17 00:00:00 2001 From: Simon Ho Date: Tue, 25 Nov 2014 17:10:44 -0800 Subject: [PATCH] Extend your API --- common/models/coffee-shop.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/common/models/coffee-shop.js b/common/models/coffee-shop.js index 5812a03..1e0b510 100644 --- a/common/models/coffee-shop.js +++ b/common/models/coffee-shop.js @@ -1,3 +1,26 @@ module.exports = function(CoffeeShop) { + CoffeeShop.status = function(cb) { + var currentDate = new Date(); + var currentHour = currentDate.getHours(); + var OPEN_HOUR = 6; + var CLOSE_HOUR = 20; + console.log('Current hour is ' + currentHour); + + var response; + if (currentHour > OPEN_HOUR && currentHour < CLOSE_HOUR) { + response = 'We are open for business.'; + } else { + response = 'Sorry, we are closed. Open daily from 6am to 8pm.'; + } + cb(null, response); + }; + + CoffeeShop.remoteMethod( + 'status', + { + http: {path: '/status', verb: 'get'}, + returns: {arg: 'status', type: 'string'} + } + ); };