Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 154 additions & 49 deletions apps/http-backend/src/routes/userRoutes/userRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
AvailableNodes,
TriggerSchema,
WorkflowSchema,
NodeSchema,
} from "@repo/common/zod";
import { GoogleSheetsNodeExecutor } from "@repo/nodes";
const router: Router = Router();
Expand All @@ -34,16 +35,18 @@ const router: Router = Router();
// }
// });

router.post("/createNode", async (req: AuthRequest, res: Response) => {
// ------------------- AVALIABLE TRIGGERS AND NODES CREATION AND FETCHING ROUTES --------------------------

router.post("/createAvaliableNode", async (req: AuthRequest, res: Response) => {
try {
const Data = req.body;
console.log("Thi is the Data from Normal Data", Data);
// console.log("Thi is the Data from Normal Data", Data);
const parseData = AvailableNodes.safeParse(Data);
console.log("This is the ParsedData", parseData.data);
// console.log("This is the ParsedData", parseData.data);
// if(!parseData) return
if (!parseData.success) {
return res.status(statusCodes.BAD_REQUEST).json({
message: "Invalid Inpput in node creating",
message: "Invalid Input in node creating",
});
}
const createNode = await prismaClient.availableNode.create({
Expand All @@ -58,7 +61,7 @@ router.post("/createNode", async (req: AuthRequest, res: Response) => {
Data: createNode,
});
} catch (e) {
console.log("This is the error from Node creatig", e);
console.log("This is the error from Node creating", e);
return res.status(statusCodes.INTERNAL_SERVER_ERROR).json({
message: "Internal server Error from Node creation",
});
Expand Down Expand Up @@ -90,7 +93,7 @@ router.get("/getAvailableNodes",
}
);

router.post("/createTriggers",
router.post("/createAvaliableTriggers",
userMiddleware,
async (req: AuthRequest, res: Response) => {
try {
Expand Down Expand Up @@ -148,6 +151,8 @@ router.get("/getAvailableTriggers",
}
);

//------------------------------ GET CREDENTIALS -----------------------------

router.get('/getCredentials/:type',
userMiddleware,
async (req: AuthRequest, res) =>{
Expand Down Expand Up @@ -195,6 +200,7 @@ router.get('/getCredentials/:type',
}
);

// ----------------------------------- CREATE WORKFLOW ---------------------------------

router.post("/create/workflow",
userMiddleware,
Expand All @@ -219,57 +225,18 @@ router.post("/create/workflow",
// Example JSON body to test this route:
/*
{
"Name": "My Workflow Trigger",
"AvailableTriggerId": "trigger123",
"Config": {
"key1": "value1",
"key2": 42,
"key3": true
},
"AvailableNodes": [
{
"name": "First Node",
"config": { "foo": "bar" },
"type": "TypeA",
"id": "nodeA1"
},
{
"name": "Second Node",
"config": { "baz": 123 },
"type": "TypeB",
"nodeId": "nodeB2"
},
{
"name": "Third Node",
"config": { "example": false },
"type": "TypeC",
"AvailabeNodeID": "nodeC3"
}
]
"Name":"workflow-1",
"UserId": "",
"Config":[{}]
}
*/
data: {
user: {
connect: { id: UserID },
},
description: "First Workflow",
description: "Workflow-generated",
name: ParsedData.data.Name,
config: ParsedData.data.Config,
Trigger: {
create: {
name: ParsedData.data.Name,
AvailableTriggerID: ParsedData.data.AvailableTriggerId,
config: ParsedData.data.Config,
},
},
nodes: {
create: ParsedData.data.AvailableNodes.map((x, index) => ({
name: x.Name,
AvailabeNodeID: x.AvailableNodeId,
config: x.Config,
position: index,
})),
},
},
});
return res.status(statusCodes.CREATED).json({
Expand All @@ -285,6 +252,8 @@ router.post("/create/workflow",
}
);

// ------------------------------------ FETCHING WORKFLOWS -----------------------------------

router.get("/workflows",
userMiddleware,
async (req: AuthRequest, res: Response) => {
Expand Down Expand Up @@ -313,6 +282,34 @@ router.get("/workflows",
}
);

router.get('/empty/workflow', userMiddleware, async(req:AuthRequest, res: Response)=>{
try{
if (!req.user)
return res
.status(statusCodes.UNAUTHORIZED)
.json({ message: "User is not logged in /not authorized" });
const userId = req.user.id;
const workflow = await prismaClient.workflow.findFirst({
where:{
userId: userId,
isEmpty: true
},
orderBy: {
createdAt: 'desc'
}
})
return res
.status(statusCodes.OK)
.json({ message: "Workflow fetched succesful", Data: workflow });

}catch(e){
console.log("The error is from getting wrkflows", e instanceof Error ? e.message : "UNKNOWN ERROR");

return res.status(statusCodes.INTERNAL_SERVER_ERROR).json({
meesage: "Internal Server Error From getting workflows for the user",
});
}
})
router.get("/workflow/:workflowId",
userMiddleware,
async (req: AuthRequest, res: Response) => {
Expand All @@ -329,6 +326,10 @@ router.get("/workflow/:workflowId",
id: workflowId,
userId: userId,
},
include:{
Trigger: true,
nodes: { orderBy: {position: 'asc'}}
}
});
if (!getWorkflow) {
return res.status(statusCodes.UNAUTHORIZED).json({
Expand All @@ -347,6 +348,110 @@ router.get("/workflow/:workflowId",
}
}
);

// ---------------------------------------- INSERTING DATA INTO NODES/ TRIGGER TABLE-----------------------------

router.post('/create/trigger', userMiddleware, async(req: AuthRequest, res: Response)=>{
try {
if (!req.user) {
return res.status(statusCodes.BAD_REQUEST).json({
message: "User is not logged in ",
});
}
const data = req.body;
const dataSafe = TriggerSchema.safeParse(data)
if(!dataSafe.success)
return res.status(statusCodes.BAD_REQUEST).json({
message: "Invalid input"
})
const createdTrigger = await prismaClient.trigger.create({
data:{
name: dataSafe.data.Name,
AvailableTriggerID: dataSafe.data.AvailableTriggerID,
config: dataSafe.data.Config,
workflowId: dataSafe.data.WorkflowId,
// trigger type pettla db lo ledu aa column
}
})

if(createdTrigger){
return res.status(statusCodes.CREATED).json({
message: "Trigger created",
data: createdTrigger
})
}
}catch(e){
console.log("This is the error from Trigger creatig", e);
return res.status(statusCodes.INTERNAL_SERVER_ERROR).json({
message: "Internal server Error from Trigger creation ",
});
}
Comment on lines +377 to +388

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Missing response when trigger creation returns falsy value.

If createdTrigger is falsy (e.g., null or undefined), the route handler doesn't send a response, leaving the client hanging. While Prisma typically throws on failure, this is still a defensive coding gap.

🔎 Suggested fix
       if(createdTrigger){
         return res.status(statusCodes.CREATED).json({
           message: "Trigger created",
           data: createdTrigger
         })
       }
+      return res.status(statusCodes.INTERNAL_SERVER_ERROR).json({
+        message: "Failed to create trigger"
+      });
     }catch(e){
🤖 Prompt for AI Agents
In apps/http-backend/src/routes/userRoutes/userRoutes.ts around lines 377 to
388, the handler returns a response only when createdTrigger is truthy and
leaves the client hanging when it's falsy; add an explicit else branch (or an
early return after the if) that sends an appropriate HTTP response (e.g., 500
INTERNAL_SERVER_ERROR or 400/404 with a clear message) when createdTrigger is
null/undefined, and ensure the catch block still logs the error and returns a
500 — keep responses consistent with existing statusCodes.


// INPUT FORMAT
// {
// "Name": "test-1",
// "AvailableTriggerID": "153c62fb-d61e-4e10-a8f4-d54780883200",
// "Config": {},
// "WorkflowId": "d0216fca-ca9b-4f3f-b01c-0a29b4305708",
// "TriggerType":""
// }
})

router.post('/create/node', userMiddleware, async(req: AuthRequest, res: Response)=>{
try{
if(!req.user){
return res.status(statusCodes.BAD_REQUEST).json({
message: "User is not logged in ",
});
}
const data = req.body;
console.log(data," from http-backeden" );

const dataSafe = NodeSchema.safeParse(data)
if(!dataSafe.success) {
return res.status(statusCodes.BAD_REQUEST).json({
message: "Invalid input"
})
}
const createdNode = await prismaClient.node.create({
data:{
name: dataSafe.data.Name,
workflowId: dataSafe.data.WorkflowId,
AvailableNodeID: dataSafe.data.AvailableNodeId,
// AvailabeNodeID: dataSafe.data.AvailableNodeId,
config: dataSafe.data.Config,
position: dataSafe.data.Position
}
})

if(createdNode)
return res.status(statusCodes.CREATED).json({
message: "Node created",
data: createdNode
})
}catch(e){
console.log("This is the error from Node creating", e);
return res.status(statusCodes.INTERNAL_SERVER_ERROR).json({
message: "Internal server Error from Node creation",
});
}
Comment on lines +427 to +437

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Missing response when node creation returns falsy value.

Same issue as with trigger creation - if createdNode is falsy, no response is sent.

🔎 Suggested fix
     if(createdNode) 
       return res.status(statusCodes.CREATED).json({
         message: "Node created",
         data: createdNode
       })
+    return res.status(statusCodes.INTERNAL_SERVER_ERROR).json({
+      message: "Failed to create node"
+    });
   }catch(e){
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if(createdNode)
return res.status(statusCodes.CREATED).json({
message: "Node created",
data: createdNode
})
}catch(e){
console.log("This is the error from Node creating", e);
return res.status(statusCodes.INTERNAL_SERVER_ERROR).json({
message: "Internal server Error from Node creation",
});
}
if(createdNode)
return res.status(statusCodes.CREATED).json({
message: "Node created",
data: createdNode
})
return res.status(statusCodes.INTERNAL_SERVER_ERROR).json({
message: "Failed to create node"
});
}catch(e){
console.log("This is the error from Node creating", e);
return res.status(statusCodes.INTERNAL_SERVER_ERROR).json({
message: "Internal server Error from Node creation",
});
}
🤖 Prompt for AI Agents
In apps/http-backend/src/routes/userRoutes/userRoutes.ts around lines 427-437,
the handler currently only returns a response when createdNode is truthy and
falls through silently when createdNode is falsy; update the control flow to
handle the falsy case by returning an appropriate HTTP response (e.g.,
res.status(statusCodes.BAD_REQUEST).json({ message: "Node not created" }) or
other domain-appropriate status) so the client always receives a response, and
optionally include minimal context or validation errors in the body; ensure you
do not leave an unhandled code path after the try block.

})


// ----------------------- GET WORKFLOW DATA(NODES, TRIGGER)---------------------

// router.get('/getworkflowData', userMiddleware, async(req: AuthRequest, res: Response)=>{
// try{
// if(!req.user){
// return res.status(statusCodes.BAD_REQUEST).json({
// message: "User is not logged in ",
// });
// }
// }catch(e){

// }
// })

router.get("/protected", userMiddleware, (req: AuthRequest, res) => {
return res.json({
ok: true,
Expand Down
2 changes: 1 addition & 1 deletion apps/http-backend/tsconfig.tsbuildinfo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"root":["./src/index.ts","./src/routes/nodes.routes.ts","./src/routes/userRoutes/userMiddleware.ts","./src/routes/userRoutes/userRoutes.ts"],"version":"5.7.3"}
{"root":["./src/index.ts","./src/routes/google_callback.ts","./src/routes/nodes.routes.ts","./src/routes/userroutes/usermiddleware.ts","./src/routes/userroutes/userroutes.ts"],"version":"5.7.3"}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash

# 1. Find any imports still referencing old casing patterns
echo "=== Checking for old casing in imports ==="
rg -i "from.*['\"].*userRoutes|from.*['\"].*userMiddleware|import.*['\"].*userRoutes|import.*['\"].*userMiddleware" --type=ts --type=js apps/http-backend/ 2>/dev/null || echo "No matches found for old casing"

echo ""
echo "=== Checking for imports of routes (any casing) ==="
rg "from.*['\"].*userroute|from.*['\"].*usermiddleware|import.*userroute|import.*usermiddleware" --type=ts --type=js apps/http-backend/ 2>/dev/null | head -20 || echo "No matches found"

# 2. Verify google_callback.ts exists
echo ""
echo "=== Checking for google_callback.ts ==="
fd "google_callback.ts" apps/http-backend/ 2>/dev/null || echo "google_callback.ts not found"

# 3. Verify the new userroutes directory structure
echo ""
echo "=== Checking userroutes directory structure ==="
fd "userroutes" apps/http-backend/src/ 2>/dev/null || echo "userroutes directory not found"

# 4. Check if old casing directory exists
echo ""
echo "=== Checking if old userRoutes directory still exists ==="
fd "userRoutes" apps/http-backend/src/ 2>/dev/null || echo "userRoutes directory not found"

# 5. List actual files in src/routes/
echo ""
echo "=== Contents of src/routes/ directory ==="
ls -la apps/http-backend/src/routes/ 2>/dev/null || echo "Directory not found"

Repository: Dev-Pross/BuildFlow

Length of output: 1344


🏁 Script executed:

#!/bin/bash

echo "=== Verifying source files referenced in tsconfig.tsbuildinfo ==="
cd apps/http-backend || exit

# Check each file mentioned in tsconfig.tsbuildinfo
echo "1. Checking ./src/index.ts:"
test -f src/index.ts && echo "✓ exists" || echo "✗ not found"

echo "2. Checking ./src/routes/google_callback.ts:"
test -f src/routes/google_callback.ts && echo "✓ exists" || echo "✗ not found"

echo "3. Checking ./src/routes/nodes.routes.ts:"
test -f src/routes/nodes.routes.ts && echo "✓ exists" || echo "✗ not found"

echo "4. Checking ./src/routes/userroutes/usermiddleware.ts:"
test -f src/routes/userroutes/usermiddleware.ts && echo "✓ exists" || echo "✗ not found"

echo "5. Checking ./src/routes/userroutes/userroutes.ts:"
test -f src/routes/userroutes/userroutes.ts && echo "✓ exists" || echo "✗ not found"

echo ""
echo "=== Full directory tree of src/routes ==="
find src/routes -type f -name "*.ts" | sort

Repository: Dev-Pross/BuildFlow

Length of output: 576


Critical: tsconfig.tsbuildinfo references non-existent file paths — build will fail.

The auto-generated tsconfig.tsbuildinfo declares source roots using lowercase paths (userroutes/usermiddleware.ts, userroutes/userroutes.ts) that do not exist in the actual source tree. The directories and files remain in the original camelCase (userRoutes/userMiddleware.ts). Additionally, all source file imports still reference the old camelCase paths:

  • nodes.routes.ts and google_callback.ts import from ./userRoutes/userMiddleware.js
  • userRoutes/userRoutes.ts imports from ./userMiddleware.js
  • index.ts imports from ./routes/userRoutes/userRoutes.js

This mismatch will cause TypeScript compilation to fail. Either rename the actual directories/files to lowercase and update all imports, or revert the case changes in tsconfig.tsbuildinfo to match the current source structure.

🤖 Prompt for AI Agents
In apps/http-backend/tsconfig.tsbuildinfo around line 1, the buildinfo lists
source root paths using lowercase `userroutes/*` that don't match the actual
camelCase files (`userRoutes/userMiddleware.ts`, `userRoutes/userRoutes.ts`),
causing the build to fail; fix by either (A) reverting the entries in
tsconfig.tsbuildinfo to the correct camelCase paths to match the real files, or
(B) delete tsconfig.tsbuildinfo and run a clean TypeScript build so the
.tsbuildinfo is regenerated with the correct paths; after that verify and, if
needed, update any import statements in src files to consistently use the actual
camelCase paths (or alternatively rename the filesystem to the lowercase names
if you prefer that canonicalization), then re-run the build to confirm the issue
is resolved.

44 changes: 0 additions & 44 deletions apps/web/app/api/google-sheets/documents/route.ts

This file was deleted.

38 changes: 0 additions & 38 deletions apps/web/app/api/google-sheets/tabs/route.ts

This file was deleted.

Loading