@@ -286,7 +286,9 @@ function _save(appId, collectionName, document, accessList, isMasterKey, reqType
286
286
_validateSchema ( appId , listOfDocs , accessList , isMasterKey ) . then ( function ( listOfDocs ) {
287
287
console . log ( "Schema checked" ) ;
288
288
289
- var mongoDocs = JSON . parse ( JSON . stringify ( listOfDocs ) ) ; //making copies of an array to avoid modification by "call by reference"
289
+ var mongoDocs = listOfDocs . map ( function ( doc ) {
290
+ return Object . assign ( { } , doc )
291
+ } )
290
292
291
293
promises . push ( databaseDriver . save ( appId , mongoDocs ) ) ;
292
294
global . q . allSettled ( promises ) . then ( function ( array ) {
@@ -438,6 +440,14 @@ var _isSchemaValid = function(appId, collectionName, document, accessList, isMas
438
440
continue ; //ignore.
439
441
440
442
if ( document [ columns [ i ] . name ] === undefined ) {
443
+ //TODO : check type for defaultValue , convert to date of type is DateTime , quick patch , fix properly later
444
+ if ( columns [ i ] . dataType === 'DateTime' ) {
445
+ try {
446
+ columns [ i ] . defaultValue = new Date ( columns [ i ] . defaultValue )
447
+ } catch ( e ) {
448
+ columns [ i ] . defaultValue = null
449
+ }
450
+ }
441
451
document [ columns [ i ] . name ] = columns [ i ] . defaultValue ;
442
452
}
443
453
@@ -517,7 +527,7 @@ var _isSchemaValid = function(appId, collectionName, document, accessList, isMas
517
527
if ( key === '_tableName' || key === '_type' || key === '_version' )
518
528
continue ; //check id; //ignore.
519
529
else if ( key === '_id' ) {
520
- //check if this is a string.
530
+ //check if this is a string..
521
531
if ( typeof document [ key ] !== 'string' ) {
522
532
mainPromise . reject ( 'Invalid data in ID of type ' + collectionName + '. It should be of type string' ) ;
523
533
return mainPromise . promise ;
0 commit comments