Controller and routing for the Vizualtion and builder

This commit is contained in:
2025-05-29 15:34:12 +05:30
parent bea6044b25
commit c38a698692
34 changed files with 2523 additions and 926 deletions

View File

@@ -0,0 +1,131 @@
import { Response } from "express";
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
import {
getEnvironment,
setEnvironment,
} from "../../../../shared/services/builder/EnvironmentService.ts";
export const SetEnvironmentController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { organization, userId } = req.user || {};
const {
roofVisibility,
renderDistance,
limitDistance,
wallVisibility,
shadowVisibility,
projectId,
} = req.body;
if (
!organization ||
!userId ||
!roofVisibility ||
!wallVisibility ||
!renderDistance ||
!limitDistance ||
!shadowVisibility ||
!projectId
) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const data = {
roofVisibility,
wallVisibility,
shadowVisibility,
organization,
projectId,
userId,
renderDistance,
limitDistance,
};
const result = await setEnvironment(data);
switch (result.status) {
case "User not found":
res.status(404).json({
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "environments updated":
res.status(200).json(result.data);
break;
case "Success":
res.status(201).json(result.data);
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
console.log("error: ", error);
res.status(500).json({
message: "Unknown error",
});
}
};
export const GetEnvironmentController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { organization, userId } = req.user || {};
const { projectId } = req.params;
if (!organization || !userId || !projectId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const data = {
organization,
projectId,
userId,
};
const result = await getEnvironment(data);
switch (result.status) {
case "User not found":
res.status(404).json({
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Environment Not found for the User":
res.status(404).json({
message: "Environment Not found for the User",
});
break;
case "Success":
res.status(200).json(result.data);
break;
default:
res.status(500).json({
message: "Internal server error",
});
break;
}
} catch (error) {
console.log("error: ", error);
res.status(500).json({
message: "Unknown error",
});
}
};