File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ // global_config.js
2+
3+ var Parse = require ( 'parse/node' ) . Parse ,
4+ PromiseRouter = require ( './PromiseRouter' ) ,
5+ rest = require ( './rest' ) ;
6+
7+ var router = new PromiseRouter ( ) ;
8+
9+ // Returns a promise for a {response} object.
10+ function handleUpdateGlobalConfig ( req ) {
11+ return rest . update ( req . config , req . auth ,
12+ '_GlobalConfig' , 1 , req . body )
13+ . then ( ( response ) => {
14+ return { response : response } ;
15+ } ) ;
16+ }
17+
18+ // Returns a promise for a {response} object.
19+ function handleGetGlobalConfig ( req ) {
20+ return rest . find ( req . config , req . auth , '_GlobalConfig' , 1 )
21+ . then ( ( response ) => {
22+ if ( ! response . results || response . results . length == 0 ) {
23+ throw new Parse . Error ( Parse . Error . OBJECT_NOT_FOUND ,
24+ 'Object not found.' ) ;
25+ } else {
26+ // only return 'params' attribute of response
27+ return { response : { params : response . results [ 0 ] . params } } ;
28+ }
29+ } ) ;
30+ }
31+
32+ router . route ( 'GET' , '/config' , handleGetGlobalConfig ) ;
33+ router . route ( 'POST' , '/config' , handleUpdateGlobalConfig ) ;
34+
35+ module . exports = router ;
You can’t perform that action at this time.
0 commit comments