37 lines
979 B
TypeScript
37 lines
979 B
TypeScript
import { NextResponse } from 'next/server';
|
|
import { supabaseAdmin } from '@/lib/supabase';
|
|
|
|
// GET /api/admin/jobs/[id]/actions - Get all job actions for a service record
|
|
export async function GET(
|
|
request: Request,
|
|
{ params }: { params: Promise<{ id: string }> }
|
|
) {
|
|
try {
|
|
const { id } = await params;
|
|
const serviceRecordId = id;
|
|
|
|
const { data, error } = await supabaseAdmin
|
|
.from('JobActions')
|
|
.select('*')
|
|
.eq('service_record', serviceRecordId)
|
|
.order('created_at', { ascending: false });
|
|
|
|
if (error) {
|
|
console.error('Supabase error:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to fetch job actions', details: error.message },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
|
|
return NextResponse.json(data || []);
|
|
} catch (error) {
|
|
console.error('Error fetching job actions:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to fetch job actions' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|
|
|