Skip to content

Commit 5cbf3eb

Browse files
committed
Tidy up db controller
1 parent 37953d1 commit 5cbf3eb

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/Adapters/Storage/Mongo/MongoTransform.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ const valueAsDate = value => {
140140
}
141141

142142
function transformQueryKeyValue(schema, className, key, value, { validate } = {}) {
143-
// Check if the schema is known since it's a built-in field.
144143
switch(key) {
145144
case 'createdAt':
146145
if (valueAsDate(value)) {
@@ -188,9 +187,6 @@ function transformQueryKeyValue(schema, className, key, value, { validate } = {}
188187
}
189188
}
190189

191-
// Handle special schema key changes
192-
// TODO: it seems like this is likely to have edge cases where
193-
// pointer types are missed
194190
let expected = undefined;
195191
if (schema && schema.getExpectedType) {
196192
expected = schema.getExpectedType(className, key);

src/Controllers/DatabaseController.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,29 +158,34 @@ DatabaseController.prototype.update = function(className, query, update, {
158158

159159
var isMaster = acl === undefined;
160160
var aclGroup = acl || [];
161-
var mongoUpdate, schema;
161+
var mongoUpdate;
162162
return this.loadSchema()
163-
.then(s => {
164-
schema = s;
165-
if (!isMaster) {
166-
return schema.validatePermission(className, aclGroup, 'update');
167-
}
168-
return Promise.resolve();
169-
})
163+
.then(schemaController => {
164+
return (isMaster ? Promise.resolve() : schemaController.validatePermission(className, aclGroup, 'update'))
170165
.then(() => this.handleRelationUpdates(className, query.objectId, update))
171166
.then(() => this.adapter.adaptiveCollection(className))
172167
.then(collection => {
173168
if (!isMaster) {
174-
query = this.addPointerPermissions(schema, className, 'update', query, aclGroup);
169+
query = this.addPointerPermissions(schemaController, className, 'update', query, aclGroup);
175170
}
176171
if (!query) {
177172
return Promise.resolve();
178173
}
179174
if (acl) {
180175
query = addWriteACL(query, acl);
181176
}
182-
var mongoWhere = this.transform.transformWhere(schema, className, query, {validate: !this.skipValidation});
183-
mongoUpdate = this.transform.transformUpdate(schema, className, update, {validate: !this.skipValidation});
177+
var mongoWhere = this.transform.transformWhere(
178+
schemaController,
179+
className,
180+
query,
181+
{validate: !this.skipValidation}
182+
);
183+
mongoUpdate = this.transform.transformUpdate(
184+
schemaController,
185+
className,
186+
update,
187+
{validate: !this.skipValidation}
188+
);
184189
if (many) {
185190
return collection.updateMany(mongoWhere, mongoUpdate);
186191
} else if (upsert) {
@@ -191,14 +196,14 @@ DatabaseController.prototype.update = function(className, query, update, {
191196
})
192197
.then(result => {
193198
if (!result) {
194-
return Promise.reject(new Parse.Error(Parse.Error.OBJECT_NOT_FOUND,
195-
'Object not found.'));
199+
return Promise.reject(new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Object not found.'));
196200
}
197201
if (this.skipValidation) {
198202
return Promise.resolve(result);
199203
}
200204
return sanitizeDatabaseResult(originalUpdate, result);
201205
});
206+
});
202207
};
203208

204209
function sanitizeDatabaseResult(originalObject, result) {

0 commit comments

Comments
 (0)