Skip to content

feat:base setup for donation backend service - #11

Merged
mubarak23 merged 1 commit into
devfrom
ft_donation_setup
Jul 23, 2025
Merged

mubarak23 merged 1 commit into
devfrom
ft_donation_setup

Conversation

@mubarak23

@mubarak23 mubarak23 commented Jul 23, 2025

Copy link
Copy Markdown
Contributor

close #10
This PR sets up the foundational components for handling donations, including the database entity (CampaignEntity), input validation via Zod, and a structured response DTO for returning donation-related data to clients.

Summary by CodeRabbit

  • New Features

    • Introduced validation for donation creation inputs, ensuring correct formats for campaign IDs, Ethereum addresses, amounts, and transaction hashes.
    • Added standardized API response structure for donation-related endpoints.
    • Implemented a new campaign entity to manage campaign data, including automatic ID generation and timestamping.
  • Bug Fixes

    • Improved input validation to prevent invalid or malformed donation data submissions.

@coderabbitai

coderabbitai Bot commented Jul 23, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This change introduces foundational components for the donation contribution service. It adds a TypeORM entity for campaigns, TypeScript DTOs for API responses, and a Zod validation schema for donation creation input. These additions establish the structure for handling campaign data, validating donation requests, and standardizing API responses.

Changes

File(s) Change Summary
src/components/v1/Donation/donation.dto.ts Added CampaignResponseDto and generic ApiResponse<T> TypeScript interfaces.
src/components/v1/Donation/donation.entity.ts Introduced CampaignEntity TypeORM entity with lifecycle hook for UUID assignment.
src/components/v1/Donation/donation.validation.ts Added Zod validation schema createDonationSchema and inferred type alias CreateDonationInput.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Validation
    participant Service
    participant Database

    Client->>Validation: Submit donation creation input
    Validation->>Validation: Validate input with createDonationSchema
    alt Validation passes
        Validation->>Service: Pass validated input
        Service->>Database: Create CampaignEntity
        Database-->>Service: Persisted entity
        Service->>Client: Return ApiResponse<CampaignResponseDto>
    else Validation fails
        Validation->>Client: Return ApiResponse<null> with error message
    end
Loading

Estimated code review effort

2 (~15 minutes)

Poem

In the warren, code takes root,
Entities and DTOs in a tidy suit.
Validation hops in, sharp and keen,
Ensuring donations are crisp and clean.
With every schema, the service grows—
A bunny’s dream, as the project flows! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-23T10_55_14_067Z-debug-0.log

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (7)
src/components/v1/Donation/donation.validation.ts (2)

3-3: Remove unused import.

The ValidationError import appears to be unused in this file.

-import { ValidationError } from "./path-to-validation-error" // reuse if needed

5-6: Validate regex patterns for security and correctness.

The regex patterns look correct, but consider these improvements:

  1. The Ethereum address regex correctly validates the format
  2. The decimal string regex allows integers and decimals but doesn't prevent leading zeros or excessive decimal places

Consider making the decimal regex more restrictive to prevent edge cases:

-const decimalStringRegex = /^\d+(\.\d+)?$/
+const decimalStringRegex = /^(?:0|[1-9]\d*)(?:\.\d{1,18})?$/

This prevents leading zeros and limits decimal places to 18 (typical for Ethereum tokens).

src/components/v1/Donation/donation.dto.ts (1)

10-14: Consider enhancing the generic ApiResponse interface.

The current design is functional but could be enhanced for better error handling and API consistency.

Consider this enhanced version:

-export interface ApiResponse<T> {
-  data: T | null
-  success: boolean
-  message?: string
-}
+export interface ApiResponse<T> {
+  data: T | null
+  success: boolean
+  message?: string
+  error?: {
+    code: string
+    details?: string
+  }
+  timestamp?: string
+}

This provides better error context and API traceability.

src/components/v1/Donation/donation.entity.ts (4)

12-13: Consider using UUID type for primary key.

Using text type for UUID primary key works but isn't optimal for performance and storage.

-  @PrimaryColumn("text", { name: "campaign_id" })
+  @PrimaryColumn("uuid", { name: "campaign_id" })

This requires ensuring your database supports UUID type and the uuid utility generates valid UUIDs.


18-19: Consider using numeric types for amounts and addresses.

Using text for targetAmount and donationToken (Ethereum address) may not be optimal:

  1. targetAmount could use decimal or numeric type for better precision
  2. donationToken as an Ethereum address could benefit from a specific length constraint
-  @Column("text", { name: "target_amount", nullable: false })
+  @Column("decimal", { name: "target_amount", nullable: false, precision: 78, scale: 18 })
   targetAmount: string

-  @Column("text", { name: "donation_token", nullable: false })
+  @Column("varchar", { name: "donation_token", nullable: false, length: 42 })

Also applies to: 22-22


10-25: Consider adding database indexes for performance.

For a donation system, you'll likely query by various fields. Consider adding indexes for better performance.

 @Entity("Campaign")
+@Index("idx_campaign_ref", ["campaignRef"])
+@Index("idx_donation_token", ["donationToken"])
+@Index("idx_transaction_hash", ["transactionHash"])
 export class CampaignEntity {

Don't forget to import Index from TypeORM.


42-42: Consider removing default export in favor of named export.

The class is already exported as a named export. The default export is redundant and can cause confusion.

-export default CampaignEntity
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3bf84d3 and 7921157.

📒 Files selected for processing (3)
  • src/components/v1/Donation/donation.dto.ts (1 hunks)
  • src/components/v1/Donation/donation.entity.ts (1 hunks)
  • src/components/v1/Donation/donation.validation.ts (1 hunks)
🔇 Additional comments (5)
src/components/v1/Donation/donation.validation.ts (2)

17-17: Verify transaction hash regex accuracy.

The transaction hash regex enforces exactly 64 hex characters after '0x', which is correct for Ethereum transaction hashes.


19-22: Network enum verified and correctly imported

  • The Network enum is defined in src/types/enums.ts (lines 16–23).
  • It’s properly imported in src/components/v1/Donation/donation.validation.ts (line 2).

No further action required.

src/components/v1/Donation/donation.dto.ts (1)

1-8: LGTM! DTO structure aligns with entity design.

The CampaignResponseDto interface correctly mirrors the CampaignEntity structure, ensuring consistent data transfer between database and API responses.

src/components/v1/Donation/donation.entity.ts (2)

34-39: LGTM! UUID generation logic is correct.

The @BeforeInsert() hook properly generates a UUID only if campaignId is not already set, preventing overwriting existing IDs.


8-8: Confirmed uuid utility implementation

  • Located in src/utils/index.ts:
    export const uuid = () => randomUUID();
  • Leverages Node.js crypto.randomUUID() to produce valid v4 UUIDs.

No changes required.

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.

Base Setup for Donation Contribution Service

1 participant