Skip to content

Commit

Permalink
solve first time search problem
Browse files Browse the repository at this point in the history
  • Loading branch information
dokmy committed Jan 13, 2024
1 parent 0163567 commit f7a87b3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/app/api/search/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export async function POST(req: Request) {
const inSearchCreditsDb = await checkSearchCredits(userId)

if (!inSearchCreditsDb) {
incrementSearchCredit(userId, 5)
await incrementSearchCredit(userId, 5)
console.log("First time searching. Added 5 credits.")
}

const creditsLeft = await getSearchCreditCount(userId)
Expand All @@ -68,7 +69,8 @@ export async function POST(req: Request) {


if (creditsLeft > 0) {
deductSearchCredit(userId)
await deductSearchCredit(userId)
console.log("Search is permitted. Deduct 1 credit.")
}


Expand Down

0 comments on commit f7a87b3

Please sign in to comment.