Skip to content

Commit

Permalink
Merge pull request #208 from CloudBoost/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
shubhamqweasd authored Jun 28, 2017
2 parents 5e2f5a7 + 5b399d5 commit d1ee901
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions services/cloudObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ function _save(appId, collectionName, document, accessList, isMasterKey, reqType
_validateSchema(appId, listOfDocs, accessList, isMasterKey).then(function(listOfDocs) {
console.log("Schema checked");

var mongoDocs = JSON.parse(JSON.stringify(listOfDocs)); //making copies of an array to avoid modification by "call by reference"
var mongoDocs = listOfDocs.map(function(doc){
return Object.assign({},doc)
})

promises.push(databaseDriver.save(appId, mongoDocs));
global.q.allSettled(promises).then(function(array) {
Expand Down Expand Up @@ -438,6 +440,14 @@ var _isSchemaValid = function(appId, collectionName, document, accessList, isMas
continue; //ignore.

if (document[columns[i].name] === undefined) {
//TODO : check type for defaultValue , convert to date of type is DateTime , quick patch , fix properly later
if(columns[i].dataType === 'DateTime'){
try{
columns[i].defaultValue = new Date(columns[i].defaultValue)
} catch(e){
columns[i].defaultValue = null
}
}
document[columns[i].name] = columns[i].defaultValue;
}

Expand Down Expand Up @@ -517,7 +527,7 @@ var _isSchemaValid = function(appId, collectionName, document, accessList, isMas
if (key === '_tableName' || key === '_type' || key === '_version')
continue; //check id; //ignore.
else if (key === '_id') {
//check if this is a string.
//check if this is a string..
if (typeof document[key] !== 'string') {
mainPromise.reject('Invalid data in ID of type ' + collectionName + '. It should be of type string');
return mainPromise.promise;
Expand Down

0 comments on commit d1ee901

Please sign in to comment.