-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Showing
15 changed files
with
933 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,7 @@ CACHE_EXPIRE_S = 10 | |
|
||
ADMINS = "Random,[email protected]" | ||
NEXT_PUBLIC_DISABLE_FEATURES = "featurea,featureb,featurec" | ||
EXCHANGE_RATE_SECRET="" # https://www.exchangerate-api.com/ | ||
GITHUB_CLIENT_ID="" | ||
GITHUB_CLIENT_SECRET="" | ||
GITHUB_PAT="" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import db from '@/db'; | ||
import { | ||
formatINR, | ||
formatUSD, | ||
getCurrencyRate, | ||
sendBountyComment, | ||
} from '@/utiles/bounty'; | ||
|
||
export async function POST(req: NextRequest) { | ||
const body = await req.json(); | ||
const USD_amount = +body.bountyAmount.split('$')[1]; | ||
const PR_By = body.author; | ||
const PR_Link = body.pr_link; | ||
const repo_owner = body.repo_owner; | ||
const repoName = PR_Link.split('/')[4]; | ||
const PR_No: string = PR_Link.split('/')[6]; | ||
const username = body.username; | ||
const PR_Title = body.PR_Title; | ||
|
||
try { | ||
const INR_amount = await getCurrencyRate(USD_amount); | ||
const commentBody = `💰Congratulation @${PR_By} for winning ${formatUSD.format(USD_amount).split('.')[0]} (${formatINR.format(INR_amount).split('.')[0]}) bounty.\n👉 To claim visit https://app.100xdevs.com/bounty.\n🐥Keep contributing.`; | ||
|
||
const findBountyInfo = await db.bountyInfo.findUnique({ | ||
where: { PR_Link }, | ||
}); | ||
|
||
if (findBountyInfo) { | ||
const commentBody = `[Duplicate]\n💰Bounty worth ${formatUSD.format(findBountyInfo.USD_amount).split('.')[0]} (${formatINR.format(findBountyInfo.INR_amount).split('.')[0]}) is already created to @${PR_By} for this PR.\n👉 To claim visit https://app.100xdevs.com/bounty.\n🐥Keep contributing.`; | ||
sendBountyComment({ repo_owner, repoName, PR_No, commentBody }); | ||
return NextResponse.json( | ||
{ message: 'duplicate bounty message' }, | ||
{ status: 401 }, | ||
); | ||
} | ||
|
||
const findUser = await db.githubUser.findUnique({ | ||
where: { username }, | ||
}); | ||
|
||
if (findUser) { | ||
const addBountyInfo = await db.bountyInfo.create({ | ||
data: { | ||
username, | ||
PR_Title, | ||
PR_Link, | ||
repoName, | ||
USD_amount, | ||
INR_amount, | ||
githubUserId: findUser.userId, | ||
}, | ||
}); | ||
if (addBountyInfo) { | ||
sendBountyComment({ repo_owner, repoName, PR_No, commentBody }); | ||
} | ||
} else { | ||
const addBountyInfo = await db.bountyInfo.create({ | ||
data: { | ||
username, | ||
PR_Title, | ||
PR_Link, | ||
repoName, | ||
USD_amount, | ||
INR_amount, | ||
}, | ||
}); | ||
if (addBountyInfo) { | ||
sendBountyComment({ repo_owner, repoName, PR_No, commentBody }); | ||
} | ||
} | ||
return NextResponse.json({ message: 'success' }, { status: 200 }); | ||
} catch (e) { | ||
return NextResponse.json( | ||
{ message: 'Error while updating database' }, | ||
{ status: 401 }, | ||
); | ||
} | ||
} |
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,53 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import db from '@/db'; | ||
|
||
export async function POST(req: NextRequest) { | ||
const { value: username, userId } = await req.json(); | ||
try { | ||
await db.githubUser.upsert({ | ||
where: { userId, isLinked: false }, | ||
create: { userId, username }, | ||
update: { userId, username }, | ||
}); | ||
return NextResponse.json({ message: 'successful' }, { status: 200 }); | ||
} catch (e) { | ||
return NextResponse.json({ message: 'failed' }, { status: 403 }); | ||
} | ||
} | ||
|
||
export async function PUT(req: NextRequest) { | ||
const { username, email, publicName } = await req.json(); | ||
if (!username) { | ||
return NextResponse.json( | ||
{ message: 'error while fetching username' }, | ||
{ status: 403 }, | ||
); | ||
} | ||
try { | ||
const findUser = await db.githubUser.findUnique({ | ||
where: { username, isLinked: false }, | ||
}); | ||
if (!findUser) { | ||
return NextResponse.json( | ||
{ message: 'Error while linking account, username is different' }, | ||
{ status: 401 }, | ||
); | ||
} | ||
const updateInfo = await db.githubUser.update({ | ||
where: { username }, | ||
data: { isLinked: true, email, publicName }, | ||
}); | ||
|
||
await db.bountyInfo.updateMany({ | ||
where: { username }, | ||
data: { githubUserId: updateInfo.userId }, | ||
}); | ||
|
||
return NextResponse.json({ message: 'successful' }, { status: 200 }); | ||
} catch (e) { | ||
return NextResponse.json( | ||
{ message: 'Error while linking account, username is different' }, | ||
{ status: 403 }, | ||
); | ||
} | ||
} |
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,33 @@ | ||
import BountyUser from '@/components/BountyUser'; | ||
import { getGithubDetail } from '@/db/course'; | ||
import { authOptions } from '@/lib/auth'; | ||
import { getServerSession } from 'next-auth'; | ||
import { redirect } from 'next/navigation'; | ||
|
||
export default async function Page({ | ||
params, | ||
}: { | ||
params: { bountyId: string }; | ||
}) { | ||
const session = await getServerSession(authOptions); | ||
if (!session) { | ||
redirect('/signin'); | ||
} | ||
const { role } = session.user; | ||
|
||
if (role === 'user') { | ||
redirect('/bounty'); | ||
} | ||
|
||
const userInfo = await getGithubDetail({ userId: params.bountyId }); | ||
|
||
if (!userInfo || userInfo.isLinked === false) { | ||
redirect('/signInGithub'); | ||
} | ||
|
||
return ( | ||
<div> | ||
{role === 'admin' && <BountyUser userInfo={userInfo} role={role} />} | ||
</div> | ||
); | ||
} |
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,37 @@ | ||
import BountyAdmin from '@/components/BountyAdmin'; | ||
import BountyUser from '@/components/BountyUser'; | ||
import { getAllBountyDetail, getGithubDetail } from '@/db/course'; | ||
import { authOptions } from '@/lib/auth'; | ||
import { getServerSession } from 'next-auth'; | ||
import { redirect } from 'next/navigation'; | ||
|
||
export default async function BountyPage() { | ||
const session = await getServerSession(authOptions); | ||
|
||
if (!session) { | ||
redirect('/signin'); | ||
} | ||
|
||
const { role, id } = session.user; | ||
|
||
if (role === 'user') { | ||
const userInfo = await getGithubDetail({ userId: id }); | ||
if (!userInfo || userInfo.isLinked === false) { | ||
redirect('/signInGithub'); | ||
} | ||
return <BountyUser userInfo={userInfo} role={role} />; | ||
} | ||
|
||
if (role === 'admin') { | ||
const allGithubBountyInfo = await getAllBountyDetail(); | ||
if (!allGithubBountyInfo) { | ||
return <div>No bounties</div>; | ||
} | ||
const allDetails = { | ||
userInfo: allGithubBountyInfo.userInfo, | ||
bountyInfo: allGithubBountyInfo.bountyInfo, | ||
}; | ||
|
||
return <BountyAdmin allGithubBountyInfo={allDetails} />; | ||
} | ||
} |
Oops, something went wrong.