Optimize code patterns from recent commits: eliminate duplication, modernize syntax, fix async handling#7
Conversation
…yntax Co-authored-by: PhantomDave <34485699+PhantomDave@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes code patterns from recent commits by eliminating duplication, modernizing syntax, and fixing async handling issues.
- Extracts repeated object mapping logic in
FinanceRecordServiceinto a reusable helper method - Modernizes C# string slicing syntax and removes redundant null coalescing
- Fixes async/await handling in dialog callback and removes unnecessary computed wrapper
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
frontend/src/app/models/finance-record/finance-record-service.ts |
Extracts mapToFinanceRecord() helper to eliminate ~20 lines of duplicate mapping logic; removes redundant null coalescing for recurrenceFrequency |
frontend/src/app/components/configurator/configurator-component/configurator-component.ts |
Adds await to createFinanceRecord() call in dialog callback for proper async handling |
frontend/src/app/components/configurator/add-entry/add-entry.ts |
Removes unnecessary computed() wrapper by directly using toSignal() for isSubmitDisabled |
frontend/codegen.ts |
Adds USE_LOCAL_SCHEMA environment variable support for local GraphQL schema building |
PhantomDave.BankTracking.Api/Services/FinanceRecordService.cs |
Modernizes string slicing from Substring(0, 500) to range operator [..500] |
| description: string; | ||
| amount: number; | ||
| currency: string; | ||
| date: any; |
There was a problem hiding this comment.
The date parameter type should be string instead of any since GraphQL returns ISO date strings. This provides better type safety and makes the conversion on line 75 more explicit.
| date: any; | |
| date: string; |
| private mapToFinanceRecord(data: { | ||
| id: number; | ||
| name: string; | ||
| description: string; | ||
| amount: number; | ||
| currency: string; | ||
| date: any; | ||
| isRecurring: boolean; | ||
| }): FinanceRecord { |
There was a problem hiding this comment.
[nitpick] Consider extracting the inline type definition for the data parameter into a separate type or interface (e.g., CreateFinanceRecordResponse). This would improve reusability if the mapping needs to be used elsewhere and make the type definition more maintainable.
Code review of today's commits revealed several suboptimal patterns: duplicate object mapping, redundant null coalescing, outdated C# syntax, missing async/await, and unnecessary computed wrappers.
Changes
Frontend - Eliminate duplication in
FinanceRecordServicemapToFinanceRecord()helper (~20 lines removed)Frontend - Remove redundant null coalescing
recurrenceFrequencytoNone, removed?? RecurrenceFrequency.NONEBackend - Modernize string slicing
trimmed.Substring(0, 500)with range operatortrimmed[..500]Frontend - Fix missing await in
ConfiguratorComponentawaittocreateFinanceRecord()call for proper async handlingFrontend - Remove unnecessary computed wrapper
computed(() => signal())pass-throughBuild - Support local schema in codegen
USE_LOCAL_SCHEMAenv var to build without running GraphQL serverOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.