project create socket
This commit is contained in:
51
src/socket-server/controllers/project/projectController.ts
Normal file
51
src/socket-server/controllers/project/projectController.ts
Normal 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}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -98,4 +98,8 @@ export const EVENTS = {
|
|||||||
update3dPositionResponse:"viz-widget3D:response:modifyPositionRotation",
|
update3dPositionResponse:"viz-widget3D:response:modifyPositionRotation",
|
||||||
delete3DWidget:"v2:viz-3D-widget:delete",
|
delete3DWidget:"v2:viz-3D-widget:delete",
|
||||||
widget3DDeleteResponse:"viz-widget3D:response:delete",
|
widget3DDeleteResponse:"viz-widget3D:response:delete",
|
||||||
|
|
||||||
|
//PROJECT
|
||||||
|
addProject:"v1:project:add",
|
||||||
|
projectResponse:"v1-project:response:update:",
|
||||||
}
|
}
|
||||||
@@ -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) {
|
if (organization) {
|
||||||
socket.to(organization).emit(event, {
|
socket.to(organization).emit(event, {
|
||||||
success: result.success,
|
success: result.success,
|
||||||
|
|||||||
Reference in New Issue
Block a user