feat: create and delete api keys

This commit is contained in:
Henry
2025-05-31 23:59:48 +01:00
parent e61dd4e27e
commit 1d00aa78b4
11 changed files with 153 additions and 24 deletions

View File

@@ -1,8 +1,8 @@
import { eq } from "drizzle-orm";
import { desc, eq } from "drizzle-orm";
import { v4 as uuidv4 } from "uuid";
import type { dbClient } from "@kan/db/client";
import { users } from "@kan/db/schema";
import { apiKey, users } from "@kan/db/schema";
export const getById = async (db: dbClient, userId: string) => {
return await db.query.users.findFirst({
@@ -13,6 +13,17 @@ export const getById = async (db: dbClient, userId: string) => {
image: true,
stripeCustomerId: true,
},
with: {
apiKeys: {
columns: {
id: true,
prefix: true,
key: true,
},
orderBy: desc(apiKey.createdAt),
limit: 1,
},
},
where: eq(users.id, userId),
});
};