@@ -6,62 +6,62 @@ var express = require('express'),
6
6
var router = new PromiseRouter ( ) ;
7
7
8
8
function mongoFieldTypeToApiResponseType ( type ) {
9
- if ( type [ 0 ] === '*' ) {
10
- return {
11
- type : 'Pointer' ,
12
- targetClass : type . slice ( 1 ) ,
13
- } ;
14
- }
15
- if ( type . startsWith ( 'relation<' ) ) {
16
- return {
17
- type : 'Relation' ,
18
- targetClass : type . slice ( 'relation<' . length , type . length - 1 ) ,
19
- } ;
20
- }
21
- switch ( type ) {
22
- case 'number' : return { type : 'Number' } ;
23
- case 'string' : return { type : 'String' } ;
24
- case 'boolean' : return { type : 'Boolean' } ;
25
- case 'date' : return { type : 'Date' } ;
26
- case 'object' : return { type : 'Object' } ;
27
- case 'array' : return { type : 'Array' } ;
28
- case 'geopoint' : return { type : 'GeoPoint' } ;
29
- case 'file' : return { type : 'File' } ;
30
- }
9
+ if ( type [ 0 ] === '*' ) {
10
+ return {
11
+ type : 'Pointer' ,
12
+ targetClass : type . slice ( 1 ) ,
13
+ } ;
14
+ }
15
+ if ( type . startsWith ( 'relation<' ) ) {
16
+ return {
17
+ type : 'Relation' ,
18
+ targetClass : type . slice ( 'relation<' . length , type . length - 1 ) ,
19
+ } ;
20
+ }
21
+ switch ( type ) {
22
+ case 'number' : return { type : 'Number' } ;
23
+ case 'string' : return { type : 'String' } ;
24
+ case 'boolean' : return { type : 'Boolean' } ;
25
+ case 'date' : return { type : 'Date' } ;
26
+ case 'object' : return { type : 'Object' } ;
27
+ case 'array' : return { type : 'Array' } ;
28
+ case 'geopoint' : return { type : 'GeoPoint' } ;
29
+ case 'file' : return { type : 'File' } ;
30
+ }
31
31
}
32
32
33
33
function mongoSchemaAPIResponseFields ( schema ) {
34
- fieldNames = Object . keys ( schema ) . filter ( key => key !== '_id' ) ;
35
- response = { } ;
36
- fieldNames . forEach ( fieldName => {
37
- response [ fieldName ] = mongoFieldTypeToApiResponseType ( schema [ fieldName ] ) ;
38
- } ) ;
39
- response . ACL = { type : 'ACL' } ;
40
- response . createdAt = { type : 'Date' } ;
41
- response . updatedAt = { type : 'Date' } ;
42
- response . objectId = { type : 'String' } ;
43
- return response ;
34
+ fieldNames = Object . keys ( schema ) . filter ( key => key !== '_id' ) ;
35
+ response = { } ;
36
+ fieldNames . forEach ( fieldName => {
37
+ response [ fieldName ] = mongoFieldTypeToApiResponseType ( schema [ fieldName ] ) ;
38
+ } ) ;
39
+ response . ACL = { type : 'ACL' } ;
40
+ response . createdAt = { type : 'Date' } ;
41
+ response . updatedAt = { type : 'Date' } ;
42
+ response . objectId = { type : 'String' } ;
43
+ return response ;
44
44
}
45
45
46
46
function mongoSchemaToSchemaAPIResponse ( schema ) {
47
- return {
48
- className : schema . _id ,
49
- fields : mongoSchemaAPIResponseFields ( schema ) ,
50
- } ;
47
+ return {
48
+ className : schema . _id ,
49
+ fields : mongoSchemaAPIResponseFields ( schema ) ,
50
+ } ;
51
51
}
52
52
53
53
function getAllSchemas ( req ) {
54
- if ( ! req . auth . isMaster ) {
55
- return Promise . resolve ( {
56
- status : 401 ,
57
- response : { error : 'unauthorized' } ,
58
- } ) ;
59
- }
60
- return req . config . database . collection ( '_SCHEMA' )
61
- . then ( coll => coll . find ( { } ) . toArray ( ) )
62
- . then ( schemas => ( { response : {
63
- results : schemas . map ( mongoSchemaToSchemaAPIResponse )
64
- } } ) ) ;
54
+ if ( ! req . auth . isMaster ) {
55
+ return Promise . resolve ( {
56
+ status : 401 ,
57
+ response : { error : 'unauthorized' } ,
58
+ } ) ;
59
+ }
60
+ return req . config . database . collection ( '_SCHEMA' )
61
+ . then ( coll => coll . find ( { } ) . toArray ( ) )
62
+ . then ( schemas => ( { response : {
63
+ results : schemas . map ( mongoSchemaToSchemaAPIResponse )
64
+ } } ) ) ;
65
65
}
66
66
67
67
router . route ( 'GET' , '/schemas' , getAllSchemas ) ;
0 commit comments