Skip to content

Commit

Permalink
fix db issue
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminshafii committed Dec 10, 2024
1 parent 1d5dfa5 commit 7b64fe7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 10 additions & 5 deletions web/app/dashboard/lifetime/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Vercel } from "@vercel/sdk";
import { auth } from "@clerk/nextjs/server";
import { db, vercelTokens } from "@/drizzle/schema";
import { eq } from "drizzle-orm";
import { eq, exists } from "drizzle-orm";
import { createLicenseKeyFromUserId } from "@/app/actions";

const GITHUB_ORG = "different-ai";
Expand All @@ -17,7 +17,10 @@ type SetupProjectResult = {
projectUrl: string;
};

export async function setupProject(vercelToken: string, openaiKey: string): Promise<SetupProjectResult> {
export async function setupProject(
vercelToken: string,
openaiKey: string
): Promise<SetupProjectResult> {
const { userId } = auth();
// create an api key for the user
if (!userId) {
Expand All @@ -32,15 +35,18 @@ export async function setupProject(vercelToken: string, openaiKey: string): Prom
if (!openaiKey) {
throw new Error("OpenAI API key is required");
}
console.log("userId", userId);

// Store or update the token
const existingToken = await db
.select()
.from(vercelTokens)
.where(eq(vercelTokens.userId, userId));

if (existingToken) {
console.log("Updating existing token");
console.log("existingToken", existingToken);

if (existingToken.length > 0) {
console.log("Updating existing token", vercelToken);
// Update existing token
await db
.update(vercelTokens)
Expand Down Expand Up @@ -118,7 +124,6 @@ export async function setupProject(vercelToken: string, openaiKey: string): Prom
},
},
});


// Update token record with project details and URL
await db
Expand Down
4 changes: 4 additions & 0 deletions web/vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
{
"path": "/api/cron/reset-tokens",
"schedule": "0 0 1 * *"
},
{
"path": "/api/cron/redeploy",
"schedule": "0 0 * * *"
}
]
}

0 comments on commit 7b64fe7

Please sign in to comment.