ali-ahnaf / ali-ahnaf/pocket_pixel

Send push notifications for debts due tomorrow and today

Aberta
#279 0 comentários 0 reações 0 responsáveis Ver no GitHub
backend unit-tests up for grabs
Linguagem predominante
TypeScript
Estrelas
14
Forks
91
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

### 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.

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
nodejs, typescript
Domínio
api, backend, databases, testing
Tipo de issue
Funcionalidade
Dificuldade
3/5
Tempo estimado
1-2 dias
Status de atividade
Pouca atividade
Clareza
Claramente especificada
Facilidade para iniciantes
78/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.