@@ -4,7 +4,7 @@ var express = require('express'),
4
4
Parse = require ( 'parse/node' ) . Parse ,
5
5
Schema = require ( '../Schema' ) ;
6
6
7
- import PromiseRouter from '../PromiseRouter' ;
7
+ import PromiseRouter from '../PromiseRouter' ;
8
8
import * as middleware from "../middlewares" ;
9
9
10
10
function classNameMismatchResponse ( bodyClass , pathClass ) {
@@ -14,30 +14,10 @@ function classNameMismatchResponse(bodyClass, pathClass) {
14
14
) ;
15
15
}
16
16
17
- function mongoSchemaAPIResponseFields ( schema ) {
18
- var fieldNames = Object . keys ( schema ) . filter ( key => key !== '_id' && key !== '_metadata' ) ;
19
- var response = fieldNames . reduce ( ( obj , fieldName ) => {
20
- obj [ fieldName ] = Schema . mongoFieldTypeToSchemaAPIType ( schema [ fieldName ] )
21
- return obj ;
22
- } , { } ) ;
23
- response . ACL = { type : 'ACL' } ;
24
- response . createdAt = { type : 'Date' } ;
25
- response . updatedAt = { type : 'Date' } ;
26
- response . objectId = { type : 'String' } ;
27
- return response ;
28
- }
29
-
30
- function mongoSchemaToSchemaAPIResponse ( schema ) {
31
- return {
32
- className : schema . _id ,
33
- fields : mongoSchemaAPIResponseFields ( schema ) ,
34
- } ;
35
- }
36
-
37
17
function getAllSchemas ( req ) {
38
18
return req . config . database . adaptiveCollection ( '_SCHEMA' )
39
19
. then ( collection => collection . find ( { } ) )
40
- . then ( schemas => schemas . map ( mongoSchemaToSchemaAPIResponse ) )
20
+ . then ( schemas => schemas . map ( Schema . mongoSchemaToSchemaAPIResponse ) )
41
21
. then ( schemas => ( { response : { results : schemas } } ) ) ;
42
22
}
43
23
@@ -51,7 +31,7 @@ function getOneSchema(req) {
51
31
}
52
32
return results [ 0 ] ;
53
33
} )
54
- . then ( schema => ( { response : mongoSchemaToSchemaAPIResponse ( schema ) } ) ) ;
34
+ . then ( schema => ( { response : Schema . mongoSchemaToSchemaAPIResponse ( schema ) } ) ) ;
55
35
}
56
36
57
37
function createSchema ( req ) {
@@ -68,7 +48,7 @@ function createSchema(req) {
68
48
69
49
return req . config . database . loadSchema ( )
70
50
. then ( schema => schema . addClassIfNotExists ( className , req . body . fields ) )
71
- . then ( result => ( { response : mongoSchemaToSchemaAPIResponse ( result ) } ) ) ;
51
+ . then ( result => ( { response : Schema . mongoSchemaToSchemaAPIResponse ( result ) } ) ) ;
72
52
}
73
53
74
54
function modifySchema ( req ) {
@@ -118,7 +98,7 @@ function modifySchema(req) {
118
98
if ( err ) {
119
99
reject ( err ) ;
120
100
}
121
- resolve ( { response : mongoSchemaToSchemaAPIResponse ( mongoObject . result ) } ) ;
101
+ resolve ( { response : Schema . mongoSchemaToSchemaAPIResponse ( mongoObject . result ) } ) ;
122
102
} )
123
103
} ) ) ;
124
104
} ) ;
0 commit comments