Skip to content

Commit d495123

Browse files
committed
Add docs in user and tasks
1 parent 58e2364 commit d495123

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed

src/core/domain/task.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export type TaskUpdateStatusCommand = {
2525
status: TaskStatus
2626
}
2727

28+
/**
29+
* The `TaskRepository` is an abstraction that represents a storage of tasks.
30+
* Its implementation is part of the infrastructure layer.
31+
*/
2832
export interface TaskRepository {
2933
get(id: string): Promise<Task | null>
3034
getAll(userId?: string): Promise<Task[]>
@@ -34,13 +38,60 @@ export interface TaskRepository {
3438
delete(id: string): Promise<boolean>
3539
}
3640

41+
/**
42+
* The `TaskUseCases` is a service that is responsable to manage all the `Task` entities on the platform.
43+
* Each Task has a owner defined by the `userId` property which limits the access to all the users.
44+
* A Task can be handled only by the user owner or a super user.
45+
*/
3746
export interface TaskUseCases {
47+
/**
48+
* Get a Task by a given id based on the current user permissions.
49+
* @param id Task id.
50+
* @returns Existing task or an error when it does not exists or user is not authorized.
51+
*/
3852
getTask(id: string): Promise<Task>
53+
54+
/**
55+
* Get a list of all tasks based on the current user.
56+
* @returns Async result containing a list of tasks allowed by the current user.
57+
*/
3958
getAllTasks(): Promise<Task[]>
59+
60+
/**
61+
* Get a collection of tasks based on the status.
62+
* @param status Status of the Tasks defined by `TaskStatus` enum.
63+
* @returns Async result containing a collection of tasks.
64+
*/
4065
getTasksByStatus(status: TaskStatus): Promise<Task[]>
66+
67+
/**
68+
* Add a new tasks for the current user.
69+
* @param command Valida command representing a Task.
70+
* @returns Async result containing a new Task.
71+
*/
4172
addNewTask(command: TaskCommand): Promise<Task>
73+
74+
/**
75+
* Update an existing Task by a given id based on the current user permissions.
76+
* @param id Id of the task to be updated.
77+
* @param command Valid command representing a Task.
78+
* @returns Async result containing the updated Task. This operation can also throw an error based on the current user permissions.
79+
*/
4280
updateExistingTask(id: string, command: TaskCommand): Promise<Task>
81+
82+
/**
83+
* Update the status of a task. Useful when a user just want to move the Task to a different state. Only owners and admin can change it.
84+
* @param id Id of the task.
85+
* @param status New state of the task.
86+
* @returns Async result containing the updated task. This operation can also throw an error depending on the user permissions.
87+
*/
4388
updateStatus(id: string, status: TaskStatus): Promise<Task>
89+
90+
/**
91+
* Delete an existing Task by the id.
92+
* @param id Task Id.
93+
* @returns Async result containing if the delete operation succeed. This operation can also throw an error depending on the user permissions.
94+
*/
4495
deleteTask(id: string): Promise<boolean>
4596
}
4697

src/core/domain/user.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,24 @@ export type UserSession = {
3131
ipAddress?: string
3232
}
3333

34+
/**
35+
* The `UserUseCases` represents the user-cases for `User` entity.
36+
* It holds all the operations around the users including the get user details and part of the authentication process.
37+
*/
3438
export interface UserUseCases {
35-
authenticateUser(input: AuthenticateUserInput): Promise<User>
39+
/**
40+
* Get a User by a given id.
41+
* @param id User id.
42+
* @returns Async result containing a User instance. This operation can also throw an error when the user does not exists.
43+
*/
3644
getUserById(id: string): Promise<User | null>
45+
46+
/**
47+
* Validate a user input model for authentication process.
48+
* @param input User authentication model.
49+
* @returns Async result containing the user when the operation succeed. This operation can also throw an error when the user does not exists or the credentials does not matches.
50+
*/
51+
authenticateUser(input: AuthenticateUserInput): Promise<User>
3752
}
3853

3954
export interface CurrentUser {

src/core/use-cases/task-use-cases.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { CurrentUser } from '../domain/user.js'
55
import { TaskPrismaRepository } from '../infrastructure/task-repository.js'
66

77
/**
8-
* The `TaskService` is a service that is responsable to manage all the `Task` entities on the platform.
8+
* The `TaskService` is a service that implements the `TaskUseCases` which is responsable to manage all the `Task` entities on the platform.
99
* This service depends on an abstract `repository` and a user `session` representation.
1010
* Each Task has a owner defined by the `userId` property which limits the access to all the users.
11-
* A Task can be handled only by the user owner or admin user.
11+
* A Task can be handled only by the user owner or a super user.
1212
*/
1313
export class TaskService implements TaskUseCases {
1414
/**

0 commit comments

Comments
 (0)