-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.repository.ts
More file actions
26 lines (25 loc) · 1.23 KB
/
Copy pathtasks.repository.ts
File metadata and controls
26 lines (25 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { Task } from './entities/task.entity';
import { TaskPage, TaskQuery, TaskStats } from './tasks.types';
/**
* Storage port for tasks. The service depends only on this abstraction; the
* concrete adapter is bound in {@link TasksModule}.
*
* Two deliberate decisions make it future-proof against a real database:
*
* 1. **Every method is async.** In-memory work resolves immediately, but the
* signatures already return Promises — so introducing a DB never ripples
* `await`s through the service and controller.
* 2. **Querying lives here, not in the service.** `findMany` takes a domain
* {@link TaskQuery} and is responsible for filtering, sorting, pagination
* and counting; `getStats` does aggregation. A SQL adapter pushes these
* down to `WHERE/ORDER BY/LIMIT/GROUP BY` instead of loading every row.
*
* Net effect: adding Postgres is a new class implementing these four methods
* plus a one-line provider swap — the service, controller and DTOs are untouched.
*/
export abstract class TasksRepository {
abstract findById(id: string): Promise<Task | null>;
abstract findMany(query: TaskQuery): Promise<TaskPage>;
abstract save(task: Task): Promise<Task>;
abstract getStats(): Promise<TaskStats>;
}