⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
import { and, eq } from "drizzle-orm";
import { HTTPException } from "hono/http-exception";
import { withLockedTask } from "./with-locked-task";
import { columnTable, taskTable } from "../../database/schema";
import { publishEvent } from "../../events";
import { publishTaskMutation } from "./task-mutation-effects";
import { assertValidTaskStatus } from "../validate-task-fields";
async function updateTaskStatus({
id,
status,
currentUserId,
}: {
id: string;
status: string;
currentUserId: string;
}) {
const { before: existingTask, after: updatedTask } = await withLockedTask(
id,
async (tx, existingTask) => {
await assertValidTaskStatus(status, existingTask.projectId, tx);
const column = await tx.query.columnTable.findFirst({
where: and(
eq(columnTable.projectId, existingTask.projectId),
eq(columnTable.slug, status),
),
});
const [updatedTask] = await tx
.update(taskTable)
.set({ status, columnId: column?.id ?? null })
.where(eq(taskTable.id, id))
.returning();
if (!updatedTask) {
throw new HTTPException(500, {
message: "Failed to update task status",
});
}
return updatedTask;
},
);
await publishTaskMutation(existingTask, updatedTask, currentUserId, {
fields: ["status"],
});
if (
existingTask.status === updatedTask.status &&
existingTask.columnId !== updatedTask.columnId
)
await publishEvent("task.updated", {
taskId: updatedTask.id,
projectId: updatedTask.projectId,
userId: currentUserId,
});
return updatedTask;
}
export default updateTaskStatus;