This commit is contained in:
phaichayon
2026-06-27 10:04:43 +07:00
parent 2ace5dbb83
commit 3fdd681dd0
29 changed files with 8593 additions and 15 deletions

View File

@@ -0,0 +1,33 @@
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 }
);
}
}

View File

@@ -0,0 +1,29 @@
import { NextResponse } from 'next/server';
import { processApprovalAutomation } from '@/features/foundation/approval-automation/server/service';
import { PERMISSIONS } from '@/lib/auth/rbac';
import { AuthError, requireOrganizationAccess } from '@/lib/auth/session';
export async function POST() {
try {
const { organization, session } = await requireOrganizationAccess({
permission: PERMISSIONS.crmApprovalAutomationRun
});
const result = await processApprovalAutomation(organization.id, session.user.id);
return NextResponse.json({
success: true,
message: 'Approval automation completed 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 run approval automation' }, { status: 500 });
}
}