Skip to content

feat: add wallets model - #41

Merged
daniloamsilva merged 1 commit into
mainfrom
feat/add-wallets-model
Jul 22, 2026
Merged

daniloamsilva merged 1 commit into
mainfrom
feat/add-wallets-model

Conversation

@daniloamsilva

Copy link
Copy Markdown
Owner

This pull request introduces a new Wallet domain model and integrates wallet creation into the user registration flow. It adds the necessary entity, repository interfaces and implementations (in-memory and PostgreSQL), a migration for the wallets table, and updates the user creation logic and tests to ensure each new user receives a default wallet.

Wallet Domain Model and Persistence

  • Added a new Wallet entity with properties such as userId, name, initialBalance, isDefault, and timestamps (createdAt, updatedAt, deletedAt). (src/entities/wallet/wallet.entity.ts)
  • Created repository interface (WalletsRepositoryInterface) and both in-memory and PostgreSQL implementations for wallet persistence. (src/repositories/wallets/wallets.repository.interface.ts, src/repositories/wallets/wallets-in-memory.repository.ts, src/repositories/wallets/wallets-postgres.repository.ts) [1] [2] [3]
  • Added a database migration to create the wallets table with relevant fields, constraints, and indexes, including a unique constraint for default wallets per user. (src/infra/database/migrations/1784669759347_create-wallets-table.js)

User Creation Flow Updates

  • Updated CreateUserService to inject the WalletsRepositoryInterface and automatically create a default wallet ("Carteira") for each new user during registration. (src/models/users/use-cases/create-user/create-user.service.ts, src/models/users/users.module.ts, src/repositories/providers.enum.ts) [1] [2] [3] [4] [5] [6]

Testing Enhancements

  • Enhanced the user creation service test to verify that a default wallet is created for each new user and that its properties are set correctly. (src/models/users/use-cases/create-user/create-user.service.spec.ts) [1] [2] [3]

Copilot AI 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.

Pull request overview

This PR introduces a new Wallet domain model with persistence (in-memory + PostgreSQL) and wires automatic default wallet creation into the user registration flow, including a DB migration and test updates to validate the behavior.

Changes:

  • Added Wallet entity plus wallet repository interface and implementations (Postgres + in-memory).
  • Added migration to create the wallets table, including indexes/constraints.
  • Updated user creation flow (and tests) to create a default wallet for each new user.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/entities/wallet/wallet.entity.ts Introduces the Wallet domain entity and its properties.
src/repositories/wallets/wallets.repository.interface.ts Defines wallet persistence contract (save, findByUserId).
src/repositories/wallets/wallets-in-memory.repository.ts Adds in-memory wallet persistence for tests/local usage.
src/repositories/wallets/wallets-postgres.repository.ts Adds PostgreSQL wallet persistence using DatabaseService.
src/infra/database/migrations/1784669759347_create-wallets-table.js Creates the wallets table and related indexes/constraints.
src/repositories/providers.enum.ts Adds DI token for wallets repository.
src/models/users/users.module.ts Registers WalletsPostgresRepository provider in Users module.
src/models/users/use-cases/create-user/create-user.service.ts Creates a default wallet during user registration.
src/models/users/use-cases/create-user/create-user.service.spec.ts Extends create-user test to assert wallet creation and fields.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/repositories/wallets/wallets-in-memory.repository.ts
Comment thread src/repositories/wallets/wallets-in-memory.repository.ts
Comment thread src/infra/database/migrations/1784669759347_create-wallets-table.js
Comment thread src/repositories/wallets/wallets-postgres.repository.ts
Comment thread src/repositories/wallets/wallets-postgres.repository.ts
@daniloamsilva
daniloamsilva force-pushed the feat/add-wallets-model branch from 141f4b3 to e671104 Compare July 22, 2026 02:19
@daniloamsilva
daniloamsilva merged commit 004f067 into main Jul 22, 2026
2 checks passed
@daniloamsilva
daniloamsilva deleted the feat/add-wallets-model branch July 24, 2026 00:02
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.

2 participants