Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
1.7 kB ยท 49 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950import { Events } from "@openstatus/analytics";import { enabledFeatures } from "@openstatus/services";import { getTrialDaysLeft, getWorkspaceUsage, updateWorkspaceName,} from "@openstatus/services/workspace";import { z } from "zod";
import { toServiceCtx, toTRPCError } from "../service-adapter";import { createTRPCRouter, protectedProcedure } from "../trpc";
export const workspaceRouter = createTRPCRouter({ // The authed middleware already resolved and parsed this row; re-selecting // it would be the same query. Counts live in `usage` โ the shell reads // `limits` on every route, the counts only on two surfaces. // `trialDaysLeft` is derived here, not stored: it depends on "now". get: protectedProcedure.query(({ ctx }) => ({ ...ctx.workspace, trialDaysLeft: getTrialDaysLeft(ctx.workspace.trialEndsAt), features: enabledFeatures(ctx.workspace), })),
usage: protectedProcedure.query(async ({ ctx }) => { try { return await getWorkspaceUsage({ ctx: toServiceCtx(ctx) }); } catch (err) { toTRPCError(err); } }),
// `resolveActiveWorkspace` already joined the user's workspaces to pick the // active one, so this is the same rows the service would re-query. list: protectedProcedure.query(({ ctx }) => ctx.workspaces),
updateName: protectedProcedure .meta({ track: Events.UpdateWorkspace }) .input(z.object({ name: z.string() })) .mutation(async ({ ctx, input }) => { try { await updateWorkspaceName({ ctx: toServiceCtx(ctx), input: { name: input.name }, }); } catch (err) { toTRPCError(err); } }),});