refactor: small improvements for cal ai (#23444)
* refactor: small improvements follow up * fix: add docs
This commit is contained in:
1 parent
e7779bba0a
commit
dd16c2b99d
6 files changed
+47
-23
No files matched your search
@@ -1,3 +1,6 @@
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
import { generateUniqueAPIKey as generateHashedApiKey } from "@calcom/ee/api-keys/lib/apiKeys";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
export class PrismaApiKeyRepository {
|
||||
@@ -25,4 +28,34 @@ export class PrismaApiKeyRepository {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
static async createApiKey({
|
||||
userId,
|
||||
teamId,
|
||||
note,
|
||||
expiresAt,
|
||||
}: {
|
||||
userId: number;
|
||||
teamId?: number;
|
||||
note?: string;
|
||||
expiresAt?: Date | null;
|
||||
}) {
|
||||
const [hashedApiKey, apiKey] = generateHashedApiKey();
|
||||
await prisma.apiKey.create({
|
||||
data: {
|
||||
id: uuidv4(),
|
||||
userId,
|
||||
teamId,
|
||||
expiresAt,
|
||||
hashedKey: hashedApiKey,
|
||||
note: note,
|
||||
},
|
||||
});
|
||||
|
||||
const apiKeyPrefix = process.env.API_KEY_PREFIX ?? "cal_";
|
||||
|
||||
const prefixedApiKey = `${apiKeyPrefix}${apiKey}`;
|
||||
|
||||
return prefixedApiKey;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user