diff --git a/src/api-server/V1/v1Controllers/vizualizationController/v1floatWidgetController.ts b/src/api-server/V1/v1Controllers/vizualizationController/v1floatWidgetController.ts index f259d90..ebb035d 100644 --- a/src/api-server/V1/v1Controllers/vizualizationController/v1floatWidgetController.ts +++ b/src/api-server/V1/v1Controllers/vizualizationController/v1floatWidgetController.ts @@ -254,7 +254,7 @@ export const GetFloatController = async ( ): Promise => { try { const { userId, organization } = req.user || {}; - const { projectId, zoneUuid,versionId } = req.params; + const { projectId, zoneUuid, versionId } = req.params; if (!userId || !organization || !projectId || !zoneUuid) { res.status(400).json({ message: "All fields are required", @@ -262,7 +262,8 @@ export const GetFloatController = async ( return; } const result = await GetFloatWidget({ - organization,versionId, + organization, + versionId, zoneUuid, projectId, userId, @@ -313,8 +314,14 @@ export const SingleFloatController = async ( ): Promise => { try { const { userId, organization } = req.user || {}; - const { floatWidgetID } = req.params; - if (!userId || !organization || !floatWidgetID) { + const { projectId, versionId, floatWidgetID } = req.params; + if ( + !userId || + !organization || + !floatWidgetID || + !projectId || + !versionId + ) { res.status(400).json({ message: "All fields are required", }); @@ -324,6 +331,8 @@ export const SingleFloatController = async ( organization, floatWidgetID, userId, + projectId, + versionId, }); switch (result.status) { case "User not found": @@ -331,6 +340,16 @@ export const SingleFloatController = async ( 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(404).json({ message: "Widget not found", diff --git a/src/api-server/V1/v1Routes/BuilderRoutes/v1-ZoneRoutes.ts b/src/api-server/V1/v1Routes/BuilderRoutes/v1-ZoneRoutes.ts index d38dbb3..515e6b5 100644 --- a/src/api-server/V1/v1Routes/BuilderRoutes/v1-ZoneRoutes.ts +++ b/src/api-server/V1/v1Routes/BuilderRoutes/v1-ZoneRoutes.ts @@ -21,7 +21,7 @@ V1Zone.get( ); V1Zone.get( - "/zones/:projectId/:zoneUuid/:versionId", + "/zone/:projectId/:zoneUuid/:versionId", tokenValidator, ZoneDataController ); diff --git a/src/api-server/V1/v1Routes/vizRoutes.ts/v1-FloatWidgetRoutes.ts b/src/api-server/V1/v1Routes/vizRoutes.ts/v1-FloatWidgetRoutes.ts index 4e722f1..d2f5612 100644 --- a/src/api-server/V1/v1Routes/vizRoutes.ts/v1-FloatWidgetRoutes.ts +++ b/src/api-server/V1/v1Routes/vizRoutes.ts/v1-FloatWidgetRoutes.ts @@ -10,11 +10,7 @@ import { const V1FloatWidget = express.Router(); -V1FloatWidget.post( - "/floatWidget/save", - tokenValidator, - FloatAddController -); +V1FloatWidget.post("/floatWidget/save", tokenValidator, FloatAddController); V1FloatWidget.patch( "/floatWidget/delete", tokenValidator, @@ -26,7 +22,7 @@ V1FloatWidget.get( GetFloatController ); V1FloatWidget.get( - "/floatWidget/:floatWidgetId", + "/floatWidget/:projectId/:versionId/:floatWidgetID", tokenValidator, SingleFloatController ); diff --git a/src/shared/services/visualization/floatWidgetService.ts b/src/shared/services/visualization/floatWidgetService.ts index 8015dce..325615b 100644 --- a/src/shared/services/visualization/floatWidgetService.ts +++ b/src/shared/services/visualization/floatWidgetService.ts @@ -46,6 +46,8 @@ interface ISingleFloat { userId: string; organization: string; floatWidgetID: string; + projectId: string; + versionId: string; } interface IGetZoneFloat { userId: string; @@ -407,7 +409,7 @@ export const DuplicateFloat = async ( export const GetFloatWidget = async (data: IGetZoneFloat): Promise => { try { - const { organization, zoneUuid, projectId, userId,versionId } = data; + const { organization, zoneUuid, projectId, userId, versionId } = data; const UserExists = await existingUser(userId, organization); if (!UserExists) { return { status: "User not found" }; @@ -478,16 +480,35 @@ export const SingleFloatWidget = async ( data: ISingleFloat ): Promise => { try { - const { organization, floatWidgetID, userId } = data; + const { organization, floatWidgetID, userId, projectId, versionId } = data; const UserExists = await existingUser(userId, organization); - if (!UserExists) return { status: "User not found" }; + 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 floatWidgetModel(organization) .findOne({ floatWidgetID: floatWidgetID, + projectId: projectId, + versionId: versionId, isArchive: false, }) - .select("-_id -zoneUuid -createdAt -updatedAt -__v"); + .select("-_id -zoneUuid -createdAt -updatedAt -__v -isArchive"); if (!widgetData || widgetData.length === 0) { return { status: "Widget not found" }; }