Progres towards moving mongo logic into its adapter

This commit is contained in:
Drew
2016-04-05 21:16:39 -07:00
parent cbbd66964a
commit 91ace4e718
9 changed files with 387 additions and 271 deletions

View File

@@ -17,7 +17,6 @@ function classNameMismatchResponse(bodyClass, pathClass) {
function getAllSchemas(req) {
return req.config.database.schemaCollection()
.then(collection => collection.getAllSchemas())
.then(schemas => schemas.map(Schema.mongoSchemaToSchemaAPIResponse))
.then(schemas => ({ response: { results: schemas } }));
}
@@ -25,11 +24,13 @@ function getOneSchema(req) {
const className = req.params.className;
return req.config.database.schemaCollection()
.then(collection => collection.findSchema(className))
.then(mongoSchema => {
if (!mongoSchema) {
.then(schema => ({ response: schema }))
.catch(error => {
if (error === undefined) {
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, `Class ${className} does not exist.`);
} else {
throw new Parse.Error(Parse.Error.INTERNAL_SERVER_ERROR, 'Database adapter error.');
}
return { response: Schema.mongoSchemaToSchemaAPIResponse(mongoSchema) };
});
}
@@ -47,7 +48,7 @@ function createSchema(req) {
return req.config.database.loadSchema()
.then(schema => schema.addClassIfNotExists(className, req.body.fields, req.body.classLevelPermissions))
.then(result => ({ response: Schema.mongoSchemaToSchemaAPIResponse(result) }));
.then(schema => ({ response: schema }));
}
function modifySchema(req) {
@@ -55,8 +56,8 @@ function modifySchema(req) {
return classNameMismatchResponse(req.body.className, req.params.className);
}
var submittedFields = req.body.fields || {};
var className = req.params.className;
let submittedFields = req.body.fields || {};
let className = req.params.className;
return req.config.database.loadSchema()
.then(schema => {