Openstatus www.openstatus.dev

๐Ÿ› timestamp in monitor_run (#1065)

* ๐Ÿ› time

* ci: apply automated fixes

* ๐Ÿš€ whoami endpoint

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>

authored by

Thibault Le Ouay
autofix-ci[bot]
and committed by
GitHub
65325ef4 b657ef9f

+71 -1
+45
apps/server/src/v1/whoami/get.ts
··· 1 + import { createRoute, z } from "@hono/zod-openapi"; 2 + import { eq } from "@openstatus/db"; 3 + import { db } from "@openstatus/db/src/db"; 4 + import { workspace } from "@openstatus/db/src/schema/workspaces"; 5 + import { HTTPException } from "hono/http-exception"; 6 + import type { whoamiApi } from "."; 7 + import { openApiErrorResponses } from "../../libs/errors/openapi-error-responses"; 8 + import { schema } from "./schema"; 9 + 10 + const getRoute = createRoute({ 11 + method: "get", 12 + tags: ["whoami"], 13 + path: "/", 14 + description: "Get the current workspace information", 15 + responses: { 16 + 200: { 17 + content: { 18 + "application/json": { 19 + schema: schema, 20 + }, 21 + }, 22 + description: "The current workspace information with the limits", 23 + }, 24 + ...openApiErrorResponses, 25 + }, 26 + }); // Error: createRoute is not defined 27 + 28 + export function registerGetWhoami(api: typeof whoamiApi) { 29 + return api.openapi(getRoute, async (c) => { 30 + const workspaceId = c.get("workspaceId"); 31 + 32 + const workspaceData = await db 33 + .select() 34 + .from(workspace) 35 + .where(eq(workspace.id, Number(workspaceId))) 36 + .get(); 37 + 38 + if (!workspaceData) { 39 + throw new HTTPException(404, { message: "Not Found" }); 40 + } 41 + 42 + const data = schema.parse(workspaceData); 43 + return c.json(data, 200); 44 + }); 45 + }
+7
apps/server/src/v1/whoami/index.ts
··· 1 + import { OpenAPIHono } from "@hono/zod-openapi"; 2 + import type { Variables } from ".."; 3 + import { handleZodError } from "../../libs/errors"; 4 + 5 + export const whoamiApi = new OpenAPIHono<{ Variables: Variables }>({ 6 + defaultHook: handleZodError, 7 + }); // Compare this snippet from apps/server/src/v1/whoami/index.ts:
+18
apps/server/src/v1/whoami/schema.ts
··· 1 + import { z } from "@hono/zod-openapi"; 2 + import { allPlans } from "@openstatus/db/src/schema/plan/config"; 3 + import { limitSchema } from "@openstatus/db/src/schema/plan/schema"; 4 + import { workspacePlans } from "@openstatus/db/src/schema/workspaces/constants"; 5 + 6 + export const schema = z.object({ 7 + workspaceId: z.number().openapi({ 8 + description: "The current workspace id", 9 + }), 10 + plan: z 11 + .enum(workspacePlans) 12 + .nullable() 13 + .default("free") 14 + .transform((val) => val ?? "free") 15 + .openapi({ 16 + description: "The current workspace plan", 17 + }), 18 + });
+1 -1
packages/db/src/schema/monitor_run/monitor_run.ts
··· 9 9 workspaceId: integer("workspace_id").references(() => workspace.id), 10 10 monitorId: integer("monitor_id").references(() => monitor.id), 11 11 12 - runnedAt: integer("runned_at", { mode: "timestamp" }), 12 + runnedAt: integer("runned_at", { mode: "timestamp_ms" }), 13 13 14 14 createdAt: integer("created_at", { mode: "timestamp" }).default( 15 15 sql`(strftime('%s', 'now'))`,