Skip to content

Commit

Permalink
fix: soft delete tasks instead of hard delete
Browse files Browse the repository at this point in the history
  • Loading branch information
vuvincent committed Sep 24, 2023
1 parent a013671 commit a2b96d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion apps/api-v2/src/routers/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand All @@ -32,6 +34,7 @@ export const buildTasksRouter = () => {
],
where: {
userId: authCtx.sub,
deletedAt: null,
},
});
return res.status(200).json(
Expand Down Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-v2/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function Home() {
ref={taskListRef}
>
<hr className="w-64" />
{memoizedTasksView.length === 0 && (
{undoneTasks.length === 0 && (
<div className="w-64">
<p className="text-slate-400 text-[16px] text-center">
No tasks yet. Press <Kbd>c</Kbd> to create a task, or go to the
Expand Down

1 comment on commit a2b96d6

@vercel
Copy link

@vercel vercel bot commented on a2b96d6 Sep 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.