Add cancel (discard) timer feature
Allows users to discard a running timer without creating a time entry.
A trash icon in the timer widget reveals a confirmation step ('Discard / Keep')
to prevent accidental data loss. Backend exposes a new DELETE /api/timer
endpoint that simply deletes the ongoingTimer row.
This commit is contained in:
@@ -48,6 +48,16 @@ router.put(
|
||||
}
|
||||
);
|
||||
|
||||
// DELETE /api/timer - Cancel (discard) the ongoing timer without creating a time entry
|
||||
router.delete('/', requireAuth, async (req: AuthenticatedRequest, res, next) => {
|
||||
try {
|
||||
await timerService.cancel(req.user!.id);
|
||||
res.status(204).send();
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
// POST /api/timer/stop - Stop timer
|
||||
router.post(
|
||||
'/stop',
|
||||
|
||||
@@ -138,6 +138,15 @@ export class TimerService {
|
||||
});
|
||||
}
|
||||
|
||||
async cancel(userId: string) {
|
||||
const timer = await this.getOngoingTimer(userId);
|
||||
if (!timer) {
|
||||
throw new NotFoundError("No timer is running");
|
||||
}
|
||||
|
||||
await prisma.ongoingTimer.delete({ where: { userId } });
|
||||
}
|
||||
|
||||
async stop(userId: string, data?: StopTimerInput) {
|
||||
const timer = await this.getOngoingTimer(userId);
|
||||
if (!timer) {
|
||||
|
||||
Reference in New Issue
Block a user