358 lines
8.4 KiB
TypeScript
358 lines
8.4 KiB
TypeScript
import { Response } from "express";
|
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
|
import {
|
|
DelZone,
|
|
GetZones,
|
|
SetZone,
|
|
SingleZonePanelData,
|
|
VizZoneDatas,
|
|
ZoneData,
|
|
} from "../../../../shared/services/builder/zoneService.ts";
|
|
|
|
export const CreateZoneController = async (
|
|
req: AuthenticatedRequest,
|
|
res: Response
|
|
): Promise<void> => {
|
|
try {
|
|
const { organization, userId } = req.user || {};
|
|
const { zoneData, projectId, versionId } = req.body;
|
|
if (!organization || !userId || !zoneData || !projectId || !versionId) {
|
|
res.status(400).json({
|
|
message: "All fields are required",
|
|
});
|
|
return;
|
|
}
|
|
const data = {
|
|
zoneData,
|
|
projectId,
|
|
versionId,
|
|
organization,
|
|
userId,
|
|
};
|
|
const result = await SetZone(data);
|
|
|
|
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 "zone updated":
|
|
res.status(200).json({
|
|
message: "zone updated",
|
|
ZoneData: result.data,
|
|
});
|
|
break;
|
|
case "Success":
|
|
res.status(200).json({
|
|
message: "zone created",
|
|
ZoneData: result.data,
|
|
});
|
|
break;
|
|
default:
|
|
res.status(500).json({
|
|
message: "Internal server error",
|
|
});
|
|
break;
|
|
}
|
|
} catch (error) {
|
|
res.status(500).json({
|
|
message: "Unknown error",
|
|
});
|
|
}
|
|
};
|
|
export const DeleteZoneController = async (
|
|
req: AuthenticatedRequest,
|
|
res: Response
|
|
): Promise<void> => {
|
|
try {
|
|
const { organization, userId } = req.user || {};
|
|
const { zoneUuid, projectId, versionId } = req.body;
|
|
if (!organization || !userId || !zoneUuid || !projectId || !versionId) {
|
|
res.status(400).json({
|
|
message: "All fields are required",
|
|
});
|
|
return;
|
|
}
|
|
const result = await DelZone({
|
|
organization,
|
|
zoneUuid,
|
|
projectId,
|
|
versionId,
|
|
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 "Version Data not found":
|
|
res.status(404).json({
|
|
message: "Version Data not found",
|
|
});
|
|
break;
|
|
case "Invalid zone ID":
|
|
res.status(404).json({
|
|
message: "Zone not found for the UUID",
|
|
});
|
|
break;
|
|
case "Success":
|
|
res.status(200).json({
|
|
message: "Zone deleted successfully",
|
|
});
|
|
break;
|
|
default:
|
|
res.status(500).json({
|
|
message: "Internal server error",
|
|
});
|
|
break;
|
|
}
|
|
} catch (error) {
|
|
res.status(500).json({
|
|
message: "Unknown error",
|
|
});
|
|
}
|
|
};
|
|
export const GetZoneController = async (
|
|
req: AuthenticatedRequest,
|
|
res: Response
|
|
): Promise<void> => {
|
|
try {
|
|
const { organization, userId } = req.user || {};
|
|
const { projectId, versionId } = req.params;
|
|
if (!organization || !userId || !projectId) {
|
|
res.status(400).json({
|
|
message: "All fields are required",
|
|
});
|
|
return;
|
|
}
|
|
const result = await GetZones({
|
|
organization,
|
|
projectId,
|
|
userId,
|
|
versionId,
|
|
});
|
|
|
|
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 "Invalid zone":
|
|
res.status(404).json({
|
|
message: "Zone not found for the UUID",
|
|
});
|
|
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 VizZoneController = async (
|
|
req: AuthenticatedRequest,
|
|
res: Response
|
|
): Promise<void> => {
|
|
try {
|
|
const { organization, userId } = req.user || {};
|
|
const { projectId, versionId } = req.params;
|
|
if (!organization || !userId || !projectId) {
|
|
res.status(400).json({
|
|
message: "All fields are required",
|
|
});
|
|
return;
|
|
}
|
|
const result = await VizZoneDatas({
|
|
organization,
|
|
projectId,
|
|
versionId,
|
|
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 "Version Data not found":
|
|
res.status(404).json({
|
|
message: "Version Data not found",
|
|
});
|
|
break;
|
|
case "Zone not found for the UUID":
|
|
res.status(200).json(result.data);
|
|
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 ZoneDataController = async (
|
|
req: AuthenticatedRequest,
|
|
res: Response
|
|
): Promise<void> => {
|
|
try {
|
|
const { organization, userId } = req.user || {};
|
|
const { projectId, zoneUuid, versionId } = req.params;
|
|
if (!organization || !userId || !projectId || !zoneUuid) {
|
|
res.status(400).json({
|
|
message: "All fields are required",
|
|
});
|
|
return;
|
|
}
|
|
const result = await ZoneData({
|
|
organization,
|
|
projectId,
|
|
userId,
|
|
versionId,
|
|
zoneUuid,
|
|
});
|
|
|
|
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 "Zone not found":
|
|
res.status(404).json({
|
|
message: "Zone 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 SingleZonePanelController = async (
|
|
req: AuthenticatedRequest,
|
|
res: Response
|
|
): Promise<void> => {
|
|
try {
|
|
const { organization, userId } = req.user || {};
|
|
const { versionId, projectId, zoneUuid } = req.params;
|
|
if (!organization || !userId || !projectId || !zoneUuid) {
|
|
res.status(400).json({
|
|
message: "All fields are required",
|
|
});
|
|
return;
|
|
}
|
|
const result = await SingleZonePanelData({
|
|
organization,
|
|
projectId,
|
|
userId,
|
|
versionId,
|
|
zoneUuid,
|
|
});
|
|
|
|
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 "Zone not found for the UUID":
|
|
res.status(404).json({
|
|
message: "Zone not found for the UUID",
|
|
});
|
|
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",
|
|
});
|
|
}
|
|
};
|