119 lines
2.7 KiB
TypeScript
119 lines
2.7 KiB
TypeScript
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 || !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(req.body);
|
|
|
|
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) {
|
|
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(200).json(result.data);
|
|
break;
|
|
case "Success":
|
|
res.status(200).json(result.data);
|
|
break;
|
|
default:
|
|
res.status(500).json({
|
|
message: "Internal server error",
|
|
});
|
|
break;
|
|
}
|
|
} catch (error) {
|
|
res.status(500).json({
|
|
message: "Unknown error",
|
|
});
|
|
}
|
|
};
|