54 lines
1.9 KiB
TypeScript
54 lines
1.9 KiB
TypeScript
import { Socket, Server } from "socket.io";
|
|
import { EVENTS } from "../../socket/events.ts";
|
|
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
|
import { SetCamera } from "../../../shared/services/builder/cameraService.ts";
|
|
import { ErrorResponse, FinalResponse, validateFields } from "../../utils/socketfunctionHelpers.ts";
|
|
export const SetCameraHandleEvent = async (
|
|
event: string,
|
|
socket: Socket,
|
|
io: Server,
|
|
data: any,
|
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
|
) => {
|
|
if (event !== EVENTS.setCamera_v1 || !data?.organization) return;
|
|
const requiredFields = [
|
|
"position",
|
|
"target",
|
|
"rotation",
|
|
"projectId",
|
|
"userId",
|
|
"organization",
|
|
];
|
|
const missingFields = validateFields(data, requiredFields);
|
|
|
|
if (missingFields.length > 0) {
|
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.camera_v1CreateResponse,
|
|
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
|
return;
|
|
}
|
|
const result = await SetCamera(data);
|
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
|
|
|
const messages: Record<string, { message: string }> = {
|
|
Success: { message: "Camera created successfully" },
|
|
"User not found": { message: "User not found" },
|
|
"Project not found": { message: "Project not found" },
|
|
"Update Success": { message: "Update Success" },
|
|
|
|
|
|
};
|
|
|
|
const msg = messages[status] || { message: "Internal server error" };
|
|
const Camera_Datas =
|
|
status === "Success" && result?.data
|
|
|
|
? {
|
|
|
|
}
|
|
: undefined;
|
|
|
|
const response = FinalResponse(status, socket, data.organization, messages, Camera_Datas);
|
|
|
|
|
|
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.camera_v1CreateResponse, response, connectedUsersByOrg)
|
|
} |