ali-ahnaf / ali-ahnaf/pocket_pixel
Send push notifications for debts due tomorrow and today
- Vorherrschende Sprache
- TypeScript
- Sterne
- 14
- Forks
- 91
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
### 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.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Bewertung
Dieses Issue wurde noch nicht bewertet.