project create socket

This commit is contained in:
2025-05-14 12:41:27 +05:30
parent 2997967899
commit af8510ad90
3 changed files with 56 additions and 1 deletions

View File

@@ -0,0 +1,51 @@
import { Socket } from "socket.io";
import { createProject } from "../../../shared/services/project/project-Serivices.ts";
import { EVENTS } from "../../socket/events.ts";
import { emitEventResponse } from "../../socket/socketManager.ts";
export const projectHandleEvent = async (
event: string,
socket: Socket,
data: any,
namespace: any
) => {
if (!data?.organization) {
console.warn(`Missing organization in event: ${event}`);
return;
}
let result;
switch (event) {
case EVENTS.addProject: {
result = await createProject(data);
// Create response object
const response = {
success: result.status === "success",
message:
result.status === "project_exists"
? "Project already exists"
: result.status === "user_not_found"
? "User not found"
: result.status === "invalid_user_id"
? "Invalid User ID"
: result.status === "success"
? "Project created successfully"
: "Something went wrong",
data: result.project || null,
status: result.status,
socketId: socket.id,
organization: data.organization,
};
// Emit response to the organization room
emitEventResponse(socket, data.organization, EVENTS.projectResponse, response);
break;
}
default:
console.warn(`Unknown project event: ${event}`);
}
};

View File

@@ -98,4 +98,8 @@ export const EVENTS = {
update3dPositionResponse:"viz-widget3D:response:modifyPositionRotation",
delete3DWidget:"v2:viz-3D-widget:delete",
widget3DDeleteResponse:"viz-widget3D:response:delete",
//PROJECT
addProject:"v1:project:add",
projectResponse:"v1-project:response:update:",
}

View File

@@ -1050,7 +1050,7 @@ try {
}
}
const emitEventResponse = (socket: Socket, organization: string, event: string, result: any) => {
export const emitEventResponse = (socket: Socket, organization: string, event: string, result: any) => {
if (organization) {
socket.to(organization).emit(event, {
success: result.success,