Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(board): publish atomic column reorders and imported detail updates

Tinacd36e30e5ec
diff --cc apps/api/src/column/controllers/reorder-columns.ts
index 4533d082f,c8f10281e..a2d041f1f
--- a/apps/api/src/column/controllers/reorder-columns.ts
+++ b/apps/api/src/column/controllers/reorder-columns.ts
@@@ -8,29 -7,27 +8,33 @@@ async function reorderColumns
projectId: string,
columns: Array<{ id: string; position: number }>,
) {
-- for (const col of columns) {
-- const [updated] = await db
-- .update(columnTable)
-- .set({ position: col.position })
-- .where(
-- and(eq(columnTable.id, col.id), eq(columnTable.projectId, projectId)),
-- )
-- .returning({ id: columnTable.id });
++ const updated = await db.transaction(async (tx) => {
++ for (const col of [...columns].sort((left, right) =>
++ left.id.localeCompare(right.id),
++ )) {
++ const [updated] = await tx
++ .update(columnTable)
++ .set({ position: col.position })
++ .where(
++ and(eq(columnTable.id, col.id), eq(columnTable.projectId, projectId)),
++ )
++ .returning({ id: columnTable.id });
-- if (!updated) {
-- throw new HTTPException(400, {
-- message: `Column ${col.id} does not belong to this project`,
-- });
++ if (!updated) {
++ throw new HTTPException(400, {
++ message: `Column ${col.id} does not belong to this project`,
++ });
++ }
}
-- }
-- const updated = await db.query.columnTable.findMany({
-- where: eq(columnTable.projectId, projectId),
-- orderBy: (columns, { asc }) => [asc(columns.position)],
++ return tx.query.columnTable.findMany({
++ where: eq(columnTable.projectId, projectId),
++ orderBy: (columns, { asc }) => [asc(columns.position)],
++ });
});
- await publishEvent("project.updated", { projectId: projectId });
++ await publishEvent("project.updated", { projectId });
+
return updated;
}
diff --cc tests/api-integration/column-live-updates.test.ts
index 0f2178d79,000000000..e0e55832a
mode 100644,000000..100644
--- a/tests/api-integration/column-live-updates.test.ts
+++ b/tests/api-integration/column-live-updates.test.ts
@@@ -1,38 -1,0 +1,78 @@@
+import { beforeEach, expect, it, vi } from "vite-plus/test";
++import { eq } from "drizzle-orm";
++import { columnTable } from "../../apps/api/src/database/schema";
+import db from "../../apps/api/src/database";
+import createColumn from "../../apps/api/src/column/controllers/create-column";
+import updateColumn from "../../apps/api/src/column/controllers/update-column";
+import deleteColumn from "../../apps/api/src/column/controllers/delete-column";
+import reorderColumns from "../../apps/api/src/column/controllers/reorder-columns";
+import { resetTestDatabase } from "./helpers/database";
+import {
+ createWorkspaceMember,
+ createProjectFixture,
+} from "./helpers/fixtures";
+const publish = vi.hoisted(() => vi.fn(async () => {}));
+vi.mock("../../apps/api/src/events", () => ({ publishEvent: publish }));
+beforeEach(async () => {
+ await resetTestDatabase();
+ publish.mockClear();
+});
+it("announces committed column changes for focused remote boards", async () => {
+ const { workspace } = await createWorkspaceMember();
+ const { project } = await createProjectFixture({ workspaceId: workspace.id });
+ const column = await createColumn({ projectId: project.id, name: "Review" });
+ await updateColumn(column.id, { name: "Reviewed", color: "#123456" });
+ await reorderColumns(project.id, [{ id: column.id, position: 0 }]);
+ await deleteColumn(column.id);
+ expect(publish.mock.calls).toEqual(
+ Array.from({ length: 4 }, () => [
+ "project.updated",
+ { projectId: project.id },
+ ]),
+ );
+ expect(
+ await db.query.columnTable.findFirst({
+ where: (table, { eq }) => eq(table.id, column.id),
+ }),
+ ).toBeUndefined();
+ await expect(deleteColumn(column.id)).rejects.toThrow("Column not found");
+ expect(publish).toHaveBeenCalledTimes(4);
+});
++
++it.each(["missing", "foreign"])(
++ "rolls back all positions when a later %s column is invalid",
++ async (kind) => {
++ const { workspace } = await createWorkspaceMember();
++ const { project } = await createProjectFixture({
++ workspaceId: workspace.id,
++ });
++ const before = await db.query.columnTable.findMany({
++ where: eq(columnTable.projectId, project.id),
++ orderBy: (table, { asc }) => asc(table.id),
++ });
++ let invalidId = "zz-invalid-column";
++ if (kind === "foreign") {
++ const other = await createWorkspaceMember();
++ const fixture = await createProjectFixture({
++ workspaceId: other.workspace.id,
++ });
++ const foreign = await db.query.columnTable.findFirst({
++ where: eq(columnTable.projectId, fixture.project.id),
++ });
++ invalidId = foreign!.id;
++ }
++ await expect(
++ reorderColumns(project.id, [
++ { id: before[0].id, position: 42 },
++ { id: invalidId, position: 43 },
++ ]),
++ ).rejects.toMatchObject({ status: 400 });
++ expect(
++ await db.query.columnTable.findMany({
++ where: eq(columnTable.projectId, project.id),
++ orderBy: (table, { asc }) => asc(table.id),
++ }),
++ ).toEqual(before);
++ expect(publish).not.toHaveBeenCalled();
++ },
++);