53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
'use server'
|
|
|
|
import { supabase } from '@/lib/supabase'
|
|
import { revalidatePath } from 'next/cache'
|
|
|
|
export async function getPosyanduWithReviews() {
|
|
const { data: posyandu, error } = await supabase
|
|
.from('detail_posyandu')
|
|
.select(`
|
|
*,
|
|
petugas:petugas_posyandu_lokal(*),
|
|
reviews:ulasan_posyandu(
|
|
*,
|
|
nama_pengulas
|
|
)
|
|
`)
|
|
.order('nama_posyandu', { ascending: true })
|
|
|
|
if (error) {
|
|
console.error('Error fetching posyandu:', error)
|
|
return []
|
|
}
|
|
|
|
return posyandu
|
|
}
|
|
|
|
export async function submitReview(formData: {
|
|
posyandu_id: string
|
|
nama_pengulas: string
|
|
rating: number
|
|
comment: string
|
|
}) {
|
|
const { error } = await supabase
|
|
.from('ulasan_posyandu')
|
|
.insert([
|
|
{
|
|
posyandu_id: formData.posyandu_id,
|
|
rating: formData.rating,
|
|
ulasan: formData.comment,
|
|
nama_pengulas: formData.nama_pengulas, // Add this field to the formData or handle it separately
|
|
created_at: new Date().toISOString()
|
|
}
|
|
])
|
|
|
|
if (error) {
|
|
console.error('Error submitting review:', error)
|
|
return { success: false, error: error.message }
|
|
}
|
|
|
|
revalidatePath('/user-dashboard/lokasi-posyandu')
|
|
return { success: true }
|
|
}
|