Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Feature/rcswitch api #55

Merged
merged 3 commits into from
Feb 16, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion plugins/arduino/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ define([ 'duino' ], function(duino) {
* @param {String} data.value The value to set (0 or 1)
*/
Arduino.prototype.rcswitch = function(data) {

var that = this;
this.pluginHelper.findItem(that.collection, data.id, function(err, item, collection) {
if ((!err) && (item)) {
Expand Down Expand Up @@ -219,6 +218,40 @@ define([ 'duino' ], function(duino) {
return callback(null, items);
}

/**
* API functions of the Arduino Plugin
*
* @method api
* @param {Object} req The request
* @param {Object} res The response
*/

Arduino.prototype.api = function(req, res, next) {
/*
* GET
*/
if (req.method == 'POST') {
var that = this;
var method = req.body.method;
if(method === "rcswitch") {
this.app.get('db').collection("Arduino", function(err, collection) {
collection.find({}).toArray(function(err, items) {
if (!err) {
that.beforeRender(items, function() {
res.send(200, items);
});
} else {
res.send(500, '[]');
}
});
});
} else {
next();
}
}
};


var exports = Arduino;

return exports;
Expand Down