quest-vorteq/src/app/api/allocation-requests/[id]/cancel/route.ts
Lorentz Hinrichsen e60e07c9a5
Some checks failed
Build and Deploy / build (push) Successful in 4m39s
Build and Deploy / deploy (push) Failing after 1s
feat: add shipment request (C-013) and allocation request (C-014) cart workflows
Multi-step cart workflows for both shipment and allocation requests:
- Ship-to address selection from Epicor portal_CustomerShipToAddresses
- Inventory browser dialog (shipment) / coil browser dialog (allocation)
- Cart persistence in DB with duplicate detection
- Details form (order#, PO#, pickup date, instructions, email recipients)
- Review & submit with confirmation dialog
- Cancel with permission gate and confirmation
- Shared components: stepper, ship-to selector, cart table, header form, review
- 16 API routes, 4 services, 13 components, 6 pages
- Phase 2 complete: 16/16 tasks done

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 10:37:38 -05:00

36 lines
1.2 KiB
TypeScript

import { NextResponse } from 'next/server';
import { getQuestSession, getActiveCompany, requirePermission } from '@/lib/permissions';
import { cancelRequest } from '@/services/alloc-requests';
/**
* POST: Cancel an allocation request
*/
export async function POST(
_request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
const session = await getQuestSession();
const activeCompany = await getActiveCompany();
if (!session || !activeCompany) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
try {
// Note: using cancel_shipment_request permission for now
// If a separate cancel_allocation_request permission is needed, add it later
await requirePermission('cancel_shipment_request');
} catch {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
}
try {
const { id } = await params;
const cancelled = await cancelRequest(id, activeCompany.id, session.user.id);
return NextResponse.json(cancelled);
} catch (error) {
console.error('Error cancelling allocation request:', error);
const message = error instanceof Error ? error.message : 'Internal server error';
return NextResponse.json({ error: message }, { status: 500 });
}
}