-
Notifications
You must be signed in to change notification settings - Fork 18
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
Query for recurring donation by date #1738
Conversation
Solana user profile support
… query-for-recurring-donation-by-date
WalkthroughRecent changes enhance the GraphQL API by adding a new query, Changes
Poem
Recent review detailsConfiguration used: CodeRabbit UI Files selected for processing (3)
Files skipped from review as they are similar to previous changes (1)
Additional comments not posted (10)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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.
Actionable comments posted: 6
Outside diff range, codebase verification and nitpick comments (1)
test/graphqlQueries.ts (1)
2467-2485
: Add more fields to the query.Consider adding more fields to the query to provide comprehensive donation details.
Consider adding fields such as
isBatch
,isForUpdate
, andflowRate
to the query.
@Query(_retuns => PaginateRecurringDonations, { nullable: true }) | ||
async recurringDonationsByDate( |
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.
Fix typo in decorator return type.
The decorator _retuns
should be corrected to _returns
.
- @Query(_retuns => PaginateRecurringDonations, { nullable: true })
+ @Query(_returns => PaginateRecurringDonations, { nullable: true })
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
@Query(_retuns => PaginateRecurringDonations, { nullable: true }) | |
async recurringDonationsByDate( | |
@Query(_returns => PaginateRecurringDonations, { nullable: true }) | |
async recurringDonationsByDate( |
const project = await findProjectById(projectId); | ||
if (!project) { | ||
throw new Error(i18n.__(translationErrorMessagesKeys.PROJECT_NOT_FOUND)); |
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.
Add error handling for project validation.
The error message should be more descriptive to help in debugging.
- throw new Error(i18n.__(translationErrorMessagesKeys.PROJECT_NOT_FOUND));
+ throw new Error(`Project with ID ${projectId} not found.`);
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const project = await findProjectById(projectId); | |
if (!project) { | |
throw new Error(i18n.__(translationErrorMessagesKeys.PROJECT_NOT_FOUND)); | |
const project = await findProjectById(projectId); | |
if (!project) { | |
throw new Error(`Project with ID ${projectId} not found.`); |
const [recurringDonations, donationsCount] = await query.getManyAndCount(); | ||
return { | ||
recurringDonations, | ||
totalCount: donationsCount, | ||
}; |
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.
Ensure proper error handling for query execution.
Add error handling for the query execution to catch and log any potential errors.
- const [recurringDonations, donationsCount] = await query.getManyAndCount();
+ let recurringDonations, donationsCount;
+ try {
+ [recurringDonations, donationsCount] = await query.getManyAndCount();
+ } catch (error) {
+ logger.error('Error executing recurringDonationsByDate query', error);
+ throw new Error('Failed to fetch recurring donations.');
+ }
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const [recurringDonations, donationsCount] = await query.getManyAndCount(); | |
return { | |
recurringDonations, | |
totalCount: donationsCount, | |
}; | |
let recurringDonations, donationsCount; | |
try { | |
[recurringDonations, donationsCount] = await query.getManyAndCount(); | |
} catch (error) { | |
logger.error('Error executing recurringDonationsByDate query', error); | |
throw new Error('Failed to fetch recurring donations.'); | |
} | |
return { | |
recurringDonations, | |
totalCount: donationsCount, | |
}; |
if (endtDate) { | ||
query.andWhere('recurringDonation.createdAt <= :endtDate', { | ||
endtDate: new Date(endtDate), | ||
}); | ||
} |
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.
Combine date filters.
Combine the date filters into a single condition to optimize the query.
- if (startDate) {
- query.andWhere('recurringDonation.createdAt >= :startDate', {
- startDate: new Date(startDate),
- });
- }
- if (endtDate) {
- query.andWhere('recurringDonation.createdAt <= :endtDate', {
- endtDate: new Date(endtDate),
- });
+ if (startDate || endtDate) {
+ query.andWhere('recurringDonation.createdAt BETWEEN :startDate AND :endtDate', {
+ startDate: startDate ? new Date(startDate) : new Date(0),
+ endtDate: endtDate ? new Date(endtDate) : new Date(),
+ });
}
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if (endtDate) { | |
query.andWhere('recurringDonation.createdAt <= :endtDate', { | |
endtDate: new Date(endtDate), | |
}); | |
} | |
if (startDate || endtDate) { | |
query.andWhere('recurringDonation.createdAt BETWEEN :startDate AND :endtDate', { | |
startDate: startDate ? new Date(startDate) : new Date(0), | |
endtDate: endtDate ? new Date(endtDate) : new Date(), | |
}); | |
} |
const query = RecurringDonation.createQueryBuilder('recurringDonation') | ||
.leftJoin('recurringDonation.donor', 'donor') | ||
.addSelect([ | ||
'donor.id', | ||
'donor.walletAddress', | ||
'donor.name', | ||
'donor.firstName', | ||
'donor.lastName', | ||
'donor.url', | ||
'donor.avatar', | ||
'donor.totalDonated', | ||
'donor.totalReceived', | ||
'donor.passportScore', | ||
'donor.passportStamps', | ||
]) | ||
.where(`recurringDonation.projectId = ${projectId}`); |
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.
Optimize query construction.
The query construction can be optimized by using parameterized queries to prevent SQL injection.
- .where(`recurringDonation.projectId = ${projectId}`);
+ .where('recurringDonation.projectId = :projectId', { projectId });
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const query = RecurringDonation.createQueryBuilder('recurringDonation') | |
.leftJoin('recurringDonation.donor', 'donor') | |
.addSelect([ | |
'donor.id', | |
'donor.walletAddress', | |
'donor.name', | |
'donor.firstName', | |
'donor.lastName', | |
'donor.url', | |
'donor.avatar', | |
'donor.totalDonated', | |
'donor.totalReceived', | |
'donor.passportScore', | |
'donor.passportStamps', | |
]) | |
.where(`recurringDonation.projectId = ${projectId}`); | |
const query = RecurringDonation.createQueryBuilder('recurringDonation') | |
.leftJoin('recurringDonation.donor', 'donor') | |
.addSelect([ | |
'donor.id', | |
'donor.walletAddress', | |
'donor.name', | |
'donor.firstName', | |
'donor.lastName', | |
'donor.url', | |
'donor.avatar', | |
'donor.totalDonated', | |
'donor.totalReceived', | |
'donor.passportScore', | |
'donor.passportStamps', | |
]) | |
.where('recurringDonation.projectId = :projectId', { projectId }); |
test/graphqlQueries.ts
Outdated
export const fetchRecurringDonationsByDate = ` | ||
query ( | ||
$projectId: Int! | ||
$startDate: String! | ||
$endDate: String! | ||
) { | ||
recurringDonationsByDate( | ||
projectId: $projectId | ||
startDate: $startDate | ||
endDate: $endDate | ||
) { | ||
recurringDonations { | ||
id | ||
txHash | ||
networkId | ||
flowRate | ||
currency | ||
anonymous | ||
isArchived | ||
status | ||
donor { | ||
id | ||
walletAddress | ||
firstName | ||
} | ||
createdAt | ||
} | ||
totalCount | ||
} | ||
} | ||
`; |
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.
Ensure optional date parameters.
The startDate
and endDate
parameters should be optional to match the resolver method signature.
- $startDate: String!
- $endDate: String!
+ $startDate: String
+ $endDate: String
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export const fetchRecurringDonationsByDate = ` | |
query ( | |
$projectId: Int! | |
$startDate: String! | |
$endDate: String! | |
) { | |
recurringDonationsByDate( | |
projectId: $projectId | |
startDate: $startDate | |
endDate: $endDate | |
) { | |
recurringDonations { | |
id | |
txHash | |
networkId | |
flowRate | |
currency | |
anonymous | |
isArchived | |
status | |
donor { | |
id | |
walletAddress | |
firstName | |
} | |
createdAt | |
} | |
totalCount | |
} | |
} | |
`; | |
export const fetchRecurringDonationsByDate = ` | |
query ( | |
$projectId: Int! | |
$startDate: String | |
$endDate: String | |
) { | |
recurringDonationsByDate( | |
projectId: $projectId | |
startDate: $startDate | |
endDate: $endDate | |
) { | |
recurringDonations { | |
id | |
txHash | |
networkId | |
flowRate | |
currency | |
anonymous | |
isArchived | |
status | |
donor { | |
id | |
walletAddress | |
firstName | |
} | |
createdAt | |
} | |
totalCount | |
} | |
} | |
`; |
… query-for-recurring-donation-by-date
@lovelgeorge99 Can you write test cases for this new resolver? |
… query-for-recurring-donation-by-date
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 @lovelgeorge99 LGTM
I have added a query to fetch recurring donations of a projects from a given date for this issue Giveth/giveth-dapps-v2#4287 (comment)
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Style