This commit is contained in:
Antonio Davi Macedo Coelho de Castro
2020-04-22 09:04:07 -07:00
committed by GitHub
parent 489aeae784
commit 0dec1c80e2

View File

@@ -42,7 +42,7 @@ function mongoFieldToParseSchemaField(type) {
const nonFieldSchemaKeys = ['_id', '_metadata', '_client_permissions'];
function mongoSchemaFieldsToParseSchemaFields(schema) {
var fieldNames = Object.keys(schema).filter(
key => nonFieldSchemaKeys.indexOf(key) === -1
(key) => nonFieldSchemaKeys.indexOf(key) === -1
);
var response = fieldNames.reduce((obj, fieldName) => {
obj[fieldName] = mongoFieldToParseSchemaField(schema[fieldName]);
@@ -110,7 +110,7 @@ function mongoSchemaToParseSchema(mongoSchema) {
function _mongoSchemaQueryFromNameQuery(name: string, query) {
const object = { _id: name };
if (query) {
Object.keys(query).forEach(key => {
Object.keys(query).forEach((key) => {
object[key] = query[key];
});
}
@@ -158,13 +158,13 @@ class MongoSchemaCollection {
_fetchAllSchemasFrom_SCHEMA() {
return this._collection
._rawFind({})
.then(schemas => schemas.map(mongoSchemaToParseSchema));
.then((schemas) => schemas.map(mongoSchemaToParseSchema));
}
_fetchOneSchemaFrom_SCHEMA(name: string) {
return this._collection
._rawFind(_mongoSchemaQueryFromNameQuery(name), { limit: 1 })
.then(results => {
.then((results) => {
if (results.length === 1) {
return mongoSchemaToParseSchema(results[0]);
} else {
@@ -175,17 +175,16 @@ class MongoSchemaCollection {
// Atomically find and delete an object based on query.
findAndDeleteSchema(name: string) {
return this._collection._mongoCollection.findAndRemove(
_mongoSchemaQueryFromNameQuery(name),
[]
return this._collection._mongoCollection.findOneAndDelete(
_mongoSchemaQueryFromNameQuery(name)
);
}
insertSchema(schema: any) {
return this._collection
.insertOne(schema)
.then(result => mongoSchemaToParseSchema(result.ops[0]))
.catch(error => {
.then((result) => mongoSchemaToParseSchema(result.ops[0]))
.catch((error) => {
if (error.code === 11000) {
//Mongo's duplicate key error
throw new Parse.Error(
@@ -226,7 +225,7 @@ class MongoSchemaCollection {
addFieldIfNotExists(className: string, fieldName: string, fieldType: string) {
return this._fetchOneSchemaFrom_SCHEMA(className)
.then(
schema => {
(schema) => {
// If a field with this name already exists, it will be handled elsewhere.
if (schema.fields[fieldName] != undefined) {
return;
@@ -236,7 +235,7 @@ class MongoSchemaCollection {
// Make sure there are not other geopoint fields
if (
Object.keys(schema.fields).some(
existingField =>
(existingField) =>
schema.fields[existingField].type === 'GeoPoint'
)
) {
@@ -248,7 +247,7 @@ class MongoSchemaCollection {
}
return;
},
error => {
(error) => {
// If error is undefined, the schema doesn't exist, and we can create the schema with the field.
// If some other error, reject with it.
if (error === undefined) {