Update application features and add scripts (core changes)
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
'use server'
|
||||
|
||||
import { db } from '@/lib/db'
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { RoomType } from '@prisma/client'
|
||||
|
||||
export type RoomInput = {
|
||||
slug: string
|
||||
type: RoomType
|
||||
nameTr: string
|
||||
nameEn: string
|
||||
nameDe: string
|
||||
descriptionTr: string
|
||||
descriptionEn: string
|
||||
descriptionDe: string
|
||||
capacity: number
|
||||
price: number | null
|
||||
imageUrl: string | null
|
||||
images: string[]
|
||||
amenities: string[]
|
||||
available: boolean
|
||||
featured: boolean
|
||||
}
|
||||
|
||||
export async function createRoom(data: RoomInput) {
|
||||
try {
|
||||
const room = await db.room.create({
|
||||
data,
|
||||
})
|
||||
|
||||
revalidatePath('/[locale]/admin/rooms', 'page')
|
||||
revalidatePath('/[locale]/dairelerimiz', 'page')
|
||||
revalidatePath('/[locale]', 'page')
|
||||
|
||||
return { success: true, room }
|
||||
} catch (error) {
|
||||
console.error('Failed to create room:', error)
|
||||
return { success: false, error: 'Oda oluşturulurken bir hata oluştu.' }
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateRoom(id: string, data: RoomInput) {
|
||||
try {
|
||||
const room = await db.room.update({
|
||||
where: { id },
|
||||
data,
|
||||
})
|
||||
|
||||
revalidatePath('/[locale]/admin/rooms', 'page')
|
||||
revalidatePath('/[locale]/dairelerimiz', 'page')
|
||||
revalidatePath('/[locale]', 'page')
|
||||
|
||||
return { success: true, room }
|
||||
} catch (error) {
|
||||
console.error('Failed to update room:', error)
|
||||
return { success: false, error: 'Oda güncellenirken bir hata oluştu.' }
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteRoom(id: string) {
|
||||
try {
|
||||
await db.room.delete({
|
||||
where: { id },
|
||||
})
|
||||
|
||||
revalidatePath('/[locale]/admin/rooms', 'page')
|
||||
revalidatePath('/[locale]/dairelerimiz', 'page')
|
||||
revalidatePath('/[locale]', 'page')
|
||||
|
||||
return { success: true }
|
||||
} catch (error) {
|
||||
console.error('Failed to delete room:', error)
|
||||
return { success: false, error: 'Oda silinirken bir hata oluştu.' }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
'use server'
|
||||
|
||||
import { uploadToOpeninary } from '@/lib/openinary'
|
||||
|
||||
export async function uploadImageAction(formData: FormData) {
|
||||
try {
|
||||
const file = formData.get('file') as File
|
||||
if (!file) throw new Error('No file provided')
|
||||
|
||||
const folder = (formData.get('folder') as string) || 'starapart'
|
||||
|
||||
const result = await uploadToOpeninary(file, folder)
|
||||
let finalUrl = result.url
|
||||
if (finalUrl && finalUrl.startsWith('/')) {
|
||||
finalUrl = `${process.env.NEXT_PUBLIC_OPENINARY_URL || 'https://media.ayris.tech'}${finalUrl}`
|
||||
}
|
||||
|
||||
return { success: true, url: finalUrl }
|
||||
} catch (error: any) {
|
||||
console.error('Upload error:', error)
|
||||
return { success: false, error: error.message }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user