Files
alla-allaos-fullstack/src/app/api/crm/approval/automation/pending/route.ts
phaichayon 3fdd681dd0 task-f.5
2026-06-27 10:04:43 +07:00

34 lines
1.1 KiB
TypeScript

import { NextResponse } from 'next/server';
import { getPendingApprovalQueue } from '@/features/foundation/approval-automation/server/service';
import { PERMISSIONS } from '@/lib/auth/rbac';
import { AuthError, requireOrganizationAccess } from '@/lib/auth/session';
export async function GET() {
try {
const { organization } = await requireOrganizationAccess({
permission: PERMISSIONS.crmApprovalAutomationRead
});
const result = await getPendingApprovalQueue(organization.id);
return NextResponse.json({
success: true,
time: new Date().toISOString(),
message: 'Pending approval automation queue loaded successfully',
...result
});
} catch (error) {
if (error instanceof AuthError) {
return NextResponse.json({ message: error.message }, { status: error.status });
}
if (error instanceof Error) {
return NextResponse.json({ message: error.message }, { status: 400 });
}
return NextResponse.json(
{ message: 'Unable to load pending approval queue' },
{ status: 500 }
);
}
}