From 83ab84dfcd101c709ad33a717993dc0f9b49de95 Mon Sep 17 00:00:00 2001 From: Vamsi_0 Date: Wed, 14 Jan 2026 14:11:18 +0530 Subject: [PATCH] refactor: improve user routes, logging, and component formatting - Streamlined error handling in userRoutes for better clarity and consistency. - Cleaned up unnecessary whitespace and improved console logging in WorkflowCanvas and ConfigModal components. - Updated Prisma schema to enhance relationships and added optional fields for better flexibility in Credential and Node models. --- .../src/routes/userRoutes/userRoutes.ts | 19 +++++++------------ .../workflows/[id]/components/ConfigModal.tsx | 9 +++++---- apps/web/app/workflows/[id]/page.tsx | 2 +- packages/db/prisma/schema.prisma | 19 +++++++++++-------- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/apps/http-backend/src/routes/userRoutes/userRoutes.ts b/apps/http-backend/src/routes/userRoutes/userRoutes.ts index 6ec7fe3..51e115e 100644 --- a/apps/http-backend/src/routes/userRoutes/userRoutes.ts +++ b/apps/http-backend/src/routes/userRoutes/userRoutes.ts @@ -233,11 +233,9 @@ router.get( "Error Fetching the credentials ", e instanceof Error ? e.message : "Unknown reason" ); - return res - .status(statusCodes.INTERNAL_SERVER_ERROR) - .json({ - message: "Internal server error from fetching the credentials", - }); + return res.status(statusCodes.INTERNAL_SERVER_ERROR).json({ + message: "Internal server error from fetching the credentials", + }); } } ); @@ -433,7 +431,6 @@ router.get( } ); - // router.put("/workflow/update" , userMiddleware , (req : AuthRequest , res : Response) => { // }) @@ -508,7 +505,7 @@ router.post( }); } const data = req.body; - console.log(" from http-backeden" , data); + console.log(" from http-backeden", data); const dataSafe = NodeSchema.safeParse(data); console.log("The error is ", dataSafe.error); @@ -525,10 +522,10 @@ router.post( data: { name: dataSafe.data.Name, workflowId: dataSafe.data.WorkflowId, + config: dataSafe.data.Config || {}, + stage: Number(dataSafe.data.stage ?? 0), + position: {}, AvailableNodeID: dataSafe.data.AvailableNodeId, - config: {}, // Config is an empty object by default - stage: Number(dataSafe.data.stage), - position: {} }, }); @@ -628,8 +625,6 @@ router.put( } ); - - router.get("/protected", userMiddleware, (req: AuthRequest, res) => { return res.json({ ok: true, diff --git a/apps/web/app/workflows/[id]/components/ConfigModal.tsx b/apps/web/app/workflows/[id]/components/ConfigModal.tsx index 6a4d741..70525f9 100644 --- a/apps/web/app/workflows/[id]/components/ConfigModal.tsx +++ b/apps/web/app/workflows/[id]/components/ConfigModal.tsx @@ -3,7 +3,6 @@ import { getNodeConfig } from "@/app/lib/nodeConfigs"; import { useState } from "react"; import { HOOKS_URL } from "@repo/common/zod"; -import { userAction } from "@/store/slices/userSlice"; import { useAppSelector } from "@/app/hooks/redux"; interface ConfigModalProps { isOpen: boolean; @@ -19,10 +18,12 @@ export default function ConfigModal({ onSave, }: ConfigModalProps) { const [loading, setLoading] = useState(false); - + const userId = useAppSelector( + (state) => state.user.userId + ) as unknown as string; + console.log("we are getting this userId from ConfigModal", userId); if (!isOpen || !selectedNode) return null; - const userId = useAppSelector((state) => state.user.userId) as unknown as string; - console.log("we are getting this userId from ConfigModal" , userId) + const handleSave = async () => { setLoading(true); try { diff --git a/apps/web/app/workflows/[id]/page.tsx b/apps/web/app/workflows/[id]/page.tsx index e4c92ca..9de046f 100644 --- a/apps/web/app/workflows/[id]/page.tsx +++ b/apps/web/app/workflows/[id]/page.tsx @@ -430,7 +430,7 @@ export default function WorkflowCanvas() { const isTrigger = nodes.find((n) => n.id === nodeId)?.data.nodeType === "trigger"; if (isTrigger) { - await api.triggers.update({ TriggerId: nodeId, Config: config}); + await api.triggers.update({ TriggerId: nodeId, Config: config }); } else { await api.nodes.update({ NodeId: nodeId, Config: config }); } diff --git a/packages/db/prisma/schema.prisma b/packages/db/prisma/schema.prisma index 2773c98..d0d6bd3 100644 --- a/packages/db/prisma/schema.prisma +++ b/packages/db/prisma/schema.prisma @@ -19,14 +19,15 @@ model User { } model Credential { - id String @id @default(uuid()) + id String @id @default(uuid()) userId String type String config Json nodeId String? - node Node? @relation(fields: [nodeId], references: [id]) - user User @relation(fields: [userId], references: [id]) - // Node_Node_CredentialsIDToCredential Node[] @relation("Node_CredentialsIDToCredential") + node Node? @relation(fields: [nodeId], references: [id]) + user User @relation(fields: [userId], references: [id]) + Node_Node_CredentialsIDToCredential Node[] @relation("Node_CredentialsIDToCredential") + Trigger Trigger[] } model Trigger { @@ -35,7 +36,9 @@ model Trigger { config Json workflowId String? @unique AvailableTriggerID String + CredentialsID String? triggerType AvailableTrigger @relation(fields: [AvailableTriggerID], references: [id]) + Credential Credential? @relation(fields: [CredentialsID], references: [id]) workflow Workflow? @relation(fields: [workflowId], references: [id]) } @@ -62,14 +65,14 @@ model Node { id String @id @default(uuid()) name String config Json - position Json stage Int workflowId String? AvailableNodeID String - // CredentialsID String + CredentialsID String? + position Json? credentials Credential[] - AvailableNode AvailableNode? @relation(fields: [AvailableNodeID], references: [id]) - // Credential_Node_CredentialsIDToCredential Credential @relation("Node_CredentialsIDToCredential", fields: [CredentialsID], references: [id], onDelete: Cascade) + AvailableNode AvailableNode @relation(fields: [AvailableNodeID], references: [id]) + Credential_Node_CredentialsIDToCredential Credential? @relation("Node_CredentialsIDToCredential", fields: [CredentialsID], references: [id]) workflow Workflow? @relation(fields: [workflowId], references: [id]) executions NodeExecution[] }