Widget updated

This commit is contained in:
2025-06-25 18:15:27 +05:30
parent 15abd00e0e
commit dd91f4ccb9
4 changed files with 136 additions and 25 deletions

View File

@@ -4,6 +4,7 @@ import {
Add3DWidget,
Delete3Dwidget,
Get3Dwidget,
GetSingle3Dwidget,
Update3Dwidget,
} from "../../../../shared/services/visualization/widget3dService.ts";
@@ -57,16 +58,16 @@ export const Add3dWidgetController = async (
message: "Zone not found",
});
break;
case "Widget not updated":
res.status(200).json({
message: "Widget not updated",
});
break;
case "widget update successfully":
case "3dwidget update successfully":
res.status(200).json({
message: "widget update successfully",
});
break;
case "3dWidget not updated":
res.status(200).json({
message: "Widget3d update unsuccessfull",
});
break;
case "Widget 3d not created":
res.status(200).json({
message: "Widget 3d not created",
@@ -309,3 +310,61 @@ export const Get3DWidgetController = async (
return;
}
};
export const Get3DSingleWidgetController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { projectId, widgetID, versionId } = req.params;
if (!userId || !organization || !projectId || !widgetID || !versionId) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await GetSingle3Dwidget({
organization,
userId,
widgetID,
versionId,
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 "Version Data not found":
res.status(404).json({
message: "Version Data not found",
});
break;
case "Widget not found":
res.status(200).json({
message: "Widget 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",
});
return;
}
};

View File

@@ -4,32 +4,28 @@ import { tokenValidator } from "../../../../shared/utils/token.ts";
import {
Add3dWidgetController,
Delete3DwidgetController,
Get3DSingleWidgetController,
Get3DWidgetController,
Update3DwidgetController,
} from "../../v1Controllers/vizualizationController/widget3Dcontroller.ts";
const V1Widget3d = express.Router();
V1Widget3d.post(
"/widget3d/save",
tokenValidator,
Add3dWidgetController
);
V1Widget3d.patch(
"/widget3d/update",
tokenValidator,
Update3DwidgetController
);
V1Widget3d.patch("/widget3d/update", tokenValidator, Update3DwidgetController);
V1Widget3d.get(
"/widget3d/data/:zoneUuid/:projectId/:versionId",
tokenValidator,
Get3DWidgetController
);
V1Widget3d.patch(
"/widget3d/delete",
V1Widget3d.get(
"/widget3dData/:widgetID/:projectId/:versionId",
tokenValidator,
Delete3DwidgetController
Get3DSingleWidgetController
);
V1Widget3d.patch("/widget3d/delete", tokenValidator, Delete3DwidgetController);
export default V1Widget3d;

View File

@@ -50,6 +50,13 @@ interface I3dWidgetGet {
zoneUuid: string;
userId: string;
}
interface I3dSingleWidgetGet {
organization: string;
projectId: string;
versionId: string;
widgetID: string;
userId: string;
}
export const Add3DWidget = async (data: IWidget3DAdd): Promise<IResult> => {
try {
const { organization, widget, userId, zoneUuid, projectId, versionId } =
@@ -365,3 +372,52 @@ export const Get3Dwidget = async (data: I3dWidgetGet): Promise<IResult> => {
}
}
};
export const GetSingle3Dwidget = async (
data: I3dSingleWidgetGet
): Promise<IResult> => {
try {
const { organization, userId, widgetID, versionId, projectId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const VersionGetId = versionId ? versionId : LivingProject.Present_version;
const ExistingVersion = await LivingCurrentVersion(
organization,
LivingProject._id,
VersionGetId
);
if (!ExistingVersion) return { status: "Version Data not found" };
const widgetData = await widget3dModel(organization).findOne({
widgetID: widgetID,
versionId: ExistingVersion._id,
projectId: projectId,
isArchive: false,
});
if (!widgetData) {
return { status: "Widget not found" };
}
const Datastructure = {
measurements: widgetData?.Data?.measurements,
duration: widgetData?.Data?.duration,
};
const widgetName = widgetData.widgetName;
const Data = { Datastructure, widgetName };
return { status: "Success", data: Data };
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};

View File

@@ -332,17 +332,17 @@ export const UpdateWidget = async (data: IWidgetUpdate): Promise<IResult> => {
});
if (!findWidget) return { status: "Data not found" };
const updateData = {
widgetName: values.widgetName,
widgetSide: values.widgetSide,
elementType: values.type,
widgetName: values?.widgetName,
widgetSide: values?.widgetSide,
elementType: values?.type,
Data: {
measurement: values.Data.measurement,
duration: values.Data.duration,
measurement: values.Data?.measurement,
duration: values.Data?.duration,
},
elementColor: values.color,
fontFamily: values.fontFamily,
fontStyle: values.fontStyle,
fontWeight: values.fontWeight,
elementColor: values?.color,
fontFamily: values?.fontFamily,
fontStyle: values?.fontStyle,
fontWeight: values?.fontWeight,
isArchive: false,
};