corrad-bp/server/api/process/[id].get.js
Afiq 44baddb6e3 Enhance Process Builder with Critical Fixes and Database Integration
- Implemented complete API system with REST endpoints for all process operations, including CRUD functionality.
- Added support for direct process linking via URL parameters, improving navigation and usability.
- Enhanced save functionality with success/error notifications and improved state management.
- Fixed navigation issues, including unsaved changes detection and automatic URL synchronization.
- Resolved Vue Flow interference, allowing for seamless connector dragging between nodes.
- Ensured backward compatibility for legacy process definitions, automatically upgrading them.
- Introduced comprehensive toast notifications for user feedback on all operations.
- Optimized performance by reducing re-renders and improving memory management.
- Enhanced error handling with robust validation and graceful recovery throughout the system.
- Updated UI consistency across form builder and process builder management interfaces.
2025-05-30 16:36:32 +08:00

57 lines
1.3 KiB
JavaScript

import { PrismaClient } from '@prisma/client';
// Initialize Prisma client
const prisma = new PrismaClient();
export default defineEventHandler(async (event) => {
try {
// Get the process ID from the route parameter
const processId = getRouterParam(event, 'id');
if (!processId) {
return {
success: false,
error: 'Process ID is required'
};
}
// Check if the ID is a UUID or numeric ID
const isUUID = processId.length === 36 && processId.includes('-');
// Find the process by UUID or ID
const process = await prisma.process.findFirst({
where: isUUID
? { processUUID: processId }
: { processID: parseInt(processId) },
include: {
creator: {
select: {
userID: true,
userFullName: true,
userUsername: true
}
}
}
});
if (!process) {
return {
success: false,
error: 'Process not found'
};
}
return {
success: true,
process
};
} catch (error) {
console.error('Error fetching process:', error);
return {
success: false,
error: 'Failed to fetch process',
details: process.env.NODE_ENV === 'development' ? error.message : undefined
};
}
});