first commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/db'
|
||||
import { requireAdmin } from '@/lib/auth-helpers'
|
||||
import { MOCK_MESSAGES } from '@/lib/mock'
|
||||
|
||||
const USE_MOCK = process.env.USE_MOCK === 'true'
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
await requireAdmin()
|
||||
const data = USE_MOCK
|
||||
? MOCK_MESSAGES
|
||||
: await prisma.contactMessage.findMany({
|
||||
where: { deletedAt: null },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
})
|
||||
return NextResponse.json({ data })
|
||||
} catch {
|
||||
return NextResponse.json({ error: 'Server error' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/db'
|
||||
import { requireAdmin } from '@/lib/auth-helpers'
|
||||
import { MOCK_UNITS } from '@/lib/mock'
|
||||
import { UnitSchema } from '@/lib/validations'
|
||||
|
||||
const USE_MOCK = process.env.USE_MOCK === 'true'
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const data = USE_MOCK
|
||||
? MOCK_UNITS
|
||||
: await prisma.unit.findMany({ where: { deletedAt: null }, orderBy: { order: 'asc' } })
|
||||
return NextResponse.json({ data })
|
||||
} catch {
|
||||
return NextResponse.json({ error: 'Server error' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
try {
|
||||
await requireAdmin()
|
||||
const body = await req.json()
|
||||
const parsed = UnitSchema.safeParse(body)
|
||||
if (!parsed.success) return NextResponse.json({ error: parsed.error.flatten() }, { status: 400 })
|
||||
const record = await prisma.unit.create({ data: parsed.data })
|
||||
return NextResponse.json({ data: record }, { status: 201 })
|
||||
} catch {
|
||||
return NextResponse.json({ error: 'Server error' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
import { handlers } from '@/lib/auth'
|
||||
export const { GET, POST } = handlers
|
||||
@@ -0,0 +1,34 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { prisma } from '@/lib/db'
|
||||
import { ContactSchema } from '@/lib/validations'
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
try {
|
||||
const body = await req.json()
|
||||
const parsed = ContactSchema.safeParse(body)
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json({ error: parsed.error.flatten() }, { status: 400 })
|
||||
}
|
||||
|
||||
const message = await prisma.contactMessage.create({
|
||||
data: parsed.data,
|
||||
})
|
||||
|
||||
return NextResponse.json({ data: message }, { status: 201 })
|
||||
} catch (error) {
|
||||
console.error('Contact form error:', error)
|
||||
return NextResponse.json({ error: 'Server error' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const messages = await prisma.contactMessage.findMany({
|
||||
where: { deletedAt: null },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
})
|
||||
return NextResponse.json({ data: messages })
|
||||
} catch {
|
||||
return NextResponse.json({ error: 'Server error' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { uploadImage, deleteImage } from '@/lib/cloudinary'
|
||||
import { requireAdmin } from '@/lib/auth-helpers'
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
try {
|
||||
await requireAdmin()
|
||||
const { file, folder = 'vesta-mugla' } = await req.json()
|
||||
if (!file) return NextResponse.json({ error: 'File required' }, { status: 400 })
|
||||
const result = await uploadImage(file, folder)
|
||||
return NextResponse.json({ data: result })
|
||||
} catch (error) {
|
||||
console.error('Upload error:', error)
|
||||
return NextResponse.json({ error: 'Upload failed' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(req: NextRequest) {
|
||||
try {
|
||||
await requireAdmin()
|
||||
const { publicId } = await req.json()
|
||||
await deleteImage(publicId)
|
||||
return NextResponse.json({ success: true })
|
||||
} catch {
|
||||
return NextResponse.json({ error: 'Delete failed' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user