Controller and routing for the Vizualtion and builder
This commit is contained in:
@@ -1,61 +1,51 @@
|
||||
import { Request, Response } from "express";
|
||||
|
||||
import { Response } from "express";
|
||||
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||
import {
|
||||
GetCamers,
|
||||
SetCamera,
|
||||
} from "../../../../shared/services/builder/cameraService.ts";
|
||||
DelZone,
|
||||
GetZones,
|
||||
SetZone,
|
||||
SingleZonePanelData,
|
||||
VizZoneDatas,
|
||||
ZoneData,
|
||||
} from "../../../../shared/services/builder/zoneService.ts";
|
||||
|
||||
export const SetNewCamera = async (
|
||||
export const CreateZoneController = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, role, userId } = req.user || {};
|
||||
const { position, target, rotation, projectId, versionId } = req.body;
|
||||
if (
|
||||
!organization ||
|
||||
!role ||
|
||||
!userId ||
|
||||
!position ||
|
||||
!target ||
|
||||
!rotation ||
|
||||
!projectId ||
|
||||
!versionId
|
||||
) {
|
||||
const { organization, userId } = req.user || {};
|
||||
const { zoneData, projectId } = req.body;
|
||||
if (!organization || !userId || !zoneData || !projectId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
position,
|
||||
target,
|
||||
rotation,
|
||||
zoneData,
|
||||
projectId,
|
||||
versionId,
|
||||
organization,
|
||||
role,
|
||||
userId,
|
||||
};
|
||||
const result = await SetCamera(data);
|
||||
const result = await SetZone(data);
|
||||
|
||||
switch (result.status) {
|
||||
case "Project not found":
|
||||
res.status(404).json({
|
||||
message: "Project not found",
|
||||
TrashDatas: [],
|
||||
case "User not found":
|
||||
res.status(200).json({
|
||||
message: "User not found",
|
||||
});
|
||||
break;
|
||||
|
||||
case "Update Success":
|
||||
case "zone updated":
|
||||
res.status(200).json({
|
||||
TrashDatas: result.data,
|
||||
message: "zone updated",
|
||||
ZoneData: result.data,
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
TrashDatas: result.data,
|
||||
message: "zone created",
|
||||
ZoneData: result.data,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
@@ -71,29 +61,35 @@ export const SetNewCamera = async (
|
||||
});
|
||||
}
|
||||
};
|
||||
export const CameraList = async (
|
||||
export const DeleteZoneController = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, role, userId } = req.user || {};
|
||||
if (!organization || !role || !userId) {
|
||||
const { organization, userId } = req.user || {};
|
||||
const { zoneId, projectId } = req.body;
|
||||
if (!organization || !userId || !zoneId || !projectId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await GetCamers({
|
||||
const result = await DelZone({
|
||||
organization,
|
||||
role,
|
||||
zoneId,
|
||||
projectId,
|
||||
userId,
|
||||
});
|
||||
|
||||
switch (result.status) {
|
||||
case "Project not found":
|
||||
case "User not found":
|
||||
res.status(404).json({
|
||||
message: "Project not found",
|
||||
TrashDatas: [],
|
||||
message: "User not found",
|
||||
});
|
||||
break;
|
||||
case "Invalid zone ID":
|
||||
res.status(404).json({
|
||||
message: "Zone not found for the UUID",
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
@@ -113,3 +109,186 @@ export const CameraList = async (
|
||||
});
|
||||
}
|
||||
};
|
||||
export const GetZoneController = 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 GetZones({
|
||||
organization,
|
||||
projectId,
|
||||
userId,
|
||||
});
|
||||
|
||||
switch (result.status) {
|
||||
case "User not found":
|
||||
res.status(404).json({
|
||||
message: "User 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 } = req.params;
|
||||
if (!organization || !userId || !projectId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await VizZoneDatas({
|
||||
organization,
|
||||
projectId,
|
||||
userId,
|
||||
});
|
||||
|
||||
switch (result.status) {
|
||||
case "User not found":
|
||||
res.status(404).json({
|
||||
message: "User 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",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const ZoneDataController = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, userId } = req.user || {};
|
||||
const { projectId, zoneId } = req.params;
|
||||
if (!organization || !userId || !projectId || !zoneId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await ZoneData({
|
||||
organization,
|
||||
projectId,
|
||||
userId,
|
||||
zoneId,
|
||||
});
|
||||
|
||||
switch (result.status) {
|
||||
case "User not found":
|
||||
res.status(404).json({
|
||||
message: "User 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 { projectId, zoneId } = req.params;
|
||||
if (!organization || !userId || !projectId || !zoneId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await SingleZonePanelData({
|
||||
organization,
|
||||
projectId,
|
||||
userId,
|
||||
zoneId,
|
||||
});
|
||||
|
||||
switch (result.status) {
|
||||
case "User not found":
|
||||
res.status(404).json({
|
||||
message: "User 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",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user