first commit

This commit is contained in:
2026-01-17 14:17:42 +05:30
commit 0f194eb9e7
328 changed files with 73544 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
import { NextRequest, NextResponse } from 'next/server'
import { auth } from '@/auth'
import { prisma } from '@/lib/prisma'
export async function PUT(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const session = await auth()
if (!session?.user?.id) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
const { id: addressId } = await params
// Check if address belongs to user
const existingAddress = await prisma.address.findFirst({
where: {
id: addressId,
userId: session.user.id
}
})
if (!existingAddress) {
return NextResponse.json({ error: 'Address not found' }, { status: 404 })
}
// Unset all other default addresses for this user
await prisma.address.updateMany({
where: {
userId: session.user.id,
isDefault: true
},
data: { isDefault: false }
})
// Set this address as default
const address = await prisma.address.update({
where: { id: addressId },
data: { isDefault: true }
})
return NextResponse.json({ address })
} catch (error) {
console.error('Error setting default address:', error)
return NextResponse.json(
{ error: 'Failed to set default address' },
{ status: 500 }
)
}
}