Schema format cleanup

This commit is contained in:
Drew
2016-04-07 04:47:47 -07:00
committed by Florent Vilmart
parent ef92a79818
commit 325d09ca4c
2 changed files with 25 additions and 16 deletions

View File

@@ -115,9 +115,20 @@ class MongoSchemaCollection {
});
}
// Add a collection. Currently the input is in mongo format, but that will change to Parse format in a
// later PR. Returns a promise that is expected to resolve with the newly created schema, in Parse format.
// If the class already exists, returns a promise that rejects with undefined as the reason. If the collection
// can't be added for a reason other than it already existing, requirements for rejection reason are TBD.
addSchema(name: string, fields) {
let mongoObject = _mongoSchemaObjectFromNameFields(name, fields);
return this._collection.insertOne(mongoObject);
return this._collection.insertOne(mongoObject)
.then(result => mongoSchemaToParseSchema(result.ops[0]))
.catch(error => {
if (error.code === 11000) { //Mongo's duplicate key error
return Promise.reject();
}
return Promise.reject(error);
});
}
updateSchema(name: string, update) {