-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
#4678: Converting strings to Date when schema.type is Date within agg… #4743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
fa8c902
9a12b7c
044453a
90b43ba
1714711
867863e
d922a7a
7261ba0
beb54bb
403e81b
9526c65
7993f45
f8c06d9
abf42d9
f7edfa5
cdc90e2
52b2f7f
ae3ce3b
da3afbb
a7c428d
cc25079
1a51a82
af531c1
6b8fded
f8d7826
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -565,18 +565,7 @@ export class MongoStorageAdapter implements StorageAdapter { | |
} | ||
} | ||
if (stage.$match) { | ||
for (const field in stage.$match) { | ||
if (schema.fields[field] && schema.fields[field].type === 'Pointer') { | ||
const transformMatch = { [`_p_${field}`] : `${schema.fields[field].targetClass}$${stage.$match[field]}` }; | ||
stage.$match = transformMatch; | ||
} | ||
if (field === 'objectId') { | ||
const transformMatch = Object.assign({}, stage.$match); | ||
transformMatch._id = stage.$match[field]; | ||
delete transformMatch.objectId; | ||
stage.$match = transformMatch; | ||
} | ||
} | ||
this._parseAggregateArgs(schema, stage.$match); | ||
} | ||
return stage; | ||
}); | ||
|
@@ -608,6 +597,55 @@ export class MongoStorageAdapter implements StorageAdapter { | |
.catch(err => this.handleError(err)); | ||
} | ||
|
||
_parseAggregateArgs(schema: any, pipeline: any): any { | ||
var rtnval = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use const, and actually remove :) |
||
if (Array.isArray(pipeline)) { | ||
rtnval = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we transform in
|
||
for (const field in pipeline) { | ||
rtnval.push(this._parseAggregateArgs(schema, pipeline[field])); | ||
} | ||
} | ||
else if (typeof pipeline === 'object') { | ||
for (const field in pipeline) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. declare |
||
if (schema.fields[field] && schema.fields[field].type === 'Pointer') { | ||
rtnval[`_p_${field}`] = `${schema.fields[field].targetClass}$${pipeline[field]}`; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. throughout the codebase we always write
Can we keep the style please? |
||
else if (schema.fields[field] && schema.fields[field].type === 'Date') { | ||
rtnval[field] = this._convertToDate(pipeline[field]); | ||
} | ||
else { | ||
rtnval[field] = this._parseAggregateArgs(schema, pipeline[field]); | ||
} | ||
|
||
if (field === 'objectId') { | ||
rtnval['_id'] = rtnval[field]; | ||
delete rtnval[field]; | ||
} | ||
else if (field === 'createdAt') { | ||
rtnval['_created_at'] = rtnval[field]; | ||
delete rtnval[field]; | ||
} | ||
else if (field === 'updatedAt') { | ||
rtnval['_updated_at'] = rtnval[field]; | ||
delete rtnval[field]; | ||
} | ||
} | ||
} | ||
return rtnval; | ||
} | ||
|
||
_convertToDate(value: any): any { | ||
if (typeof value === 'string') { | ||
return new Date(value); | ||
} | ||
|
||
var rtnval = {} | ||
for (const field in value) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we document what we expect the value to look like, I have trouble understanding what it does, and why we need the iterator, and recursion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the newbie question...how do we take care of these? I've updated my branch to include your suggestions. Thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function may work wrong way when "value" is |
||
rtnval[field] = this._convertToDate(value[field]) | ||
} | ||
return rtnval; | ||
} | ||
|
||
_parseReadPreference(readPreference: ?string): ?string { | ||
switch (readPreference) { | ||
case 'PRIMARY': | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returned value seem unused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for picking up on that...I was trying to hurry and pushed the repo by accident (muscle memory from my day job, haha). I just pushed the fix.