Skip to content

Commit

Permalink
Merge pull request #205 from CloudBoost/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
shubhamqweasd authored Jun 27, 2017
2 parents 6783a23 + c615cb8 commit 5e2f5a7
Show file tree
Hide file tree
Showing 7 changed files with 302 additions and 181 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Build Status](https://travis-ci.org/CloudBoost/cloudboost.svg?branch=master)](https://travis-ci.org/CloudBoost/cloudboost)
[![OpenCollective](https://opencollective.com/cloudboost/backers/badge.svg)](#backers)

CloudBoost is the Complete NoSQL Database Service for your app. **Think of CloudBoost as Parse + Firebase + Algolia + Iron.io all combined into one** :
CloudBoost is the complete serverless platform for your app. **Think of CloudBoost as Parse + Firebase + Algolia + Iron.io all combined into one** :
- Data-Storage / JSON Storage / BLOB Storage
- 100% data ownership
- Realtime
Expand Down
86 changes: 41 additions & 45 deletions api/tables/CloudObjects.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,44 @@

/*
# CloudBoost - Core Engine that powers Bakend as a Service
# (c) 2014 HackerBay, Inc.
# (c) 2014 HackerBay, Inc.
# CloudBoost may be freely distributed under the Apache 2 License
*/


var customHelper = require('../../helpers/custom.js');

module.exports = function() {


global.app.put('/data/:appId/:tableName', function (req, res) { //save a new document into <tableName> of app
if(req.body && req.body.method=="DELETE"){
global.app.put('/data/:appId/:tableName', function(req, res) { //save a new document into <tableName> of app
if (req.body && req.body.method == "DELETE") {
/******************DELETE API*********************/
_deleteApi(req, res);
/******************DELETE API*********************/
}else{
} else {
/******************SAVE API*********************/
console.log("SAVE API");
var appId = req.params.appId;
var document = req.body.document;
var collectionName = req.params.tableName;
var appKey = req.body.key || req.params.key;
var sdk = req.body.sdk || "REST";
global.appService.isMasterKey(appId, appKey).then(function (isMasterKey) {

global.appService.isMasterKey(appId, appKey).then(function(isMasterKey) {
return global.customService.save(appId, collectionName, document, customHelper.getAccessList(req), isMasterKey);
}).then(function (result) {
}).then(function(result) {
console.log('+++ Save Success +++');
console.log(result);
res.status(200).send(result);
}, function (error) {
}, function(error) {
console.log('++++++ Save Error +++++++');
console.log(error);
res.status(400).send(error);
});

global.apiTracker.log(appId,"Object / Save", req.url,sdk);
global.apiTracker.log(appId, "Object / Save", req.url, sdk);
/******************SAVE API*********************/
}
});



global.app.get('/data/:appId/:tableName/find', _getData);
global.app.post('/data/:appId/:tableName/find', _getData);

Expand All @@ -54,8 +50,8 @@ module.exports = function() {

global.app.get('/data/:appId/:tableName/findOne', _findOne);
global.app.post('/data/:appId/:tableName/findOne', _findOne);
global.app.delete('/data/:appId/:tableName', _deleteApi);

global.app.delete('/data/:appId/:tableName', _deleteApi);

function _deleteApi(req, res) { //delete a document matching the <objectId>
console.log("DELETE API");
Expand All @@ -65,16 +61,16 @@ module.exports = function() {
var appKey = req.body.key || req.param('key');
var sdk = req.body.sdk || "REST";

global.appService.isMasterKey(appId,appKey).then(function(isMasterKey){
return global.customService.delete(appId, collectionName, document, customHelper.getAccessList(req),isMasterKey);
global.appService.isMasterKey(appId, appKey).then(function(isMasterKey) {
return global.customService.delete(appId, collectionName, document, customHelper.getAccessList(req), isMasterKey);
}).then(function(result) {
res.json(result);
}, function(error) {
res.status(400).send(error);
});
global.apiTracker.log(appId,"Object / Delete", req.url,sdk);

global.apiTracker.log(appId, "Object / Delete", req.url, sdk);

}

};
Expand All @@ -90,16 +86,16 @@ function _getData(req, res) { //get document(s) object based on query and variou
var skip = req.body.skip;
var appKey = req.body.key || req.param('key');
var sdk = req.body.sdk || "REST";
global.appService.isMasterKey(appId, appKey).then(function (isMasterKey) {

global.appService.isMasterKey(appId, appKey).then(function(isMasterKey) {
return global.customService.find(appId, collectionName, query, select, sort, limit, skip, customHelper.getAccessList(req), isMasterKey);
}).then(function (results) {
}).then(function(results) {
res.json(results);
}, function (error) {
}, function(error) {
res.status(400).send(error);
});
global.apiTracker.log(appId,"Object / Find", req.url,sdk);

global.apiTracker.log(appId, "Object / Find", req.url, sdk);
}

function _count(req, res) { //get document(s) object based on query and various parameters
Expand All @@ -111,16 +107,16 @@ function _count(req, res) { //get document(s) object based on query and various
var skip = req.body.skip;
var appKey = req.body.key || req.param('key');
var sdk = req.body.sdk || "REST";
global.appService.isMasterKey(appId, appKey).then(function (isMasterKey) {

global.appService.isMasterKey(appId, appKey).then(function(isMasterKey) {
return global.customService.count(appId, collectionName, query, limit, skip, customHelper.getAccessList(req), isMasterKey);
}).then(function (result) {
}).then(function(result) {
res.json(result);
}, function (error) {
}, function(error) {
res.status(400).send(error);
});
global.apiTracker.log(appId,"Object / Count", req.url,sdk);

global.apiTracker.log(appId, "Object / Count", req.url, sdk);
}

function _distinct(req, res, next) { //get document(s) object based on query and various parameters
Expand All @@ -135,16 +131,16 @@ function _distinct(req, res, next) { //get document(s) object based on query and
var skip = req.body.skip;
var appKey = req.body.key || req.param('key');
var sdk = req.body.sdk || "REST";
global.appService.isMasterKey(appId, appKey).then(function (isMasterKey) {

global.appService.isMasterKey(appId, appKey).then(function(isMasterKey) {
return global.customService.distinct(appId, collectionName, onKey, query, select, sort, limit, skip, customHelper.getAccessList(req), isMasterKey);
}).then(function (results) {
}).then(function(results) {
res.json(results);
}, function (error) {
}, function(error) {
res.status(400).send(error);
});
global.apiTracker.log(appId,"Object / Distinct", req.url,sdk);

global.apiTracker.log(appId, "Object / Distinct", req.url, sdk);
}

function _findOne(req, res) { //get a single document matching the search query
Expand All @@ -157,14 +153,14 @@ function _findOne(req, res) { //get a single document matching the search query
var skip = req.body.skip;
var appKey = req.body.key || req.param('key');
var sdk = req.body.sdk || "REST";
global.appService.isMasterKey(appId, appKey).then(function (isMasterKey) {

global.appService.isMasterKey(appId, appKey).then(function(isMasterKey) {
return global.customService.findOne(appId, collectionName, query, select, sort, skip, customHelper.getAccessList(req), isMasterKey);
}).then(function (result) {
}).then(function(result) {
res.json(result);
}, function (error) {
}, function(error) {
res.status(400).send(error);
});
global.apiTracker.log(appId,"Object / FindOne", req.url,sdk);

global.apiTracker.log(appId, "Object / FindOne", req.url, sdk);
}
15 changes: 9 additions & 6 deletions database-connect/realTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ module.exports = function(io) {

});

g.sendObjectNotification = function(appId, document, eventType) {
g.sendObjectNotification = function(appId, document, eventType, isMasterKey) {
//pass masterkey to access events as default ACL for event R/W is set to false
try {
//event type can be created, updated, deleted.
if (document && document._tableName) {
Expand All @@ -171,13 +172,13 @@ module.exports = function(io) {
if (typeof sockets === "object") {
for (var key in sockets) {
if (sockets[key]) {
promises.push(_sendNotification(appId, document, sockets[key], eventType));
promises.push(_sendNotification(appId, document, sockets[key], eventType, isMasterKey));
}
}
} else {
for (var i = 0; i < sockets.length; i++) {
var socket = sockets[i];
promises.push(_sendNotification(appId, document, socket, eventType));
promises.push(_sendNotification(appId, document, socket, eventType, isMasterKey));
}
}

Expand All @@ -202,14 +203,15 @@ module.exports = function(io) {
/**
*/

function _sendNotification(appId, document, socket, eventType) {
function _sendNotification(appId, document, socket, eventType, isMasterKey) {
//pass masterkey to access events as default ACL for event R/W is set to false
var deferred = global.q.defer();
try {
global.socketSessionHelper.getSession(socket.id, function(err, session) {
if (err) {
deferred.reject();
}
if (!session || global.aclHelper.isAllowedReadAccess(session.userId, session.roles, document.ACL)) {
if (!session || global.aclHelper.isAllowedReadAccess(session.userId, session.roles, document.ACL) || isMasterKey) {
global.socketQueryHelper.getData(socket.id, eventType, function(err, socketData) {
var socketQueryValidate = true;
if (socketData && socketData.query)
Expand All @@ -219,8 +221,9 @@ function _sendNotification(appId, document, socket, eventType) {
socketData = {
timestamp: ''
};
console.log(appId.toLowerCase() + 'table' + document._tableName.toLowerCase() + eventType.toLowerCase() + socketData.timestamp)
socket.emit(appId.toLowerCase() + 'table' + document._tableName.toLowerCase() + eventType.toLowerCase() + socketData.timestamp, JSON.stringify(document));
console.log("Socket Emitteddddddddddddddddddddddddddddddddddddd.", document);
console.log("Socket Emited.", document);
} else {
console.log('Socket Query doesn\'t satsfies the current document');
}
Expand Down
7 changes: 7 additions & 0 deletions databases/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ module.exports = function() {
if (!sort) {
sort = {};
}
//default sort added
/*
without sort if limit and skip are used, the records are returned out of order. To solve this default sort in ascending order of 'createdAt' is added
*/

if (!sort['createdAt'])
sort['createdAt'] = 1

if (!limit || limit === -1) {
limit = 20;
Expand Down
Loading

0 comments on commit 5e2f5a7

Please sign in to comment.