Search Api, socket comments erased
This commit is contained in:
5
.env
5
.env
@@ -3,6 +3,11 @@ MONGO_URI=mongodb://mongo/
|
|||||||
MONGO_USER=admin
|
MONGO_USER=admin
|
||||||
MONGO_PASSWORD=admin321
|
MONGO_PASSWORD=admin321
|
||||||
MONGO_AUTH_DB=admin
|
MONGO_AUTH_DB=admin
|
||||||
|
# MONGO_URI=mongodb://192.168.0.110/
|
||||||
|
# MONGO_USER=mydata
|
||||||
|
# MONGO_PASSWORD=mongodb@hexr2002
|
||||||
|
# MONGO_AUTH_DB=admin
|
||||||
|
|
||||||
|
|
||||||
API_PORT=5000
|
API_PORT=5000
|
||||||
SOCKET_PORT=8000
|
SOCKET_PORT=8000
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ export const DeleteZoneController = async (
|
|||||||
break;
|
break;
|
||||||
case "Success":
|
case "Success":
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
TrashDatas: result.data,
|
message:"Zone deleted successfully"
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -15,12 +15,12 @@ v1homeRoutes.get(
|
|||||||
recentDataController
|
recentDataController
|
||||||
);
|
);
|
||||||
v1homeRoutes.get(
|
v1homeRoutes.get(
|
||||||
"/searchProjects",
|
"/search/searchProjects",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
searchProjectController
|
searchProjectController
|
||||||
);
|
);
|
||||||
v1homeRoutes.get(
|
v1homeRoutes.get(
|
||||||
"/searchTrashProjects",
|
"/search/searchTrashProjects",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
searchTrashProjectController
|
searchTrashProjectController
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -119,12 +119,12 @@ export const DelZone = async (data: IZone): Promise<IResult> => {
|
|||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
if (findZoneId) {
|
if (findZoneId) {
|
||||||
const deleteZone = await zoneModel(organization)
|
const deleteZone = await zoneModel(organization)
|
||||||
.findOneAndDelete({
|
.findOneAndUpdate({
|
||||||
zoneId: zoneId,
|
zoneId: zoneId,
|
||||||
createdBy: userId,
|
createdBy: userId,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
})
|
},{isArchive:true},{new:true})
|
||||||
.select("-_id -__v");
|
.select("-_id -__v");
|
||||||
if (deleteZone) {
|
if (deleteZone) {
|
||||||
const panels = await panelModel(organization).find({
|
const panels = await panelModel(organization).find({
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import express,{ Response, Request } from "express";
|
import express, { Response, Request } from "express";
|
||||||
import http from "http";
|
import http from "http";
|
||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
import { SocketServer } from "./manager/manager.ts";
|
import { SocketServer } from "./manager/manager.ts";
|
||||||
|
import { initSocketServer } from "./socket/socketManager.ts";
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = process.env.SOCKET_PORT;
|
const PORT = process.env.SOCKET_PORT;
|
||||||
const server = http.createServer(app);
|
const server = http.createServer(app);
|
||||||
@@ -12,7 +13,11 @@ const server = http.createServer(app);
|
|||||||
app.get("/", (req: Request, res: Response) => {
|
app.get("/", (req: Request, res: Response) => {
|
||||||
res.send("Hello, I am Major-Dwinzo RealTime!");
|
res.send("Hello, I am Major-Dwinzo RealTime!");
|
||||||
});
|
});
|
||||||
SocketServer(server)
|
initSocketServer(server);
|
||||||
|
|
||||||
|
|
||||||
|
SocketServer(server);
|
||||||
|
|
||||||
server.listen(PORT, () => {
|
server.listen(PORT, () => {
|
||||||
console.log(`socket-Server is running on http://localhost:${PORT}`);
|
console.log(`socket-Server is running on http://localhost:${PORT}`);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ import { AddPanelHandleEvent, ClearPanelHandleEvent, DeletePanelHandleEvent, Loc
|
|||||||
import { AddTemplateHandleEvent, addTemplateZoneHandleEvent, TemplateDeleteHandleEvent } from '../controllers/vizualizationController/template-Controller.ts';
|
import { AddTemplateHandleEvent, addTemplateZoneHandleEvent, TemplateDeleteHandleEvent } from '../controllers/vizualizationController/template-Controller.ts';
|
||||||
import { AddWidgetHandleEvent, WidgetDeleteHandleEvent } from '../controllers/vizualizationController/widget-Controller.ts';
|
import { AddWidgetHandleEvent, WidgetDeleteHandleEvent } from '../controllers/vizualizationController/widget-Controller.ts';
|
||||||
import { getUserRole } from '../utils/getUsers.ts';
|
import { getUserRole } from '../utils/getUsers.ts';
|
||||||
|
import { initSocketServer } from "../socket/socketManager.ts";
|
||||||
|
|
||||||
interface UserSocketInfo {
|
interface UserSocketInfo {
|
||||||
socketId: string;
|
socketId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ const lineHandleEvent = async (
|
|||||||
data: any,
|
data: any,
|
||||||
io: any
|
io: any
|
||||||
) => {
|
) => {
|
||||||
if (!data?.organization) {
|
if (!data?.organization|| typeof data.organization !== 'string') {
|
||||||
console.warn(`Missing organization for event: ${event}`);
|
console.warn(`Missing organization for event: ${event}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -992,8 +992,19 @@ export const initSocketServer = (httpServer: any) => {
|
|||||||
namespace: any,
|
namespace: any,
|
||||||
...eventHandlers: Function[]
|
...eventHandlers: Function[]
|
||||||
) => {
|
) => {
|
||||||
namespace.on("connection", (socket: Socket) => {
|
namespace.use((socket: Socket, next: (err?: Error) => void) => {
|
||||||
const { organization, email } = socket.handshake.auth;
|
const token = socket.handshake.auth.token;
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
console.log("No token provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
namespace.on("connection", async (socket: Socket) => {
|
||||||
|
|
||||||
|
const { organization, email, userId } = socket.handshake.auth;
|
||||||
|
|
||||||
if (organization) {
|
if (organization) {
|
||||||
socket.join(organization);
|
socket.join(organization);
|
||||||
@@ -1018,9 +1029,9 @@ export const initSocketServer = (httpServer: any) => {
|
|||||||
if (onlineUsers[organization]?.size === 0)
|
if (onlineUsers[organization]?.size === 0)
|
||||||
delete onlineUsers[organization];
|
delete onlineUsers[organization];
|
||||||
userStatus(EVENTS.disconnect, socket, socket.handshake.auth, socket);
|
userStatus(EVENTS.disconnect, socket, socket.handshake.auth, socket);
|
||||||
connectedUsersByOrg[organization] = connectedUsersByOrg[
|
// connectedUsersByOrg[organization] = connectedUsersByOrg[
|
||||||
organization
|
// organization
|
||||||
].filter((u) => u.socketId !== socket.id);
|
// ].filter((u) => u.socketId !== socket.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("reconnect", (attempt: number) => {
|
socket.on("reconnect", (attempt: number) => {
|
||||||
@@ -1079,5 +1090,7 @@ export const initSocketServer = (httpServer: any) => {
|
|||||||
projectDeleteHandleEvent,
|
projectDeleteHandleEvent,
|
||||||
projecUpdateHandleEvent
|
projecUpdateHandleEvent
|
||||||
);
|
);
|
||||||
|
|
||||||
return io;
|
return io;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,9 +10,7 @@ interface EmitOptions {
|
|||||||
status?: string;
|
status?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Emit a structured socket event response to a specific organization room.
|
|
||||||
*/
|
|
||||||
export const emitEventResponse = (
|
export const emitEventResponse = (
|
||||||
socket: Socket,
|
socket: Socket,
|
||||||
organization: string,
|
organization: string,
|
||||||
@@ -36,15 +34,7 @@ export const emitEventResponse = (
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// interface EmitOptions {
|
|
||||||
// success: boolean;
|
|
||||||
// message: string;
|
|
||||||
// data?: any;
|
|
||||||
// error?: any;
|
|
||||||
// organization: string;
|
|
||||||
// socketId: string;
|
|
||||||
// status?: string;
|
|
||||||
// }
|
|
||||||
|
|
||||||
export const emitToSenderAndAdmins = (
|
export const emitToSenderAndAdmins = (
|
||||||
io: Server,
|
io: Server,
|
||||||
@@ -68,20 +58,5 @@ export const emitToSenderAndAdmins = (
|
|||||||
socketId: result.socketId,
|
socketId: result.socketId,
|
||||||
organization,
|
organization,
|
||||||
});
|
});
|
||||||
// Emit to all admin sockets in organization except sender
|
|
||||||
// const admins = connectedUsersByOrg[organization]?.filter(
|
|
||||||
// user => user.role === 'Admin' && user.socketId !== socket.id
|
|
||||||
// ) || [];
|
|
||||||
// console.log('admins: ', admins);
|
|
||||||
|
|
||||||
|
|
||||||
// admins.forEach(adminUser => {
|
|
||||||
// io.to(adminUser.socketId).emit(event, {
|
|
||||||
// message: result.message,
|
|
||||||
// data: result.data,
|
|
||||||
// error: result.error,
|
|
||||||
// socketId: result.socketId,
|
|
||||||
// organization,
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user