npm run build
This commit is contained in:
@@ -67,6 +67,16 @@ export async function saveFlow(prevState: State, formData: FormData): Promise<St
|
||||
|
||||
try {
|
||||
if (id) {
|
||||
// Check if path is unique before updating
|
||||
const checkStmt = db.prepare('SELECT id FROM flows WHERE path = ? AND id != ?');
|
||||
const existing = checkStmt.get(path, id);
|
||||
if (existing) {
|
||||
return {
|
||||
success: false,
|
||||
message: 'A flow with this path already exists.',
|
||||
errors: [{ path: ['path'], message: 'A flow with this path already exists.', code: 'custom' }],
|
||||
};
|
||||
}
|
||||
// Update existing flow
|
||||
const stmt = db.prepare(
|
||||
'UPDATE flows SET name = ?, description = ?, path = ?, updatedAt = CURRENT_TIMESTAMP WHERE id = ?'
|
||||
@@ -101,6 +111,10 @@ export async function saveFlow(prevState: State, formData: FormData): Promise<St
|
||||
|
||||
export async function deleteFlow(id: number): Promise<{ success: boolean, message: string }> {
|
||||
try {
|
||||
// Prevent deletion of the default flow (ID 1)
|
||||
if (id === 1) {
|
||||
return { success: false, message: "The default flow cannot be deleted." };
|
||||
}
|
||||
const stmt = db.prepare('DELETE FROM flows WHERE id = ?');
|
||||
stmt.run(id);
|
||||
revalidatePath('/admin/flows');
|
||||
|
||||
Reference in New Issue
Block a user