Skip to content

refactor(task): Move task read logic into package service - #136

Merged
KiwiGaze merged 2 commits into
stagingfrom
KiwiGaze/extract-auth-package
Feb 17, 2026
Merged

refactor(task): Move task read logic into package service#136
KiwiGaze merged 2 commits into
stagingfrom
KiwiGaze/extract-auth-package

Conversation

@KiwiGaze

@KiwiGaze KiwiGaze commented Feb 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • Extract task read queries into packages/task with a dedicated repository and server read service.
  • Move shared task read types (TaskSortField, TaskFilter, TaskQueryOptions, TaskListResult) into package exports.
  • Update task page and task API routes to use createTaskReadService instead of legacy lib/tasks read helpers.
  • Add repository unit tests for filtering, sorting, pagination, and user scoping.

Testing

  • Not run in this session.

Summary by CodeRabbit

  • New Features
    • Exposes typed task query options (sorting, filtering, pagination) for client use and adds structured paginated task results.
  • Refactor
    • Switched internal task data access to a dedicated read service/repository for more consistent and maintainable task retrieval.
  • Tests
    • Added a test configuration for the task package.

@coderabbitai

coderabbitai Bot commented Feb 17, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉


Walkthrough

Refactors task read logic into a new service package (@simplifying/task): adds task read repository/service and server types, removes legacy lib/tasks exports, updates API routes and UI components to use createTaskReadService(prisma) and the package-level types.

Changes

Cohort / File(s) Summary
Package types & exports
packages/task/src/types.ts, packages/task/src/index.ts, packages/task/src/types.server.ts, packages/task/src/server.ts
Added TaskSortField, TaskFilter, TaskQueryOptions (client types) and TaskListResult (server type); re-exported types and new server exports (createTaskReadService, TaskReadService, etc.).
Read repo & service implementation
packages/task/src/repositories/task-read.repository.ts, packages/task/src/services/server-task-read-service.ts
New Prisma-backed task read repository factory and a server-side read service exposing listTasks, listTasksHistory, and findTaskById.
Prisma server typing
packages/prisma/src/server.ts
Added TaskReadPrismaClient interface exposing task and $transaction for read-only contexts.
Task package config
packages/task/package.json, packages/task/vitest.config.ts
Added workspace deps (@simplifying/constants, @simplifying/prisma) and new Vitest config for the task package.
API route updates
app/api/tasks/route.ts, app/api/tasks/[id]/route.ts, app/api/tasks/[id]/complete/route.ts, app/api/tasks/history/route.ts
Replaced direct getTaskById / listTasks / listTasksHistory calls with createTaskReadService(prisma) and calls on the resulting taskReadService instance.
Page & components
app/(protected)/task/page.tsx, app/(protected)/task/components/task-list.tsx, app/(protected)/task/components/task-sort-dropdown.tsx
Switched to service-based listing in page; moved TaskSortField type imports from local lib/types to @simplifying/task.
Local cleanup
lib/tasks.ts, lib/types/tasks.ts
Removed listTasks, listTasksHistory, getTaskById functions and removed TaskSortField, TaskFilter, and TaskQueryOptions types from local types (migrated to package).

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Route as API Route
  participant Service as TaskReadService
  participant Repo as TaskReadRepository
  participant Prisma as Prisma

  Client->>Route: request list/find task(s)
  Route->>Service: createTaskReadService(prisma)
  Route->>Service: call listTasks / findTaskById / listTasksHistory
  Service->>Repo: delegate call with normalized options
  Repo->>Prisma: prisma.task.findMany / count / findFirst
  Prisma-->>Repo: results
  Repo-->>Service: tasks + pagination
  Service-->>Route: TaskListResult / Task
  Route-->>Client: response (serialized)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor(task): Move task read logic into package service' accurately summarizes the main change: extracting task read queries and logic into a dedicated package service.
Peer Dependency Consistency ✅ Passed All peer dependency declarations are consistent across packages and match root configuration with correct workspace package placement.
Api Contract Layer Conventions ✅ Passed All modified API route handlers strictly adhere to API contract layer conventions with proper apiSuccess usage, correct parameter ordering, appropriate error handling, and timestamp serialization.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch KiwiGaze/extract-auth-package

Comment @coderabbitai help to get the list of available commands and usage tips.

The task package lacked its own vitest.config.ts, causing vitest to
fall back to the root config which references a setup file that
doesn't exist relative to the package directory.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/task/src/repositories/task-read.repository.ts (1)

1-6: Remove unused Task import.

The Task type is imported but not directly used in this file. The return type TaskListResult (which contains Task[]) is imported from types.server.ts, so the explicit Task import here is redundant.

♻️ Suggested fix
-import type { Prisma, Task } from "@prisma/client";
+import type { Prisma } from "@prisma/client";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/task/src/repositories/task-read.repository.ts` around lines 1 - 6,
Remove the unused Task type import from the top of task-read.repository.ts:
eliminate "Task" from the import list that currently reads import type { Prisma,
Task } from "@prisma/client"; since the file uses Task only indirectly via
TaskListResult (imported from ../types.server), keep the Prisma import if used
and adjust the import to import type { Prisma } from "@prisma/client"; so there
are no unused imports.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/task/src/repositories/task-read.repository.ts`:
- Around line 1-6: Remove the unused Task type import from the top of
task-read.repository.ts: eliminate "Task" from the import list that currently
reads import type { Prisma, Task } from "@prisma/client"; since the file uses
Task only indirectly via TaskListResult (imported from ../types.server), keep
the Prisma import if used and adjust the import to import type { Prisma } from
"@prisma/client"; so there are no unused imports.

@KiwiGaze
KiwiGaze merged commit 614df4c into staging Feb 17, 2026
4 checks passed
@KiwiGaze
KiwiGaze deleted the KiwiGaze/extract-auth-package branch February 22, 2026 14:17
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.

1 participant