79 lines
2.4 KiB
TypeScript
79 lines
2.4 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
import { supabaseAdmin } from '@/lib/supabase';
|
|
|
|
// PUT /api/admin/jobs/[id]/actions/[actionId] - Update a job action
|
|
export async function PUT(
|
|
request: Request,
|
|
{ params }: { params: Promise<{ id: string; actionId: string }> }
|
|
) {
|
|
try {
|
|
const { actionId } = await params;
|
|
const jobActionId = parseInt(actionId);
|
|
const body = await request.json();
|
|
const { action_type, part_type, part_id, custom_price, labour_fee } = body;
|
|
|
|
const updateData: any = {};
|
|
if (action_type !== undefined) updateData.action_type = action_type;
|
|
if (part_type !== undefined) updateData.part_type = part_type || null;
|
|
if (part_id !== undefined) updateData.part_id = part_id || null;
|
|
if (custom_price !== undefined) updateData.custom_price = custom_price;
|
|
if (labour_fee !== undefined) updateData.labour_fee = labour_fee;
|
|
|
|
const { data, error } = await supabaseAdmin
|
|
.from('JobActions')
|
|
.update(updateData)
|
|
.eq('id', jobActionId)
|
|
.select()
|
|
.single();
|
|
|
|
if (error) {
|
|
console.error('Supabase error:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to update job action', details: error.message },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
|
|
return NextResponse.json({ message: 'Job action updated successfully', data });
|
|
} catch (error) {
|
|
console.error('Error updating job action:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to update job action' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|
|
|
|
// DELETE /api/admin/jobs/[id]/actions/[actionId] - Delete a job action
|
|
export async function DELETE(
|
|
request: Request,
|
|
{ params }: { params: Promise<{ id: string; actionId: string }> }
|
|
) {
|
|
try {
|
|
const { actionId } = await params;
|
|
const jobActionId = parseInt(actionId);
|
|
|
|
const { error } = await supabaseAdmin
|
|
.from('JobActions')
|
|
.delete()
|
|
.eq('id', jobActionId);
|
|
|
|
if (error) {
|
|
console.error('Supabase error:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to delete job action', details: error.message },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
|
|
return NextResponse.json({ message: 'Job action deleted successfully' });
|
|
} catch (error) {
|
|
console.error('Error deleting job action:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to delete job action' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|
|
|