From 0b5cfb2a6ab7797812e3387f8e1b506a1dd58e84 Mon Sep 17 00:00:00 2001 From: Drew Gross Date: Fri, 5 Feb 2016 18:36:23 -0800 Subject: [PATCH] Schemas POST fix tests --- schemas.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/schemas.js b/schemas.js index e374a127..6849a6a4 100644 --- a/schemas.js +++ b/schemas.js @@ -113,18 +113,13 @@ function createSchema(req) { }, }); } - return req.config.database.collection('_SCHEMA') - .then(coll => Schema.load(coll)) - .then(schema => schema.validateClassName(req.body.className)) - .catch(error => { - console.log(arguments); - return {response: error}; - }) - .then(newSchema => { - for (key in newSchema.data) { - } - return {response: {}}; - }); + return req.config.database.loadSchema() + .then(schema => schema.addClassIfNotExists(className, req.body.fields)) + .then(result => ({ response: mongoSchemaToSchemaAPIResponse(result) })) + .catch(error => ({ + status: 400, + response: error, + })); } router.route('GET', '/schemas', getAllSchemas);