final
This commit is contained in:
@@ -6,7 +6,7 @@ import bcrypt from 'bcrypt'
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const { username, password, email } = body
|
||||
const { username, password, email, referral_id } = body
|
||||
|
||||
// Validate required fields
|
||||
if (!username || !password || !email) {
|
||||
@@ -84,6 +84,27 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
const buyer = (rows as any[])[0]
|
||||
|
||||
// Handle referral if provided
|
||||
if (referral_id) {
|
||||
const referrerId = parseInt(referral_id, 10)
|
||||
|
||||
// Validate that referrer exists and is not the same as the new user
|
||||
if (referrerId && referrerId !== buyer.id) {
|
||||
const [referrerRows] = await pool.execute(
|
||||
'SELECT id FROM buyers WHERE id = ?',
|
||||
[referrerId]
|
||||
)
|
||||
|
||||
if ((referrerRows as any[]).length > 0) {
|
||||
// Create referral record
|
||||
await pool.execute(
|
||||
'INSERT INTO referrals (referrer, referree) VALUES (?, ?)',
|
||||
[referrerId, buyer.id]
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create session cookie
|
||||
const response = NextResponse.json(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user