Merge pull request #710 from sdf611097/typeChecking

Add __type checking
This commit is contained in:
Drew
2016-03-02 14:57:19 -08:00
3 changed files with 70 additions and 17 deletions

View File

@@ -594,7 +594,7 @@ Schema.prototype.validateRequiredColumns = function(className, object, query) {
if (!columns || columns.length == 0) {
return Promise.resolve(this);
}
var missingColumns = columns.filter(function(column){
if (query && query.objectId) {
if (object[column] && typeof object[column] === "object") {
@@ -604,15 +604,15 @@ Schema.prototype.validateRequiredColumns = function(className, object, query) {
// Not trying to do anything there
return false;
}
return !object[column]
return !object[column]
});
if (missingColumns.length > 0) {
throw new Parse.Error(
Parse.Error.INCORRECT_TYPE,
missingColumns[0]+' is required.');
}
return Promise.resolve(this);
}
@@ -699,19 +699,44 @@ function getObjectType(obj) {
if (obj instanceof Array) {
return 'array';
}
if (obj.__type === 'Pointer' && obj.className) {
return '*' + obj.className;
}
if (obj.__type === 'File' && obj.name) {
return 'file';
}
if (obj.__type === 'Date' && obj.iso) {
return 'date';
}
if (obj.__type == 'GeoPoint' &&
obj.latitude != null &&
obj.longitude != null) {
return 'geopoint';
if (obj.__type){
switch(obj.__type) {
case 'Pointer' :
if(obj.className) {
return '*' + obj.className;
} else {
throw new Parse.Error(Parse.Error.INCORRECT_TYPE, "This is not a valid "+obj.__type);
}
break;
case 'File' :
if(obj.name) {
return 'file';
} else {
throw new Parse.Error(Parse.Error.INCORRECT_TYPE, "This is not a valid "+obj.__type);
}
break;
case 'Date' :
if(obj.iso) {
return 'date';
} else {
throw new Parse.Error(Parse.Error.INCORRECT_TYPE, "This is not a valid "+obj.__type);
}
break;
case 'GeoPoint' :
if(obj.latitude != null && obj.longitude != null) {
return 'geopoint';
} else {
throw new Parse.Error(Parse.Error.INCORRECT_TYPE, "This is not a valid "+obj.__type);
}
break;
case 'Bytes' :
if(!obj.base64) {
throw new Parse.Error(Parse.Error.INCORRECT_TYPE, "This is not a valid "+obj.__type);
}
break;
default :
throw new Parse.Error(Parse.Error.INCORRECT_TYPE, 'invalid type: ' + obj.__type);
}
}
if (obj['$ne']) {
return getObjectType(obj['$ne']);