float and zone Api updated

This commit is contained in:
2025-06-24 16:35:13 +05:30
parent 51c45a6a68
commit 99d68cb300
4 changed files with 51 additions and 15 deletions

View File

@@ -254,7 +254,7 @@ export const GetFloatController = async (
): Promise<void> => {
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<void> => {
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",

View File

@@ -21,7 +21,7 @@ V1Zone.get(
);
V1Zone.get(
"/zones/:projectId/:zoneUuid/:versionId",
"/zone/:projectId/:zoneUuid/:versionId",
tokenValidator,
ZoneDataController
);

View File

@@ -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
);

View File

@@ -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<IResult> => {
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<IResult> => {
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" };
}