-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: ✨ add task domain behaviors #117
Conversation
WalkthroughThe changes in this pull request involve significant modifications to the Changes
Possibly related PRs
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (6)
libs/tasks/domain/src/lib/entities/user-task.entity.ts (3)
16-25
: Consider Adding Validation increate
MethodThe
create
method currently does not validate the input parametersid
,userId
, andtaskId
. Adding validation can prevent the creation ofUserTask
instances with invalid data.Possible implementation:
static create(id: string, userId: string, taskId: string): UserTask { + if (!id || !userId || !taskId) { + throw new Error('Invalid parameters for UserTask creation.'); + } return new UserTask( id, userId, taskId, new Date(), null, TaskStatusEnum.TODO, ); }
30-42
: Consider UpdatingupdatedAt
Even When Status Is UnchangedIn the
markAsInProgress
method, if the task is already in progress, the method returnsthis
without updating theupdatedAt
timestamp. Consider updating theupdatedAt
timestamp to reflect the action, even if the status remains the same.Possible implementation:
if (this.status === TaskStatusEnum.IN_PROGRESS) { - return this; + return new UserTask( + this.id, + this.userId, + this.taskId, + this.createdAt, + new Date(), + this.status, + ); }
47-59
: Same Concern withmarkAsDone
MethodSimilarly, in the
markAsDone
method, consider updating theupdatedAt
timestamp even if the task is already marked as done.Possible implementation:
if (this.status === TaskStatusEnum.DONE) { - return this; + return new UserTask( + this.id, + this.userId, + this.taskId, + this.createdAt, + new Date(), + this.status, + ); }libs/tasks/domain/src/lib/entities/task.entity.ts (1)
12-19
: Consider Adding Validation increate
MethodThe
create
method does not currently validate input parameters such asid
,title
, andcategories
. Adding validation can ensure that only validTask
instances are created.Possible implementation:
static create( id: string, title: string, description: string | null, categories: string[], ): Task { + if (!id || !title || !categories) { + throw new Error('Invalid parameters for Task creation.'); + } return new Task(id, title, description, categories); }libs/tasks/domain/src/lib/entities/task.entity.spec.ts (1)
4-33
: Consider Adding Tests for Invalid ParametersCurrently, the tests do not cover scenarios where invalid parameters are passed to
Task.create()
. Consider adding test cases to verify that the method handles invalid inputs correctly.Example test case:
it('should throw an error when creating a task with invalid parameters', () => { expect(() => Task.create('', '', null, null)).toThrowError('Invalid parameters for Task creation.'); });libs/tasks/domain/src/lib/entities/user-task.entity.spec.ts (1)
5-51
: Consider Adding Tests for Invalid Input and Edge CasesTo strengthen the test suite, consider adding test cases for invalid input parameters in
UserTask.create()
and edge cases inmarkAsInProgress
andmarkAsDone
.Example test case:
it('should throw an error when creating a user task with invalid parameters', () => { expect(() => UserTask.create('', '', '')).toThrowError('Invalid parameters for UserTask creation.'); });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
libs/tasks/domain/src/lib/entities/task.entity.spec.ts
(1 hunks)libs/tasks/domain/src/lib/entities/task.entity.ts
(1 hunks)libs/tasks/domain/src/lib/entities/user-task.entity.spec.ts
(1 hunks)libs/tasks/domain/src/lib/entities/user-task.entity.ts
(1 hunks)
🔇 Additional comments (4)
libs/tasks/domain/src/lib/entities/user-task.entity.ts (1)
4-11
: Good Use of Encapsulation with Private Constructor and Static Factory Method
Changing the constructor to private
and introducing the create
static method enhances encapsulation and controls object instantiation.
libs/tasks/domain/src/lib/entities/task.entity.ts (1)
2-8
: Excellent Use of Factory Method Pattern
Changing the constructor to private
and introducing the create
static method improves encapsulation and allows for centralized object creation.
libs/tasks/domain/src/lib/entities/task.entity.spec.ts (1)
4-33
: Tests Updated Correctly to Use Factory Method
The test cases have been appropriately updated to use Task.create()
, reflecting the change in object instantiation.
libs/tasks/domain/src/lib/entities/user-task.entity.spec.ts (1)
5-51
: Comprehensive Tests for UserTask
Entity
The test suite thoroughly tests the creation and state transitions of UserTask
, including the new methods markAsInProgress
and markAsDone
.
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.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (2)
libs/tasks/application/src/lib/user-tasks.service.ts (2)
5-9
: Consider adding pagination and filtering parametersThe
findMany
method currently only accepts a userId parameter. For better scalability and performance, consider adding:
- Pagination parameters (limit, offset/cursor)
- Filtering options (status, date range, etc.)
- Sorting parameters
This will be especially important as the number of tasks grows.
Example signature:
async findMany( userId: string, options?: { limit?: number; offset?: number; status?: TaskStatusEnum[]; sortBy?: 'createdAt' | 'updatedAt'; sortOrder?: 'asc' | 'desc'; } ): Promise<{ items: UserTask[]; total: number; hasMore: boolean; }>
8-8
: Implement the TODO methodsAll methods are currently placeholder implementations. Given that the PR adds task domain behaviors and the AI summary indicates new UserTask entity features (status management, etc.), these methods should be implemented to utilize the new domain logic.
Would you like me to help implement these methods using the new UserTask.create() factory method and status management features?
Also applies to: 15-16, 22-23
🎉 This PR is included in version 1.17.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Related #99
Summary by CodeRabbit
New Features
create
methods for bothTask
andUserTask
entities to streamline object creation.UserTask
for marking tasks as "In Progress" and "Done", enhancing task management capabilities.Bug Fixes
Documentation
Task
andUserTask
entities, improving maintainability.