forked from Code-4-Community/scaffolding
    
        
        - 
                Notifications
    You must be signed in to change notification settings 
- Fork 0
Gr donations service domain dtos #12
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
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            6 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      1a3dfb8
              
                added dtos and normalization helpers
              
              
                GauriRajesh733 36939ba
              
                added dtos and normalization helpers
              
              
                GauriRajesh733 cb870fb
              
                static normalization helper corretions
              
              
                GauriRajesh733 bb91568
              
                static normalization helper corrections
              
              
                GauriRajesh733 d43275a
              
                Merge branch 'gr-donations-service-domain-dtos' of https://github.com…
              
              
                GauriRajesh733 5b2ff5c
              
                utils functions
              
              
                GauriRajesh733 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { | ||
| DonationType, | ||
| NormalizedInterval, | ||
| } from '../../util/donations/donations.util'; | ||
|  | ||
| export class CreateDonationDTO { | ||
| firstName: string; | ||
|  | ||
| lastName: string; | ||
|  | ||
| email: string; | ||
|  | ||
| amount: number; | ||
|  | ||
| isAnonymous: boolean = false; | ||
|  | ||
| donationType: DonationType; | ||
|  | ||
| recurringInterval?: NormalizedInterval | null; | ||
|  | ||
| dedicationMessage?: string | null; | ||
|  | ||
| showDedicationPublicly?: boolean = false; | ||
| } | 
        
          
          
            11 changes: 11 additions & 0 deletions
          
          11 
        
  apps/backend/src/donations/dtos/donation-response.domain.ts
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { CreateDonationDTO } from './create-donation.domain'; | ||
|  | ||
| export class DonationResponseDTO { | ||
| id: number; | ||
|  | ||
| stored: CreateDonationDTO; | ||
|  | ||
| createdAt: string; | ||
|  | ||
| updatedAt: string; | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export * from './create-donation.domain'; | ||
| export * from './donation-response.domain'; | ||
| export * from './public-donation.domain'; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { DonationType } from '../../util/donations/donations.util'; | ||
|  | ||
| export class PublicDonationDTO { | ||
| id: number; | ||
|  | ||
| amount: number; | ||
|  | ||
| donationType: DonationType; | ||
|  | ||
| dedicationMessage?: string | null; | ||
|  | ||
| isAnonymous: boolean; | ||
|  | ||
| donorName?: string | null; | ||
|  | ||
| createdAt: string; | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| export const donationTypes = ['one_time', 'recurring'] as const; | ||
| export type DonationType = (typeof donationTypes)[number]; | ||
| export const recurringIntervals = [ | ||
| 'monthly', | ||
| 'bimonthly', | ||
| 'quarterly', | ||
| 'annually', | ||
| 'weekly', | ||
| ] as const; | ||
| export type NormalizedInterval = (typeof recurringIntervals)[number]; | ||
|  | ||
| export function normalizeInterval( | ||
| input: string | null, | ||
| ): NormalizedInterval | null { | ||
| if (!input) { | ||
| return null; | ||
| } | ||
|  | ||
| const normalized = input.toLowerCase().trim(); | ||
|  | ||
| return (recurringIntervals as readonly string[]).includes(normalized) | ||
| ? (normalized as NormalizedInterval) | ||
| : null; | ||
| } | ||
|  | ||
| export function normalizeDonorName( | ||
| input: string | null, | ||
| anonymous: boolean, | ||
| ): string | null { | ||
| return anonymous ? null : input; | ||
| } | ||
|  | ||
| export function normalizeDonationAmount(amount: string | number): number { | ||
| const num = Number(amount); | ||
|  | ||
| return isFinite(num) ? num : 0; | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.
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.
great job on all the files! this looks good. I wrote it in really fine print but I think it would be nice to also have a minimal "amount parser" normalization helper. It'd turn a string/number into a valid number. For invalid cases like a string input, it'd turn that into a 0. This might sound bad but it's to avoid crashes and we will rely on other validations before this to ensure we're not experiencing silent failures.