feat: add create new checklist modal
This commit is contained in:
@@ -17,7 +17,7 @@ ALTER TABLE "card_checklist_item" ENABLE ROW LEVEL SECURITY;--> statement-breakp
|
||||
CREATE TABLE IF NOT EXISTS "card_checklist" (
|
||||
"id" bigserial PRIMARY KEY NOT NULL,
|
||||
"publicId" varchar(12) NOT NULL,
|
||||
"title" varchar(255) NOT NULL,
|
||||
"name" varchar(255) NOT NULL,
|
||||
"index" integer NOT NULL,
|
||||
"cardId" bigint NOT NULL,
|
||||
"createdBy" uuid,
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"id": "0b7ca39b-1114-4c0d-8e55-d932f40706ba",
|
||||
"id": "957fcb16-856c-4756-ac3b-13f2a0814959",
|
||||
"prevId": "91f9a2fa-31e2-4f3a-bdb9-852292fd7501",
|
||||
"version": "7",
|
||||
"dialect": "postgresql",
|
||||
@@ -1344,8 +1344,8 @@
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"title": {
|
||||
"name": "title",
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "varchar(255)",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
@@ -54,9 +54,9 @@
|
||||
{
|
||||
"idx": 7,
|
||||
"version": "7",
|
||||
"when": 1752582887553,
|
||||
"tag": "20250715123447_AddCardChecklists",
|
||||
"when": 1754511666265,
|
||||
"tag": "20250806202106_glossy_luminals",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
cards,
|
||||
cardsToLabels,
|
||||
cardToWorkspaceMembers,
|
||||
checklists,
|
||||
labels,
|
||||
lists,
|
||||
workspaceMembers,
|
||||
@@ -300,6 +301,24 @@ export const getWithListAndMembersByPublicId = async (
|
||||
},
|
||||
},
|
||||
},
|
||||
checklists: {
|
||||
columns: {
|
||||
publicId: true,
|
||||
name: true,
|
||||
index: true,
|
||||
},
|
||||
where: isNull(checklists.deletedAt),
|
||||
with: {
|
||||
items: {
|
||||
columns: {
|
||||
publicId: true,
|
||||
title: true,
|
||||
completed: true,
|
||||
index: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
list: {
|
||||
columns: {
|
||||
publicId: true,
|
||||
|
||||
41
packages/db/src/repository/checklist.repo.ts
Normal file
41
packages/db/src/repository/checklist.repo.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { and, desc, eq, isNull } from "drizzle-orm";
|
||||
|
||||
import type { dbClient } from "@kan/db/client";
|
||||
import { checklists } from "@kan/db/schema";
|
||||
import { generateUID } from "@kan/shared/utils";
|
||||
|
||||
export const create = async (
|
||||
db: dbClient,
|
||||
checklistInput: {
|
||||
cardId: number;
|
||||
name: string;
|
||||
createdBy: string;
|
||||
},
|
||||
) => {
|
||||
return db.transaction(async (tx) => {
|
||||
const card = await tx.query.checklists.findFirst({
|
||||
where: and(
|
||||
eq(checklists.cardId, checklistInput.cardId),
|
||||
isNull(checklists.deletedAt),
|
||||
),
|
||||
orderBy: desc(checklists.index),
|
||||
});
|
||||
|
||||
const [result] = await tx
|
||||
.insert(checklists)
|
||||
.values({
|
||||
publicId: generateUID(),
|
||||
name: checklistInput.name,
|
||||
createdBy: checklistInput.createdBy,
|
||||
cardId: checklistInput.cardId,
|
||||
index: card ? card.index + 1 : 0,
|
||||
})
|
||||
.returning({
|
||||
id: checklists.id,
|
||||
publicId: checklists.publicId,
|
||||
name: checklists.name,
|
||||
});
|
||||
|
||||
return result;
|
||||
});
|
||||
};
|
||||
@@ -16,7 +16,7 @@ import { users } from "./users";
|
||||
export const checklists = pgTable("card_checklist", {
|
||||
id: bigserial("id", { mode: "number" }).primaryKey(),
|
||||
publicId: varchar("publicId", { length: 12 }).notNull().unique(),
|
||||
title: varchar("title", { length: 255 }).notNull(),
|
||||
name: varchar("name", { length: 255 }).notNull(),
|
||||
index: integer("index").notNull(),
|
||||
cardId: bigint("cardId", { mode: "number" })
|
||||
.notNull()
|
||||
|
||||
Reference in New Issue
Block a user