-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60c6868
commit c90dbf1
Showing
18 changed files
with
553 additions
and
438 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { NextResponse } from "next/server"; | ||
import { prisma } from "@/lib/prisma"; | ||
import { LResponseError } from "@/lib"; | ||
|
||
export async function GET() { | ||
try { | ||
const costs = await prisma.cost.findMany({ | ||
where: { | ||
createdAt: { | ||
gte: new Date(new Date().setHours(0, 0, 0, 0)), | ||
}, | ||
}, | ||
}); | ||
|
||
// if costs exist means already run today | ||
if (costs.length) return LResponseError("already run today"); | ||
|
||
const users = await prisma.user.findMany({ | ||
where: { | ||
costTokens: { | ||
gt: 0, | ||
}, | ||
}, | ||
}); | ||
|
||
if (!users.length) return LResponseError("no users need to cost"); | ||
|
||
for (const user of users) { | ||
const { id, availableTokens, costTokens, costUSD } = user; | ||
|
||
await prisma.cost.create({ | ||
data: { | ||
costTokens, | ||
costUSD, | ||
userId: id, | ||
}, | ||
}); | ||
|
||
await prisma.user.update({ | ||
data: { | ||
costTokens: 0, | ||
costUSD: 0, | ||
availableTokens: availableTokens - costTokens, | ||
}, | ||
where: { id: user.id }, | ||
}); | ||
} | ||
|
||
return NextResponse.json({ error: 0 }, { status: 200 }); | ||
} catch (error) { | ||
console.log("cost error"); | ||
return LResponseError("error"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
c90dbf1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
l-gpt – ./
l-gpt.vercel.app
l-gpt-peek-a-booo-s-team.vercel.app
gpt.ltopx.com
l-gpt-git-main-peek-a-booo-s-team.vercel.app