Oouhammmourachid /
Public
ouhammmourachid / todo-api
PublicThe classic todo backend, done properly: per-user lists and todos, due dates, priorities, completion timestamps and a stats endpoint.
- Other
- 0 deploys
- 0 forks
Todo API (beginner friendly)
The classic todo backend, done properly: per-user lists and todos, due dates, priorities, completion timestamps and a stats endpoint.
What you get
- Every user sees only their own lists and todos
- Due dates and low/medium/high priority
completed_atis set and cleared automatically whendonechangesGET /api/todos/statsreturns total, done, open and overdue counts- Deleting a list deletes its todos
Collections
lists
| Field | Type | Notes |
|---|---|---|
title (required) | text | |
color | text | Any CSS color |
owner (required) | relation → users | Set by a hook to the signed-in user |
| Action | Who can do it |
|---|---|
| List / view | owner = @request.auth.id |
| Create | signed-in users |
| Update | owner = @request.auth.id |
| Delete | owner = @request.auth.id |
todos
| Field | Type | Notes |
|---|---|---|
list | relation → lists | Optional |
title (required) | text | |
notes | text | |
done | bool | |
due_date | date | |
priority | select | low, medium, high |
completed_at | date | Set automatically |
owner (required) | relation → users | Set by a hook to the signed-in user |
| Action | Who can do it |
|---|---|
| List / view | owner = @request.auth.id |
| Create | signed-in users |
| Update | owner = @request.auth.id |
| Delete | owner = @request.auth.id |
Hooks
All hooks are in pb_hooks/main.pb.js and commented.
Quick start
import PocketBase from "pocketbase"
const pb = new PocketBase("https://YOUR-INSTANCE.pocketshub.com")
const list = await pb.collection("lists").create({ title: "Groceries" })
const todo = await pb.collection("todos").create({ list: list.id, title: "Milk", priority: "high" })
await pb.collection("todos").update(todo.id, { done: true }) // completed_at is set for you
const open = await pb.collection("todos").getFullList({ filter: "done = false", sort: "due_date" })
const stats = await pb.send("/api/todos/stats", {}) // { total, done, open, overdue }
Notes
- A good first pocket for learning PocketBase API rules and hooks: every file is short and commented.
License
MIT
2 collections, 1 relation. Hover a collection to trace its relations