Skip to content

Commit ecf422b

Browse files
nodechefMattTylerBrock
authored andcommitted
Mongo object to Parse object date serialization - avoid re-serialization of iso of type Date (#3389)
* Mongo object to Parse object date serialization - avoid nested ios * Mongo object to Parse object date serialization * Remove file from previous commit
1 parent 49dc8df commit ecf422b

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

spec/MongoTransform.spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,32 @@ describe('parseObjectToMongoObjectForCreate', () => {
293293
expect(output.double).toBe(Number.MAX_VALUE);
294294
done();
295295
});
296+
297+
it('Date object where iso attribute is of type Date', (done) => {
298+
var input = {
299+
ts : { __type: 'Date', iso: new Date('2017-01-18T00:00:00.000Z') }
300+
}
301+
var output = transform.mongoObjectToParseObject(null, input, {
302+
fields : {
303+
ts : { type : 'Date' }
304+
}
305+
});
306+
expect(output.ts.iso).toEqual('2017-01-18T00:00:00.000Z');
307+
done();
308+
});
309+
310+
it('Date object where iso attribute is of type String', (done) => {
311+
var input = {
312+
ts : { __type: 'Date', iso: '2017-01-18T00:00:00.000Z' }
313+
}
314+
var output = transform.mongoObjectToParseObject(null, input, {
315+
fields : {
316+
ts : { type : 'Date' }
317+
}
318+
});
319+
expect(output.ts.iso).toEqual('2017-01-18T00:00:00.000Z');
320+
done();
321+
});
296322
});
297323

298324
describe('transformUpdate', () => {

src/Adapters/Storage/Mongo/MongoTransform.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,11 @@ const nestedMongoObjectToNestedParseObject = mongoObject => {
726726
return BytesCoder.databaseToJSON(mongoObject);
727727
}
728728

729+
if (mongoObject.hasOwnProperty('__type') && mongoObject.__type == 'Date' && mongoObject.iso instanceof Date) {
730+
mongoObject.iso = mongoObject.iso.toJSON();
731+
return mongoObject;
732+
}
733+
729734
return _.mapValues(mongoObject, nestedMongoObjectToNestedParseObject);
730735
default:
731736
throw 'unknown js type';

0 commit comments

Comments
 (0)