⚡ 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
refactor(api): add OpenAPI schemas to time entry endpoints
Andrej Acevskiad439e1c2d61
diff --git a/apps/api/src/time-entry/index.ts b/apps/api/src/time-entry/index.tsindex a1c280781..1f118cce2 100644--- a/apps/api/src/time-entry/index.ts+++ b/apps/api/src/time-entry/index.ts@@ -1,6 +1,6 @@-import { zValidator } from "@hono/zod-validator";import { Hono } from "hono";-import { z } from "zod";+import { describeRoute, resolver, validator } from "hono-openapi";+import * as v from "valibot";import createTimeEntry from "./controllers/create-time-entry";import getTimeEntriesByTaskId from "./controllers/get-time-entries";import getTimeEntry from "./controllers/get-time-entry";@@ -13,58 +13,116 @@ const timeEntry = new Hono<{}>().get("/task/:taskId",- zValidator("param", z.object({ taskId: z.string() })),+ describeRoute({+ operationId: "getTaskTimeEntries",+ tags: ["Time Entries"],+ description: "Get all time entries for a specific task",+ responses: {+ 200: {+ description: "List of time entries for the task",+ content: {+ "application/json": { schema: resolver(v.array(v.any())) },+ },+ },+ },+ }),+ validator("param", v.object({ taskId: v.string() })),async (c) => {const { taskId } = c.req.valid("param");const timeEntries = await getTimeEntriesByTaskId(taskId);return c.json(timeEntries);},)- .get("/:id", zValidator("param", z.object({ id: z.string() })), async (c) => {- const { id } = c.req.valid("param");- const timeEntry = await getTimeEntry(id);- return c.json(timeEntry);- })+ .get(+ "/:id",+ describeRoute({+ operationId: "getTimeEntry",+ tags: ["Time Entries"],+ description: "Get a specific time entry by ID",+ responses: {+ 200: {+ description: "Time entry details",+ content: {+ "application/json": { schema: resolver(v.any()) },+ },+ },+ },+ }),+ validator("param", v.object({ id: v.string() })),+ async (c) => {+ const { id } = c.req.valid("param");+ const timeEntry = await getTimeEntry(id);+ return c.json(timeEntry);+ },+ ).post("/",- zValidator(+ describeRoute({+ operationId: "createTimeEntry",+ tags: ["Time Entries"],+ description: "Create a new time entry for a task",+ responses: {+ 200: {+ description: "Time entry created successfully",+ content: {+ "application/json": { schema: resolver(v.any()) },+ },+ },+ },+ }),+ validator("json",- z.object({- taskId: z.string(),- description: z.string().optional(),- startTime: z.string(),+ v.object({+ taskId: v.string(),+ startTime: v.string(),+ endTime: v.optional(v.string()),+ description: v.optional(v.string()),}),),async (c) => {- const { taskId, description, startTime } = c.req.valid("json");+ const { taskId, startTime, endTime, description } = c.req.valid("json");const userId = c.get("userId");-const timeEntry = await createTimeEntry({taskId,userId,- description,startTime: new Date(startTime),+ endTime: endTime ? new Date(endTime) : undefined,+ description,});-return c.json(timeEntry);},).put("/:id",- zValidator("param", z.object({ id: z.string() })),- zValidator(+ describeRoute({+ operationId: "updateTimeEntry",+ tags: ["Time Entries"],+ description: "Update an existing time entry",+ responses: {+ 200: {+ description: "Time entry updated successfully",+ content: {+ "application/json": { schema: resolver(v.any()) },+ },+ },+ },+ }),+ validator("param", v.object({ id: v.string() })),+ validator("json",- z.object({- endTime: z.string(),- duration: z.number(),+ v.object({+ startTime: v.string(),+ endTime: v.optional(v.string()),}),),async (c) => {const { id } = c.req.valid("param");- const { endTime, duration } = c.req.valid("json");-- const timeEntry = await updateTimeEntry(id, new Date(endTime), duration);-+ const { startTime, endTime } = c.req.valid("json");+ const timeEntry = await updateTimeEntry(+ id,+ new Date(startTime),+ endTime ? new Date(endTime).getTime() : 0,+ );return c.json(timeEntry);},);