Cleanup update (#1590)
* destructuring in DB controller * deleteObject in db adapter * Turns out we can't have delete by object ID because of ACLs... * Fix tests * destructure acl * Don't reject with object
This commit is contained in:
@@ -159,6 +159,37 @@ export class MongoStorageAdapter {
|
||||
.then(collection => collection.insertOne(mongoObject));
|
||||
}
|
||||
|
||||
// Remove all objects that match the given parse query. Parse Query should be in Parse Format.
|
||||
// If no objects match, reject with OBJECT_NOT_FOUND. If objects are found and deleted, resolve with undefined.
|
||||
// If there is some other error, reject with INTERNAL_SERVER_ERROR.
|
||||
|
||||
// Currently accepts the acl, schemaController, validate
|
||||
// for lecacy reasons, Parse Server should later integrate acl into the query. Database adapters
|
||||
// shouldn't know about acl.
|
||||
deleteObjectsByQuery(className, query, acl, schemaController, validate) {
|
||||
return this.adaptiveCollection(className)
|
||||
.then(collection => {
|
||||
let mongoWhere = transform.transformWhere(
|
||||
schemaController,
|
||||
className,
|
||||
query,
|
||||
{ validate }
|
||||
);
|
||||
if (acl) {
|
||||
mongoWhere = transform.addWriteACL(mongoWhere, acl);
|
||||
}
|
||||
return collection.deleteMany(mongoWhere)
|
||||
})
|
||||
.then(({ result }) => {
|
||||
if (result.n === 0) {
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Object not found.');
|
||||
}
|
||||
return Promise.resolve();
|
||||
}, error => {
|
||||
throw new Parse.Error(Parse.Error.INTERNAL_SERVER_ERROR, 'Database adapter error');
|
||||
});
|
||||
}
|
||||
|
||||
get transform() {
|
||||
return transform;
|
||||
}
|
||||
|
||||
@@ -195,8 +195,7 @@ function transformWhere(schema, className, restWhere, options = {validate: true}
|
||||
let transformKeyOptions = {query: true};
|
||||
transformKeyOptions.validate = options.validate;
|
||||
for (let restKey in restWhere) {
|
||||
let out = transformKeyValue(schema, className, restKey, restWhere[restKey],
|
||||
transformKeyOptions);
|
||||
let out = transformKeyValue(schema, className, restKey, restWhere[restKey], transformKeyOptions);
|
||||
mongoWhere[out.key] = out.value;
|
||||
}
|
||||
return mongoWhere;
|
||||
@@ -333,8 +332,7 @@ function transformUpdate(schema, className, restUpdate) {
|
||||
}
|
||||
|
||||
for (var restKey in restUpdate) {
|
||||
var out = transformKeyValue(schema, className, restKey, restUpdate[restKey],
|
||||
{update: true});
|
||||
var out = transformKeyValue(schema, className, restKey, restUpdate[restKey], {update: true});
|
||||
|
||||
// If the output value is an object with any $ keys, it's an
|
||||
// operator that needs to be lifted onto the top level update
|
||||
|
||||
Reference in New Issue
Block a user