Skip to content

Open-source status page, incident response and uptime monitoring

🐛 timestamp in monitor_run (#1065)

Thibault Le Ouay65325ef4e428
diff --git a/apps/server/src/v1/whoami/get.ts b/apps/server/src/v1/whoami/get.ts
new file mode 100644
index 000000000..e6a37d857
--- /dev/null
+++ b/apps/server/src/v1/whoami/get.ts
@@ -0,0 +1,45 @@
+import { createRoute, z } from "@hono/zod-openapi";
+import { eq } from "@openstatus/db";
+import { db } from "@openstatus/db/src/db";
+import { workspace } from "@openstatus/db/src/schema/workspaces";
+import { HTTPException } from "hono/http-exception";
+import type { whoamiApi } from ".";
+import { openApiErrorResponses } from "../../libs/errors/openapi-error-responses";
+import { schema } from "./schema";
+
+const getRoute = createRoute({
+ method: "get",
+ tags: ["whoami"],
+ path: "/",
+ description: "Get the current workspace information",
+ responses: {
+ 200: {
+ content: {
+ "application/json": {
+ schema: schema,
+ },
+ },
+ description: "The current workspace information with the limits",
+ },
+ ...openApiErrorResponses,
+ },
+}); // Error: createRoute is not defined
+
+export function registerGetWhoami(api: typeof whoamiApi) {
+ return api.openapi(getRoute, async (c) => {
+ const workspaceId = c.get("workspaceId");
+
+ const workspaceData = await db
+ .select()
+ .from(workspace)
+ .where(eq(workspace.id, Number(workspaceId)))
+ .get();
+
+ if (!workspaceData) {
+ throw new HTTPException(404, { message: "Not Found" });
+ }
+
+ const data = schema.parse(workspaceData);
+ return c.json(data, 200);
+ });
+}
diff --git a/apps/server/src/v1/whoami/index.ts b/apps/server/src/v1/whoami/index.ts
new file mode 100644
index 000000000..ffd520298
--- /dev/null
+++ b/apps/server/src/v1/whoami/index.ts
@@ -0,0 +1,7 @@
+import { OpenAPIHono } from "@hono/zod-openapi";
+import type { Variables } from "..";
+import { handleZodError } from "../../libs/errors";
+
+export const whoamiApi = new OpenAPIHono<{ Variables: Variables }>({
+ defaultHook: handleZodError,
+}); // Compare this snippet from apps/server/src/v1/whoami/index.ts:
diff --git a/apps/server/src/v1/whoami/schema.ts b/apps/server/src/v1/whoami/schema.ts
new file mode 100644
index 000000000..da278590d
--- /dev/null
+++ b/apps/server/src/v1/whoami/schema.ts
@@ -0,0 +1,18 @@
+import { z } from "@hono/zod-openapi";
+import { allPlans } from "@openstatus/db/src/schema/plan/config";
+import { limitSchema } from "@openstatus/db/src/schema/plan/schema";
+import { workspacePlans } from "@openstatus/db/src/schema/workspaces/constants";
+
+export const schema = z.object({
+ workspaceId: z.number().openapi({
+ description: "The current workspace id",
+ }),
+ plan: z
+ .enum(workspacePlans)
+ .nullable()
+ .default("free")
+ .transform((val) => val ?? "free")
+ .openapi({
+ description: "The current workspace plan",
+ }),
+});
diff --git a/packages/db/src/schema/monitor_run/monitor_run.ts b/packages/db/src/schema/monitor_run/monitor_run.ts
index c382251d5..d70e33961 100644
--- a/packages/db/src/schema/monitor_run/monitor_run.ts
+++ b/packages/db/src/schema/monitor_run/monitor_run.ts
@@ -9,7 +9,7 @@ export const monitorRun = sqliteTable("monitor_run", {
workspaceId: integer("workspace_id").references(() => workspace.id),
monitorId: integer("monitor_id").references(() => monitor.id),
- runnedAt: integer("runned_at", { mode: "timestamp" }),
+ runnedAt: integer("runned_at", { mode: "timestamp_ms" }),
createdAt: integer("created_at", { mode: "timestamp" }).default(
sql`(strftime('%s', 'now'))`,