1
-
2
1
/*
3
2
# CloudBoost - Core Engine that powers Bakend as a Service
4
- # (c) 2014 HackerBay, Inc.
3
+ # (c) 2014 HackerBay, Inc.
5
4
# CloudBoost may be freely distributed under the Apache 2 License
6
5
*/
7
6
8
-
9
7
var customHelper = require ( '../../helpers/custom.js' ) ;
10
8
11
9
module . exports = function ( ) {
12
10
13
-
14
- global . app . put ( '/data/:appId/:tableName' , function ( req , res ) { //save a new document into <tableName> of app
15
- if ( req . body && req . body . method == "DELETE" ) {
11
+ global . app . put ( '/data/:appId/:tableName' , function ( req , res ) { //save a new document into <tableName> of app
12
+ if ( req . body && req . body . method == "DELETE" ) {
16
13
/******************DELETE API*********************/
17
14
_deleteApi ( req , res ) ;
18
15
/******************DELETE API*********************/
19
- } else {
16
+ } else {
20
17
/******************SAVE API*********************/
21
18
console . log ( "SAVE API" ) ;
22
19
var appId = req . params . appId ;
23
20
var document = req . body . document ;
24
21
var collectionName = req . params . tableName ;
25
22
var appKey = req . body . key || req . params . key ;
26
23
var sdk = req . body . sdk || "REST" ;
27
-
28
- global . appService . isMasterKey ( appId , appKey ) . then ( function ( isMasterKey ) {
24
+
25
+ global . appService . isMasterKey ( appId , appKey ) . then ( function ( isMasterKey ) {
29
26
return global . customService . save ( appId , collectionName , document , customHelper . getAccessList ( req ) , isMasterKey ) ;
30
- } ) . then ( function ( result ) {
27
+ } ) . then ( function ( result ) {
31
28
console . log ( '+++ Save Success +++' ) ;
32
29
console . log ( result ) ;
33
30
res . status ( 200 ) . send ( result ) ;
34
- } , function ( error ) {
31
+ } , function ( error ) {
35
32
console . log ( '++++++ Save Error +++++++' ) ;
36
33
console . log ( error ) ;
37
34
res . status ( 400 ) . send ( error ) ;
38
35
} ) ;
39
36
40
- global . apiTracker . log ( appId , "Object / Save" , req . url , sdk ) ;
37
+ global . apiTracker . log ( appId , "Object / Save" , req . url , sdk ) ;
41
38
/******************SAVE API*********************/
42
39
}
43
40
} ) ;
44
-
45
-
41
+
46
42
global . app . get ( '/data/:appId/:tableName/find' , _getData ) ;
47
43
global . app . post ( '/data/:appId/:tableName/find' , _getData ) ;
48
44
@@ -54,8 +50,8 @@ module.exports = function() {
54
50
55
51
global . app . get ( '/data/:appId/:tableName/findOne' , _findOne ) ;
56
52
global . app . post ( '/data/:appId/:tableName/findOne' , _findOne ) ;
57
-
58
- global . app . delete ( '/data/:appId/:tableName' , _deleteApi ) ;
53
+
54
+ global . app . delete ( '/data/:appId/:tableName' , _deleteApi ) ;
59
55
60
56
function _deleteApi ( req , res ) { //delete a document matching the <objectId>
61
57
console . log ( "DELETE API" ) ;
@@ -65,16 +61,16 @@ module.exports = function() {
65
61
var appKey = req . body . key || req . param ( 'key' ) ;
66
62
var sdk = req . body . sdk || "REST" ;
67
63
68
- global . appService . isMasterKey ( appId , appKey ) . then ( function ( isMasterKey ) {
69
- return global . customService . delete ( appId , collectionName , document , customHelper . getAccessList ( req ) , isMasterKey ) ;
64
+ global . appService . isMasterKey ( appId , appKey ) . then ( function ( isMasterKey ) {
65
+ return global . customService . delete ( appId , collectionName , document , customHelper . getAccessList ( req ) , isMasterKey ) ;
70
66
} ) . then ( function ( result ) {
71
67
res . json ( result ) ;
72
68
} , function ( error ) {
73
69
res . status ( 400 ) . send ( error ) ;
74
70
} ) ;
75
-
76
- global . apiTracker . log ( appId , "Object / Delete" , req . url , sdk ) ;
77
-
71
+
72
+ global . apiTracker . log ( appId , "Object / Delete" , req . url , sdk ) ;
73
+
78
74
}
79
75
80
76
} ;
@@ -90,16 +86,16 @@ function _getData(req, res) { //get document(s) object based on query and variou
90
86
var skip = req . body . skip ;
91
87
var appKey = req . body . key || req . param ( 'key' ) ;
92
88
var sdk = req . body . sdk || "REST" ;
93
-
94
- global . appService . isMasterKey ( appId , appKey ) . then ( function ( isMasterKey ) {
89
+
90
+ global . appService . isMasterKey ( appId , appKey ) . then ( function ( isMasterKey ) {
95
91
return global . customService . find ( appId , collectionName , query , select , sort , limit , skip , customHelper . getAccessList ( req ) , isMasterKey ) ;
96
- } ) . then ( function ( results ) {
92
+ } ) . then ( function ( results ) {
97
93
res . json ( results ) ;
98
- } , function ( error ) {
94
+ } , function ( error ) {
99
95
res . status ( 400 ) . send ( error ) ;
100
96
} ) ;
101
-
102
- global . apiTracker . log ( appId , "Object / Find" , req . url , sdk ) ;
97
+
98
+ global . apiTracker . log ( appId , "Object / Find" , req . url , sdk ) ;
103
99
}
104
100
105
101
function _count ( req , res ) { //get document(s) object based on query and various parameters
@@ -111,16 +107,16 @@ function _count(req, res) { //get document(s) object based on query and various
111
107
var skip = req . body . skip ;
112
108
var appKey = req . body . key || req . param ( 'key' ) ;
113
109
var sdk = req . body . sdk || "REST" ;
114
-
115
- global . appService . isMasterKey ( appId , appKey ) . then ( function ( isMasterKey ) {
110
+
111
+ global . appService . isMasterKey ( appId , appKey ) . then ( function ( isMasterKey ) {
116
112
return global . customService . count ( appId , collectionName , query , limit , skip , customHelper . getAccessList ( req ) , isMasterKey ) ;
117
- } ) . then ( function ( result ) {
113
+ } ) . then ( function ( result ) {
118
114
res . json ( result ) ;
119
- } , function ( error ) {
115
+ } , function ( error ) {
120
116
res . status ( 400 ) . send ( error ) ;
121
117
} ) ;
122
-
123
- global . apiTracker . log ( appId , "Object / Count" , req . url , sdk ) ;
118
+
119
+ global . apiTracker . log ( appId , "Object / Count" , req . url , sdk ) ;
124
120
}
125
121
126
122
function _distinct ( req , res , next ) { //get document(s) object based on query and various parameters
@@ -135,16 +131,16 @@ function _distinct(req, res, next) { //get document(s) object based on query and
135
131
var skip = req . body . skip ;
136
132
var appKey = req . body . key || req . param ( 'key' ) ;
137
133
var sdk = req . body . sdk || "REST" ;
138
-
139
- global . appService . isMasterKey ( appId , appKey ) . then ( function ( isMasterKey ) {
134
+
135
+ global . appService . isMasterKey ( appId , appKey ) . then ( function ( isMasterKey ) {
140
136
return global . customService . distinct ( appId , collectionName , onKey , query , select , sort , limit , skip , customHelper . getAccessList ( req ) , isMasterKey ) ;
141
- } ) . then ( function ( results ) {
137
+ } ) . then ( function ( results ) {
142
138
res . json ( results ) ;
143
- } , function ( error ) {
139
+ } , function ( error ) {
144
140
res . status ( 400 ) . send ( error ) ;
145
141
} ) ;
146
-
147
- global . apiTracker . log ( appId , "Object / Distinct" , req . url , sdk ) ;
142
+
143
+ global . apiTracker . log ( appId , "Object / Distinct" , req . url , sdk ) ;
148
144
}
149
145
150
146
function _findOne ( req , res ) { //get a single document matching the search query
@@ -157,14 +153,14 @@ function _findOne(req, res) { //get a single document matching the search query
157
153
var skip = req . body . skip ;
158
154
var appKey = req . body . key || req . param ( 'key' ) ;
159
155
var sdk = req . body . sdk || "REST" ;
160
-
161
- global . appService . isMasterKey ( appId , appKey ) . then ( function ( isMasterKey ) {
156
+
157
+ global . appService . isMasterKey ( appId , appKey ) . then ( function ( isMasterKey ) {
162
158
return global . customService . findOne ( appId , collectionName , query , select , sort , skip , customHelper . getAccessList ( req ) , isMasterKey ) ;
163
- } ) . then ( function ( result ) {
159
+ } ) . then ( function ( result ) {
164
160
res . json ( result ) ;
165
- } , function ( error ) {
161
+ } , function ( error ) {
166
162
res . status ( 400 ) . send ( error ) ;
167
163
} ) ;
168
-
169
- global . apiTracker . log ( appId , "Object / FindOne" , req . url , sdk ) ;
164
+
165
+ global . apiTracker . log ( appId , "Object / FindOne" , req . url , sdk ) ;
170
166
}
0 commit comments