162 lines
3.7 KiB
TypeScript
162 lines
3.7 KiB
TypeScript
import { Response } from "express";
|
|
import { WallItems } from "../../../../shared/services/builder/wallService.ts";
|
|
import { error } from "console";
|
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
|
export const WallSetup = async (
|
|
req: AuthenticatedRequest,
|
|
res: Response
|
|
): Promise<void> => {
|
|
try {
|
|
const { userId, organization } = req.user || {};
|
|
const {
|
|
modelUuid,
|
|
modelName,
|
|
position,
|
|
type,
|
|
csgposition,
|
|
csgscale,
|
|
quaternion,
|
|
scale,
|
|
projectId,
|
|
} = req.body;
|
|
if (
|
|
!modelUuid ||
|
|
!modelName ||
|
|
!position ||
|
|
!type ||
|
|
!projectId ||
|
|
!csgscale ||
|
|
!csgposition ||
|
|
!quaternion ||
|
|
!scale ||
|
|
!organization ||
|
|
!userId
|
|
) {
|
|
res.status(400).json({
|
|
message: "All fields are required!",
|
|
});
|
|
return;
|
|
}
|
|
const result = await WallItems.setWallItems({
|
|
projectId,
|
|
modelUuid,
|
|
modelName,
|
|
position,
|
|
type,
|
|
csgposition,
|
|
csgscale,
|
|
quaternion,
|
|
scale,
|
|
organization,
|
|
userId,
|
|
});
|
|
switch (result.status) {
|
|
case "User not found":
|
|
res.status(404).json({ message: "User not found" });
|
|
break;
|
|
case "Updated successfully":
|
|
res.status(200).json(result.data);
|
|
break;
|
|
case "wall Item created successfully":
|
|
res.status(201).json(result.data);
|
|
break;
|
|
default:
|
|
res.status(500).json(error);
|
|
break;
|
|
}
|
|
} catch (error) {
|
|
res.status(500).json({
|
|
message: "Unknown error",
|
|
});
|
|
return;
|
|
}
|
|
};
|
|
export const WallGet = 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 WallItems.getWallItems({
|
|
organization,
|
|
userId,
|
|
projectId,
|
|
});
|
|
|
|
switch (result.status) {
|
|
case "User not found":
|
|
res.status(404).json({ message: "User not found" });
|
|
break;
|
|
case "wallitems not found":
|
|
res.status(404).json({
|
|
message: "wallitems 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 WallDelete = async (
|
|
req: AuthenticatedRequest,
|
|
res: Response
|
|
): Promise<void> => {
|
|
try {
|
|
const { organization, userId } = req.user || {};
|
|
const { projectId, modelName, modelUuid } = req.body;
|
|
if (!organization || !userId || !projectId || !modelName || !modelUuid) {
|
|
res.status(400).json({
|
|
message: "All fields are required",
|
|
});
|
|
return;
|
|
}
|
|
const result = await WallItems.deleteWallItems({
|
|
organization,
|
|
userId,
|
|
projectId,
|
|
modelName,
|
|
modelUuid,
|
|
});
|
|
|
|
switch (result.status) {
|
|
case "User not found":
|
|
res.status(404).json({ message: "User not found" });
|
|
break;
|
|
case "model not found":
|
|
res.status(404).json({
|
|
message: "model 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",
|
|
});
|
|
}
|
|
};
|