Controller and routing for the Vizualtion and builder
This commit is contained in:
@@ -0,0 +1,327 @@
|
||||
import { Response } from "express";
|
||||
|
||||
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||
import {
|
||||
deleteAssetModel,
|
||||
getFloorItems,
|
||||
replaceEventDatas,
|
||||
setAssetModel,
|
||||
updateAssetPositionRotation,
|
||||
} from "../../../../shared/services/builder/assetService.ts";
|
||||
|
||||
export const CreateAssetController = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, userId } = req.user || {};
|
||||
const {
|
||||
modelUuid,
|
||||
modelName,
|
||||
position,
|
||||
rotation,
|
||||
eventData,
|
||||
modelfileID,
|
||||
isLocked,
|
||||
isVisible,
|
||||
projectId,
|
||||
} = req.body;
|
||||
if (
|
||||
!organization ||
|
||||
!userId ||
|
||||
!isLocked ||
|
||||
!isVisible ||
|
||||
!position ||
|
||||
!rotation ||
|
||||
!modelfileID ||
|
||||
!modelName ||
|
||||
!projectId ||
|
||||
!modelUuid
|
||||
) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
organization,
|
||||
userId,
|
||||
modelUuid,
|
||||
modelName,
|
||||
position,
|
||||
rotation,
|
||||
eventData,
|
||||
modelfileID,
|
||||
isLocked,
|
||||
isVisible,
|
||||
projectId,
|
||||
};
|
||||
const result = await setAssetModel(data);
|
||||
|
||||
switch (result.status) {
|
||||
case "User not found":
|
||||
res.status(200).json({
|
||||
message: "User not found",
|
||||
});
|
||||
break;
|
||||
case "Project not found":
|
||||
res.status(200).json({
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "Updated successfully":
|
||||
res.status(200).json(result.data);
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
message: "Model stored successfully",
|
||||
});
|
||||
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 DeleteAssetController = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, userId } = req.user || {};
|
||||
const { modelUuid, modelName, projectId } = req.body;
|
||||
if (!organization || !userId || !modelUuid || !projectId || !modelName) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await deleteAssetModel({
|
||||
organization,
|
||||
modelName,
|
||||
modelUuid,
|
||||
projectId,
|
||||
userId,
|
||||
});
|
||||
|
||||
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 "model not found":
|
||||
res.status(404).json({
|
||||
message: "Model not found",
|
||||
});
|
||||
break;
|
||||
case "Failed to archive asset":
|
||||
res.status(200).json({
|
||||
message: "Failed to archive asset",
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
message: "Asset Deleted successfully",
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
}
|
||||
};
|
||||
export const GetAssetController = 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 result = await getFloorItems({
|
||||
organization,
|
||||
projectId,
|
||||
userId,
|
||||
});
|
||||
|
||||
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 "floorItems not found":
|
||||
res.status(404).json({
|
||||
message: "floorItems not found",
|
||||
});
|
||||
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",
|
||||
});
|
||||
}
|
||||
};
|
||||
export const ReplaceEventDataController = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, userId } = req.user || {};
|
||||
const { modelUuid, eventData, projectId } = req.body;
|
||||
if (!organization || !userId || !projectId || !modelUuid || !eventData) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await replaceEventDatas({
|
||||
modelUuid,
|
||||
organization,
|
||||
eventData,
|
||||
projectId,
|
||||
userId,
|
||||
});
|
||||
|
||||
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 "Model not for this UUID":
|
||||
res.status(404).json({
|
||||
message: "Model not for this UUID",
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({ message: "Data updated successfully" });
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
}
|
||||
};
|
||||
export const AssetUpdatePosRotController = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, userId } = req.user || {};
|
||||
const {
|
||||
modelUuid,
|
||||
modelName,
|
||||
position,
|
||||
rotation,
|
||||
isLocked,
|
||||
isVisible,
|
||||
projectId,
|
||||
} = req.body;
|
||||
if (
|
||||
!organization ||
|
||||
!userId ||
|
||||
!isLocked ||
|
||||
!isVisible ||
|
||||
!position ||
|
||||
!rotation ||
|
||||
!modelName ||
|
||||
!projectId ||
|
||||
!modelUuid
|
||||
) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await updateAssetPositionRotation({
|
||||
organization,
|
||||
userId,
|
||||
modelUuid,
|
||||
modelName,
|
||||
position,
|
||||
rotation,
|
||||
isLocked,
|
||||
isVisible,
|
||||
projectId,
|
||||
});
|
||||
|
||||
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 "Asset not found":
|
||||
res.status(404).json({
|
||||
message: "Asset not found",
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({ message: "Asset updated successfully" });
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user