Implement soft-delete for clients, projects, and time entries

Replace hard deletes with deletedAt timestamp flags on all three entities.
Deleting a client or project only sets its own deletedAt; child records are
excluded implicitly by filtering on parent deletedAt in every read query.
Raw SQL statistics queries also filter out soft-deleted parents.
FK ON DELETE CASCADE removed from Project→Client and TimeEntry→Project.
This commit is contained in:
simon.franken
2026-02-23 15:21:13 +01:00
parent 685a311001
commit 1a7d13d5b9
6 changed files with 97 additions and 40 deletions

View File

@@ -5,14 +5,14 @@ import type { CreateClientInput, UpdateClientInput } from "../types";
export class ClientService {
async findAll(userId: string) {
return prisma.client.findMany({
where: { userId },
where: { userId, deletedAt: null },
orderBy: { name: "asc" },
});
}
async findById(id: string, userId: string) {
return prisma.client.findFirst({
where: { id, userId },
where: { id, userId, deletedAt: null },
});
}
@@ -43,8 +43,9 @@ export class ClientService {
throw new NotFoundError("Client not found");
}
await prisma.client.delete({
await prisma.client.update({
where: { id },
data: { deletedAt: new Date() },
});
}
}