Files
sexy/packages/backend/src/graphql/resolvers/stats.ts
Sebastian Krüger efc7624ba3
All checks were successful
Build and Push Backend Image / build (push) Successful in 46s
Build and Push Frontend Image / build (push) Successful in 5m12s
style: apply prettier formatting to all files
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-04 22:27:54 +01:00

28 lines
840 B
TypeScript

import { builder } from "../builder";
import { StatsType } from "../types/index";
import { users, videos } from "../../db/schema/index";
import { eq, count } from "drizzle-orm";
builder.queryField("stats", (t) =>
t.field({
type: StatsType,
resolve: async (_root, _args, ctx) => {
const modelsCount = await ctx.db
.select({ count: count() })
.from(users)
.where(eq(users.role, "model"));
const viewersCount = await ctx.db
.select({ count: count() })
.from(users)
.where(eq(users.role, "viewer"));
const videosCount = await ctx.db.select({ count: count() }).from(videos);
return {
models_count: modelsCount[0]?.count || 0,
viewers_count: viewersCount[0]?.count || 0,
videos_count: videosCount[0]?.count || 0,
};
},
}),
);