Skip to content

Conversation

@GauriRajesh733
Copy link
Contributor

ℹ️ Issue

Closes #9

📝 Description

Added create, findall, findone, findpublic, and get total donations service functions.
Input validation in create function (negative donation amount, invalid email, etc.)

✔️ Verification

Added unit tests for service functions with mock repository.

🏕️ (Optional) Future Work / Notes

N/A

thaninbew and others added 2 commits October 18, 2025 02:17
- Remove domain DTO files --- now going to use controller's DTO files for consistency and to prevent confusion.
- Update service to use DTOs with flat structure (not using stored)
- Fix enum references to use PascalCase (DonationType.ONE_TIME)
- Move test file to standard location alongside service --- this was my bad and was an inconsistency in my ticket writing.
- Update test expectations to match flat DTO structure
- Add missing entity fields to test mocks
- Fix linting issues (remove unused imports)

All tests passing (50/50). Service now returns correct DTO structures.
Copy link
Collaborator

@thaninbew thaninbew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My changes:
I made these changes since we needed to keep the codebase clean, consistent and follow best practices. I did remove the DTO files that were previously assigned. They were needed for the service file to be made whilst we were collaborating in parallel, but now that we have two DTOs (for controller and service) it's better to just keep one to avoid confusion. It was nothing done wrong on your part!

  • Remove domain DTO files --- now going to use controller's DTO files for consistency and to prevent confusion.
  • Update service to use DTOs with flat structure (not using stored)
  • Fix enum references to use PascalCase (DonationType.ONE_TIME)
  • Move test file to standard location alongside service --- this was my bad and was an inconsistency in my ticket writing.
  • Update test expectations to match flat DTO structure
  • Add missing entity fields to test mocks
  • Fix linting issues (remove unused imports)

stored: my recommendation is to not use it for this because it adds unnecessary complexity and makes the API inconsistent.

Changes requested:

  • Remove email validation from service - since DTO now has @isEmail() decorator
  • Fix findPublic() logic - Should return ALL donations with privacy applied, not just ones with public dedications. What this function does is it returns public facing data (we'd remove sensitive info like emails) but based on whether showDedicationPublicly is checked or not we'd choose whether to include that.

Example scenario:

Donation A: Anonymous, no dedication → Should show with hidden name
Donation B: Public donor, private dedication → Should show name but hide message
Donation C: Public donor, public dedication → Show everything
Current code only returns Donation C. Should return all three with appropriate privacy filters

Here's a more specific example for our codebase:
image
:

  • rewrite getTotalDonations() - Use SQL SUM()/COUNT() instead of fetching all data and using .reduce(). this is important for performance so all the calculations can be done in the db instead.
  • Add dedication message validation - Can't show dedication publicly without a message

I know it's a lot - please feel free to reach out for clarification!

@thaninbew thaninbew force-pushed the gr-donations-service-domain-dtos branch from 57df9c4 to 6ce1bd9 Compare October 19, 2025 17:22
@thaninbew
Copy link
Collaborator

thaninbew commented Nov 7, 2025

Changes Made (merged service and controller branches)

1. Service Layer (donations.service.ts)

  • service layer now using domain types, and the mapper handles the conversion from DTOs.
  • create() now returns DomainDonation instead of DonationResponseDto.
  • findPublic() now accepts an optional limit parameter and returns domain objects.
  • Preserved all validation logic (amount > 0, recurring interval, dedication message).
  • Added type conversions between domain strings and TypeORM enums at the database boundary.
  • Fixed raw SQL query to correctly reference the donations table.

2. Service Tests (donations.service.spec.ts)

  • Updated test data from CreateDonationDto to CreateDonationRequest.
  • Changed mock data to use lowercase string literals ('one_time') instead of enums.
  • Adjusted expectations to match domain type returns.

3. Database & Entity (donation.entity.ts, data-source.ts, migration)

  • Added explicit @Entity('donations') to entity classes.
  • Removed PluralNamingStrategy, unnecessary baggage, now use literal table name.
  • Fixed migration to create the donations table (plural) consistent with entity configuration.
  • Enums now store lowercase string values consistent with domain types.

All tests passing

@thaninbew thaninbew merged commit 28e9c06 into main Nov 7, 2025
4 checks passed
@thaninbew thaninbew deleted the gr-donations-service-domain-dtos branch November 7, 2025 05:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DonationsService (business logic and tests) (Part 2)

4 participants