new rest endpoints
This commit is contained in:
parent
aa5485d8fd
commit
369c352390
6 changed files with 61 additions and 47 deletions
6
pnpm-lock.yaml
generated
6
pnpm-lock.yaml
generated
|
@ -1653,7 +1653,7 @@ packages:
|
||||||
hasBin: true
|
hasBin: true
|
||||||
dependencies:
|
dependencies:
|
||||||
caniuse-lite: 1.0.30001519
|
caniuse-lite: 1.0.30001519
|
||||||
electron-to-chromium: 1.4.487
|
electron-to-chromium: 1.4.488
|
||||||
node-releases: 2.0.13
|
node-releases: 2.0.13
|
||||||
update-browserslist-db: 1.0.11(browserslist@4.21.10)
|
update-browserslist-db: 1.0.11(browserslist@4.21.10)
|
||||||
dev: false
|
dev: false
|
||||||
|
@ -2186,8 +2186,8 @@ packages:
|
||||||
semver: 7.5.4
|
semver: 7.5.4
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/electron-to-chromium@1.4.487:
|
/electron-to-chromium@1.4.488:
|
||||||
resolution: {integrity: sha512-XbCRs/34l31np/p33m+5tdBrdXu9jJkZxSbNxj5I0H1KtV2ZMSB+i/HYqDiRzHaFx2T5EdytjoBRe8QRJE2vQg==}
|
resolution: {integrity: sha512-Dv4sTjiW7t/UWGL+H8ZkgIjtUAVZDgb/PwGWvMsCT7jipzUV/u5skbLXPFKb6iV0tiddVi/bcS2/kUrczeWgIQ==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/emoji-regex@9.2.2:
|
/emoji-regex@9.2.2:
|
||||||
|
|
|
@ -61,7 +61,7 @@ const AdminBody: React.FC = () => {
|
||||||
isLoading: usersCountLoading,
|
isLoading: usersCountLoading,
|
||||||
isFetching: usersCountFetching,
|
isFetching: usersCountFetching,
|
||||||
refetch: refetchUsersCount,
|
refetch: refetchUsersCount,
|
||||||
} = api.user.countAll.useQuery();
|
} = api.rest.userCount.useQuery();
|
||||||
const {
|
const {
|
||||||
data: users,
|
data: users,
|
||||||
isLoading: usersLoading,
|
isLoading: usersLoading,
|
||||||
|
@ -73,13 +73,13 @@ const AdminBody: React.FC = () => {
|
||||||
isLoading: roomsCountLoading,
|
isLoading: roomsCountLoading,
|
||||||
isFetching: roomsCountFetching,
|
isFetching: roomsCountFetching,
|
||||||
refetch: refetchRoomsCount,
|
refetch: refetchRoomsCount,
|
||||||
} = api.room.countAll.useQuery();
|
} = api.rest.roomCount.useQuery();
|
||||||
const {
|
const {
|
||||||
data: votesCount,
|
data: votesCount,
|
||||||
isLoading: votesCountLoading,
|
isLoading: votesCountLoading,
|
||||||
isFetching: votesCountFetching,
|
isFetching: votesCountFetching,
|
||||||
refetch: refetchVotesCount,
|
refetch: refetchVotesCount,
|
||||||
} = api.vote.countAll.useQuery();
|
} = api.rest.voteCount.useQuery();
|
||||||
|
|
||||||
const getProviders = (user: {
|
const getProviders = (user: {
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { z } from "zod";
|
||||||
|
|
||||||
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";
|
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
|
import { fetchCache, setCache } from "~/server/redis";
|
||||||
|
|
||||||
export const restRouter = createTRPCRouter({
|
export const restRouter = createTRPCRouter({
|
||||||
dbWarmer: publicProcedure
|
dbWarmer: publicProcedure
|
||||||
|
@ -18,4 +19,58 @@ export const restRouter = createTRPCRouter({
|
||||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
throw new TRPCError({ code: "UNAUTHORIZED" });
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
voteCount: publicProcedure
|
||||||
|
.meta({ openapi: { method: "GET", path: "/rest/votes/count" } })
|
||||||
|
.input(z.void())
|
||||||
|
.output(z.number())
|
||||||
|
.query(async ({ ctx }) => {
|
||||||
|
const cachedResult = await fetchCache<number>(`kv_votecount_admin`);
|
||||||
|
|
||||||
|
if (cachedResult) {
|
||||||
|
return cachedResult;
|
||||||
|
} else {
|
||||||
|
const votesCount = await ctx.prisma.vote.count();
|
||||||
|
|
||||||
|
await setCache(`kv_votecount_admin`, votesCount);
|
||||||
|
|
||||||
|
return votesCount;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
userCount: publicProcedure
|
||||||
|
.meta({ openapi: { method: "GET", path: "/rest/users/count" } })
|
||||||
|
.input(z.void())
|
||||||
|
.output(z.number())
|
||||||
|
.query(async ({ ctx }) => {
|
||||||
|
const cachedResult = await fetchCache<number>(`kv_usercount`);
|
||||||
|
|
||||||
|
if (cachedResult) {
|
||||||
|
return cachedResult;
|
||||||
|
} else {
|
||||||
|
const usersCount = await ctx.prisma.user.count();
|
||||||
|
|
||||||
|
await setCache(`kv_usercount`, usersCount);
|
||||||
|
|
||||||
|
return usersCount;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
roomCount: publicProcedure
|
||||||
|
.meta({ openapi: { method: "GET", path: "/rest/rooms/count" } })
|
||||||
|
.input(z.void())
|
||||||
|
.output(z.number())
|
||||||
|
.query(async ({ ctx }) => {
|
||||||
|
const cachedResult = await fetchCache<number>(`kv_roomcount`);
|
||||||
|
|
||||||
|
if (cachedResult) {
|
||||||
|
return cachedResult;
|
||||||
|
} else {
|
||||||
|
const roomsCount = await ctx.prisma.room.count();
|
||||||
|
|
||||||
|
await setCache(`kv_roomcount`, roomsCount);
|
||||||
|
|
||||||
|
return roomsCount;
|
||||||
|
}
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
|
@ -97,20 +97,6 @@ export const roomRouter = createTRPCRouter({
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
countAll: adminProcedure.query(async ({ ctx }) => {
|
|
||||||
const cachedResult = await fetchCache<number>(`kv_roomcount_admin`);
|
|
||||||
|
|
||||||
if (cachedResult) {
|
|
||||||
return cachedResult;
|
|
||||||
} else {
|
|
||||||
const roomsCount = await ctx.prisma.room.count();
|
|
||||||
|
|
||||||
await setCache(`kv_roomcount_admin`, roomsCount);
|
|
||||||
|
|
||||||
return roomsCount;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
|
|
||||||
// Update One
|
// Update One
|
||||||
set: protectedProcedure
|
set: protectedProcedure
|
||||||
.input(
|
.input(
|
||||||
|
|
|
@ -14,20 +14,6 @@ import { fetchCache, invalidateCache, setCache } from "~/server/redis";
|
||||||
const resend = new Resend(process.env.RESEND_API_KEY);
|
const resend = new Resend(process.env.RESEND_API_KEY);
|
||||||
|
|
||||||
export const userRouter = createTRPCRouter({
|
export const userRouter = createTRPCRouter({
|
||||||
countAll: adminProcedure.query(async ({ ctx }) => {
|
|
||||||
const cachedResult = await fetchCache<number>(`kv_usercount_admin`);
|
|
||||||
|
|
||||||
if (cachedResult) {
|
|
||||||
return cachedResult;
|
|
||||||
} else {
|
|
||||||
const usersCount = await ctx.prisma.user.count();
|
|
||||||
|
|
||||||
await setCache(`kv_usercount_admin`, usersCount);
|
|
||||||
|
|
||||||
return usersCount;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
|
|
||||||
getProviders: protectedProcedure.query(async ({ ctx }) => {
|
getProviders: protectedProcedure.query(async ({ ctx }) => {
|
||||||
const providers = await ctx.prisma.user.findUnique({
|
const providers = await ctx.prisma.user.findUnique({
|
||||||
where: {
|
where: {
|
||||||
|
|
|
@ -11,19 +11,6 @@ import { fetchCache, invalidateCache, setCache } from "~/server/redis";
|
||||||
import { EventTypes } from "~/utils/types";
|
import { EventTypes } from "~/utils/types";
|
||||||
|
|
||||||
export const voteRouter = createTRPCRouter({
|
export const voteRouter = createTRPCRouter({
|
||||||
countAll: adminProcedure.query(async ({ ctx }) => {
|
|
||||||
const cachedResult = await fetchCache<number>(`kv_votecount_admin`);
|
|
||||||
|
|
||||||
if (cachedResult) {
|
|
||||||
return cachedResult;
|
|
||||||
} else {
|
|
||||||
const votesCount = await ctx.prisma.vote.count();
|
|
||||||
|
|
||||||
await setCache(`kv_votecount_admin`, votesCount);
|
|
||||||
|
|
||||||
return votesCount;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
getAllByRoomId: protectedProcedure
|
getAllByRoomId: protectedProcedure
|
||||||
.input(z.object({ roomId: z.string() }))
|
.input(z.object({ roomId: z.string() }))
|
||||||
.query(async ({ ctx, input }) => {
|
.query(async ({ ctx, input }) => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue