fix: soft delete labels

This commit is contained in:
Henry
2025-05-27 21:49:01 +01:00
parent 09211e60c7
commit 59eadfc694
8 changed files with 2131 additions and 5 deletions

View File

@@ -113,6 +113,7 @@ export const getByPublicId = async (
name: true,
colourCode: true,
},
where: isNull(labels.deletedAt),
},
lists: {
columns: {
@@ -244,6 +245,7 @@ export const getBySlug = async (
name: true,
colourCode: true,
},
where: isNull(labels.deletedAt),
},
lists: {
columns: {

View File

@@ -6,6 +6,7 @@ import {
cards,
cardsToLabels,
cardToWorkspaceMembers,
labels,
lists,
workspaceMembers,
} from "@kan/db/schema";
@@ -316,6 +317,7 @@ export const getWithListAndMembersByPublicId = async (
colourCode: true,
name: true,
},
where: isNull(labels.deletedAt),
},
lists: {
columns: {

View File

@@ -1,4 +1,4 @@
import { eq, inArray } from "drizzle-orm";
import { and, eq, inArray, isNull } from "drizzle-orm";
import type { dbClient } from "@kan/db/client";
import { cardsToLabels, labels } from "@kan/db/schema";
@@ -98,10 +98,21 @@ export const update = async (
return result;
};
export const hardDelete = async (db: dbClient, labelId: number) => {
export const softDelete = async (
db: dbClient,
args: {
labelId: number;
deletedAt: Date;
deletedBy: string;
},
) => {
const [result] = await db
.delete(labels)
.where(eq(labels.id, labelId))
.update(labels)
.set({
deletedAt: args.deletedAt,
deletedBy: args.deletedBy,
})
.where(and(eq(labels.id, args.labelId), isNull(labels.deletedAt)))
.returning({ id: labels.id });
return result;