/api/client/status Endpoint 추가

This commit is contained in:
static
2024-12-29 23:56:35 +09:00
parent 95bad90f36
commit ee752494cd
3 changed files with 42 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
import { and, eq, gt, lte } from "drizzle-orm";
import { and, eq, gt, lte, count } from "drizzle-orm";
import db from "./drizzle";
import { client, userClient, userClientChallenge } from "./schema";
@@ -25,6 +25,15 @@ export const getAllUserClients = async (userId: number) => {
return await db.select().from(userClient).where(eq(userClient.userId, userId)).execute();
};
export const countActiveUserClients = async (userId: number) => {
const userClients = await db
.select({ count: count() })
.from(userClient)
.where(and(eq(userClient.userId, userId), eq(userClient.state, "active")))
.execute();
return userClients[0]?.count ?? null;
};
export const getUserClient = async (userId: number, clientId: number) => {
const userClients = await db
.select()