feat: create and delete api keys
This commit is contained in:
@@ -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),
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user