kaneo (minimalist kanban) fork to experiment adding a tangled integration
github.com/usekaneo/kaneo
1import { Hono } from "hono";
2import { describeRoute, resolver, validator } from "hono-openapi";
3import * as v from "valibot";
4import { workspaceAccess } from "../utils/workspace-access-middleware";
5import deleteWorkflowRule from "./controllers/delete-workflow-rule";
6import getWorkflowRules from "./controllers/get-workflow-rules";
7import upsertWorkflowRule from "./controllers/upsert-workflow-rule";
8
9const workflowRule = new Hono<{
10 Variables: {
11 userId: string;
12 };
13}>()
14 .get(
15 "/:projectId",
16 describeRoute({
17 operationId: "getWorkflowRules",
18 tags: ["Workflow Rules"],
19 description: "Get all workflow rules for a project",
20 responses: {
21 200: {
22 description: "List of workflow rules",
23 content: {
24 "application/json": { schema: resolver(v.any()) },
25 },
26 },
27 },
28 }),
29 validator("param", v.object({ projectId: v.string() })),
30 workspaceAccess.fromProject("projectId"),
31 async (c) => {
32 const { projectId } = c.req.valid("param");
33 const rules = await getWorkflowRules(projectId);
34 return c.json(rules);
35 },
36 )
37 .put(
38 "/:projectId",
39 describeRoute({
40 operationId: "upsertWorkflowRule",
41 tags: ["Workflow Rules"],
42 description: "Create or update a workflow rule",
43 responses: {
44 200: {
45 description: "Workflow rule upserted successfully",
46 content: {
47 "application/json": { schema: resolver(v.any()) },
48 },
49 },
50 },
51 }),
52 validator("param", v.object({ projectId: v.string() })),
53 validator(
54 "json",
55 v.object({
56 integrationType: v.string(),
57 eventType: v.string(),
58 columnId: v.string(),
59 }),
60 ),
61 workspaceAccess.fromProject("projectId"),
62 async (c) => {
63 const { projectId } = c.req.valid("param");
64 const { integrationType, eventType, columnId } = c.req.valid("json");
65 const result = await upsertWorkflowRule({
66 projectId,
67 integrationType,
68 eventType,
69 columnId,
70 });
71 return c.json(result);
72 },
73 )
74 .delete(
75 "/:id",
76 describeRoute({
77 operationId: "deleteWorkflowRule",
78 tags: ["Workflow Rules"],
79 description: "Delete a workflow rule",
80 responses: {
81 200: {
82 description: "Workflow rule deleted successfully",
83 content: {
84 "application/json": { schema: resolver(v.any()) },
85 },
86 },
87 },
88 }),
89 validator("param", v.object({ id: v.string() })),
90 workspaceAccess.fromWorkflowRule("id"),
91 async (c) => {
92 const { id } = c.req.valid("param");
93 const result = await deleteWorkflowRule(id);
94 return c.json(result);
95 },
96 );
97
98export default workflowRule;