From a2b96d6a08be4adf27c46dd1a13506e603d10a4c Mon Sep 17 00:00:00 2001 From: snokpok Date: Sat, 23 Sep 2023 17:05:41 -0700 Subject: [PATCH] fix: soft delete tasks instead of hard delete --- apps/api-v2/src/routers/tasks.ts | 8 +++++++- apps/desktop-v2/app/page.tsx | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/api-v2/src/routers/tasks.ts b/apps/api-v2/src/routers/tasks.ts index b5feab9..f1fcba1 100644 --- a/apps/api-v2/src/routers/tasks.ts +++ b/apps/api-v2/src/routers/tasks.ts @@ -18,6 +18,8 @@ export const buildTasksRouter = () => { const authCtx = getAuthContext(req); // get all tasks for the user // sort by earliest one first; ones with no start time last + // also put all the done ones at the end + // do not include deleted tasks (i.e those with deletedAt not null) const tasks = await prisma.task.findMany({ orderBy: [ { @@ -32,6 +34,7 @@ export const buildTasksRouter = () => { ], where: { userId: authCtx.sub, + deletedAt: null, }, }); return res.status(200).json( @@ -141,11 +144,14 @@ export const buildTasksRouter = () => { async (req, res) => { try { const authCtx = getAuthContext(req); - const task = await prisma.task.delete({ + const task = await prisma.task.update({ where: { id: req.params.id, userId: authCtx.sub, }, + data: { + deletedAt: new Date(), + }, }); return res.status(200).json( new SupernovaResponse({ diff --git a/apps/desktop-v2/app/page.tsx b/apps/desktop-v2/app/page.tsx index 1608e80..c6c5fa0 100644 --- a/apps/desktop-v2/app/page.tsx +++ b/apps/desktop-v2/app/page.tsx @@ -107,7 +107,7 @@ function Home() { ref={taskListRef} >
- {memoizedTasksView.length === 0 && ( + {undoneTasks.length === 0 && (

No tasks yet. Press c to create a task, or go to the