Pass the Parse Schema into untransform
This commit is contained in:
@@ -199,10 +199,10 @@ export class MongoStorageAdapter {
|
|||||||
|
|
||||||
// Executes a find. Accepts: className, query in Parse format, and { skip, limit, sort }.
|
// Executes a find. Accepts: className, query in Parse format, and { skip, limit, sort }.
|
||||||
// Accepts the schemaController for legacy reasons.
|
// Accepts the schemaController for legacy reasons.
|
||||||
find(className, query, { skip, limit, sort }, schemaController) {
|
find(className, query, { skip, limit, sort }, schemaController, schema) {
|
||||||
return this.adaptiveCollection(className)
|
return this.adaptiveCollection(className)
|
||||||
.then(collection => collection.find(query, { skip, limit, sort }))
|
.then(collection => collection.find(query, { skip, limit, sort }))
|
||||||
.then(objects => objects.map(object => transform.mongoObjectToParseObject(schemaController, className, object)));
|
.then(objects => objects.map(object => transform.mongoObjectToParseObject(schemaController, className, object, schema)));
|
||||||
}
|
}
|
||||||
|
|
||||||
get transform() {
|
get transform() {
|
||||||
|
|||||||
@@ -755,7 +755,7 @@ const nestedMongoObjectToNestedParseObject = mongoObject => {
|
|||||||
|
|
||||||
// Converts from a mongo-format object to a REST-format object.
|
// Converts from a mongo-format object to a REST-format object.
|
||||||
// Does not strip out anything based on a lack of authentication.
|
// Does not strip out anything based on a lack of authentication.
|
||||||
const mongoObjectToParseObject = (schema, className, mongoObject) => {
|
const mongoObjectToParseObject = (schemaController, className, mongoObject, schema) => {
|
||||||
switch(typeof mongoObject) {
|
switch(typeof mongoObject) {
|
||||||
case 'string':
|
case 'string':
|
||||||
case 'number':
|
case 'number':
|
||||||
@@ -831,8 +831,8 @@ const mongoObjectToParseObject = (schema, className, mongoObject) => {
|
|||||||
if (key.indexOf('_p_') == 0) {
|
if (key.indexOf('_p_') == 0) {
|
||||||
var newKey = key.substring(3);
|
var newKey = key.substring(3);
|
||||||
var expected;
|
var expected;
|
||||||
if (schema && schema.getExpectedType) {
|
if (schemaController && schemaController.getExpectedType) {
|
||||||
expected = schema.getExpectedType(className, newKey);
|
expected = schemaController.getExpectedType(className, newKey);
|
||||||
}
|
}
|
||||||
if (!expected) {
|
if (!expected) {
|
||||||
log.info('transform.js',
|
log.info('transform.js',
|
||||||
@@ -861,7 +861,7 @@ const mongoObjectToParseObject = (schema, className, mongoObject) => {
|
|||||||
} else if (key[0] == '_' && key != '__type') {
|
} else if (key[0] == '_' && key != '__type') {
|
||||||
throw ('bad key in untransform: ' + key);
|
throw ('bad key in untransform: ' + key);
|
||||||
} else {
|
} else {
|
||||||
var expectedType = schema.getExpectedType(className, key);
|
var expectedType = schemaController.getExpectedType(className, key);
|
||||||
var value = mongoObject[key];
|
var value = mongoObject[key];
|
||||||
if (expectedType && expectedType.type === 'File' && FileCoder.isValidDatabaseObject(value)) {
|
if (expectedType && expectedType.type === 'File' && FileCoder.isValidDatabaseObject(value)) {
|
||||||
restObject[key] = FileCoder.databaseToJSON(value);
|
restObject[key] = FileCoder.databaseToJSON(value);
|
||||||
@@ -876,7 +876,7 @@ const mongoObjectToParseObject = (schema, className, mongoObject) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { ...restObject, ...schema.getRelationFields(className) };
|
return { ...restObject, ...schemaController.getRelationFields(className) };
|
||||||
default:
|
default:
|
||||||
throw 'unknown js type';
|
throw 'unknown js type';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -701,7 +701,7 @@ DatabaseController.prototype.find = function(className, query, {
|
|||||||
delete mongoOptions.limit;
|
delete mongoOptions.limit;
|
||||||
return collection.count(mongoWhere, mongoOptions);
|
return collection.count(mongoWhere, mongoOptions);
|
||||||
} else {
|
} else {
|
||||||
return this.adapter.find(className, mongoWhere, mongoOptions, schemaController)
|
return this.adapter.find(className, mongoWhere, mongoOptions, schemaController, schema)
|
||||||
.then(objects => objects.map(object => filterSensitiveData(isMaster, aclGroup, className, object)));
|
.then(objects => objects.map(object => filterSensitiveData(isMaster, aclGroup, className, object)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user