ali-ahnaf / ali-ahnaf/pocket_pixel

Send push notifications for debts due tomorrow and today

未關閉
#279 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
backend unit-tests up for grabs
主要語言
TypeScript
星號
14
分支
91
PR 合併指標
30 天內沒有已合併 PR

描述

### Context / background 📚
This app lets users track **debts** (money owed, called "dues" in the code) with an optional `dueDate`. It already has a working push-notification system: when a user opts in from Settings, the server can send a browser push notification to their device. You can see it in action in `packages/api/src/services/gmail.service.ts` (search for `this.push.notify`), which calls a reusable method `PushService.notify(userId, payload)` defined in `packages/api/src/services/push.service.ts`. The app also already runs a few background jobs on a schedule ("cron jobs") — see `packages/api/src/scheduler/backup-scheduler.ts` for a simple example, and `packages/api/src/scheduler/gmail-watch-scheduler.ts` for one that runs once a day.

### Problem / goal 🎯
Right now, nothing reminds a user that a debt is coming due. We want the server to automatically send a push notification to a user:
- 1 day **before** a debt's due date, and
- again **on** the due date itself.

### Suggested approach 🛠️
1. Look at `packages/api/src/entities/Debt.entity.ts` — debts have `dueDate` (a `YYYY-MM-DD` string), `completed` (boolean), `userId`, and are soft-deleted (`deletedAt`).
2. Add a query method to `packages/api/src/repositories/debts.repository.ts` that finds incomplete, non-deleted debts whose `dueDate` matches a given date (or list of dates — today and tomorrow).
3. Create a new scheduler file `packages/api/src/scheduler/debt-due-scheduler.ts`, modeled on `packages/api/src/scheduler/backup-scheduler.ts`. It should run once a day (e.g. via `node-cron`'s `'0 8 * * *'`) and:
- Compute today's date and tomorrow's date as `YYYY-MM-DD` strings.
- Fetch debts due on either date using the new repository method.
- For each debt found, call the existing `pushService.notify(debt.userId, { title, body, url: '/debts' })` — no changes needed to the push service itself.
4. Register the new scheduler's start function in `packages/api/src/index.ts`, next to the other `start*Scheduler()` calls inside the `AppDataSource.initialize().then(...)` block.
5. Add a Jest unit test under `packages/api/src/tests/` covering: a debt due tomorrow triggers a notification, a debt due today triggers a notification, and a debt due on any other day (or already completed/deleted) does not.

### Acceptance criteria ✅
- [ ] A debt with `dueDate` equal to tomorrow triggers exactly one push notification to its owner.
- [ ] A debt with `dueDate` equal to today triggers exactly one push notification to its owner.
- [ ] Completed or soft-deleted debts are excluded, even if their `dueDate` matches.
- [ ] The job runs automatically once per day without manual triggering (registered in `index.ts` on server boot).
- [ ] Unit tests added and `npm run test:api` passes.
- [ ] No changes made to `PushService`, the `Debt` entity's existing fields, or unrelated routes/services.

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

Start with packages/api/src/entities/Debt.entity.ts and packages/api/src/repositories/debts.repository.ts, then compare the scheduler examples in packages/api/src/scheduler/backup-scheduler.ts and gmail-watch-scheduler.ts. Add debt-due-scheduler.ts, register it in packages/api/src/index.ts, and add a Jest test under packages/api/src/tests/; done means today and tomorrow notify once, excluded debts do not notify, and npm run test:api passes.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
nodejs, typescript
領域
api, backend, databases, testing
Issue 類型
功能
難度
3/5
預估耗時
1-2 天
活躍度
冷清
描述清晰度
描述清楚
新手友好度
78/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。