File tree 2 files changed +33
-0
lines changed 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,7 @@ function ParseServer(args) {
111
111
router . merge ( require ( './push' ) ) ;
112
112
router . merge ( require ( './installations' ) ) ;
113
113
router . merge ( require ( './functions' ) ) ;
114
+ router . merge ( require ( './schemas' ) ) ;
114
115
115
116
batch . mountOnto ( router ) ;
116
117
Original file line number Diff line number Diff line change
1
+ // schemas.js
2
+
3
+ var express = require ( 'express' ) ,
4
+ PromiseRouter = require ( './PromiseRouter' ) ;
5
+
6
+ var router = new PromiseRouter ( ) ;
7
+
8
+ function mongoSchemaToSchemaAPIResponse ( schema ) {
9
+ fieldNames = Object . keys ( schema ) . filter ( key => key !== '_id' ) ;
10
+ return {
11
+ className : schema . _id ,
12
+ fields : fieldNames . map ( name => {
13
+ result = { } ;
14
+ result [ name ] = {
15
+ type : schema [ name ] ,
16
+ } ;
17
+ return result ;
18
+ } ) ,
19
+ } ;
20
+ }
21
+
22
+ function getAllSchemas ( req ) {
23
+ return req . config . database . collection ( '_SCHEMA' )
24
+ . then ( coll => coll . find ( { } ) . toArray ( ) )
25
+ . then ( schemas => ( { response : {
26
+ results : schemas . map ( mongoSchemaToSchemaAPIResponse )
27
+ } } ) ) ;
28
+ }
29
+
30
+ router . route ( 'GET' , '/schemas' , getAllSchemas ) ;
31
+
32
+ module . exports = router ;
You can’t perform that action at this time.
0 commit comments