feat: convert InsightsBookingService to use Prisma.sql raw queries#7
feat: convert InsightsBookingService to use Prisma.sql raw queries#7akshayutture-augment wants to merge 1 commit into
Conversation
…22345) * fix: use raw query at InsightsBookingService * feat: convert InsightsBookingService to use Prisma.sql raw queries - Convert auth conditions from Prisma object notation to Prisma.sql - Convert filter conditions from Prisma object notation to Prisma.sql - Update return types from Prisma.BookingTimeStatusDenormalizedWhereInput to Prisma.Sql - Fix type error in isOrgOwnerOrAdmin method - Follow same pattern as InsightsRoutingService conversion Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * feat: convert InsightsBookingService to use Prisma.sql raw queries - Convert auth conditions from Prisma object notation to Prisma.sql - Convert filter conditions from Prisma object notation to Prisma.sql - Update return types from Prisma.BookingTimeStatusDenormalizedWhereInput to Prisma.Sql - Fix type error in isOrgOwnerOrAdmin method - Follow same pattern as InsightsRoutingService conversion Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * fix: update InsightsBookingService integration tests for Prisma.sql format - Replace Prisma object notation expectations with Prisma.sql template literals - Add NOTHING_CONDITION constant for consistency with InsightsRoutingService - Update all test cases to use direct Prisma.sql comparisons - Use $queryRaw for actual database integration testing - Follow same testing patterns as InsightsRoutingService Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * fix: exclude intentionally skipped jobs from required CI check failure - Remove 'skipped' from failure condition in pr.yml and all-checks.yml - Allow E2E jobs to be skipped without failing the required check - Only actual failures and cancelled jobs will cause required check to fail Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * fix tests * Revert "fix: exclude intentionally skipped jobs from required CI check failure" This reverts commit 6ff44fc9a8f14ad657f7bba7c2e454e192b66c8f. * clean up tests * address feedback --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@claude review this PR |
1 similar comment
|
@claude review this PR |
|
Claude finished @akshayutture-augment's task —— View job Code Review Complete ✅I've reviewed this PR that converts 🎯 OverviewThis PR successfully converts the service from Prisma object notation to ✅ Strengths
🔍 Issues Found🔴 Critical: SQL Injection Vulnerability RiskLocation: The use of Prisma.sql`("teamId" = ANY(${teamIds})) AND ("isTeamBooking" = true)`
Prisma.sql`("userId" = ANY(${uniqueUserIds})) AND ("isTeamBooking" = false)`Concern: While
Recommendation: Test edge cases with empty arrays and add defensive checks: if (teamIds.length === 0) {
return NOTHING_CONDITION;
}🟡 Medium: Potential Performance IssueLocation: The
Issues:
Recommendation: Consider pagination or batching for large organizations, or add query limits with documentation about the constraint. 🟡 Medium: Array Deduplication LogicLocation: const uniqueUserIds = Array.from(new Set(userIdsFromOrg));Issue: This deduplication is only done for org scope, not for team scope (line 194). This inconsistency could lead to:
Recommendation: Apply consistent deduplication in both methods or document why it's different. 🟡 Medium: Error Handling MissingLocation: Throughout the service Issue: No error handling for:
Recommendation: Add try-catch blocks or let errors bubble with proper context: async getAuthorizationConditions(): Promise<Prisma.Sql> {
try {
if (this.cachedAuthConditions === undefined) {
this.cachedAuthConditions = await this.buildAuthorizationConditions();
}
return this.cachedAuthConditions;
} catch (error) {
// Log error with context
return NOTHING_CONDITION; // Fail closed for security
}
}🟢 Minor Issues1. Type Safety ConcernLocation: private options: InsightsBookingServiceOptions | null;The 2. Test Data Unique Constraint RiskLocation: The test uses 3. Inconsistent Condition WrappingLocation: Throughout service file Some conditions wrap with extra parentheses, others don't:
This inconsistency doesn't affect functionality but could be standardized for maintainability. 4. Magic ConstantLocation: const NOTHING_CONDITION = Prisma.sql`1=0`;Consider adding a comment explaining why 🧪 Test Quality AssessmentExcellent coverage overall, but consider adding:
📋 Recommendations SummaryBefore Merging:
Future Improvements:
🎓 Overall AssessmentVerdict: ✅ Approve with minor concerns The conversion to The code quality is good, tests are comprehensive, and the approach is sound. Nice work on the refactoring! |
|
This PR is being marked as stale due to inactivity. |
Test 5
Replicated from ai-code-review-evaluation/cal.com-greptile#5