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_PASSWORD=admin321
|
||||
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
|
||||
SOCKET_PORT=8000
|
||||
|
||||
@@ -104,7 +104,7 @@ export const DeleteZoneController = async (
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
TrashDatas: result.data,
|
||||
message:"Zone deleted successfully"
|
||||
});
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -15,12 +15,12 @@ v1homeRoutes.get(
|
||||
recentDataController
|
||||
);
|
||||
v1homeRoutes.get(
|
||||
"/searchProjects",
|
||||
"/search/searchProjects",
|
||||
tokenValidator,
|
||||
searchProjectController
|
||||
);
|
||||
v1homeRoutes.get(
|
||||
"/searchTrashProjects",
|
||||
"/search/searchTrashProjects",
|
||||
tokenValidator,
|
||||
searchTrashProjectController
|
||||
);
|
||||
|
||||
@@ -119,12 +119,12 @@ export const DelZone = async (data: IZone): Promise<IResult> => {
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
if (findZoneId) {
|
||||
const deleteZone = await zoneModel(organization)
|
||||
.findOneAndDelete({
|
||||
.findOneAndUpdate({
|
||||
zoneId: zoneId,
|
||||
createdBy: userId,
|
||||
projectId: projectId,
|
||||
isArchive: false,
|
||||
})
|
||||
},{isArchive:true},{new:true})
|
||||
.select("-_id -__v");
|
||||
if (deleteZone) {
|
||||
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 dotenv from "dotenv";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
import { SocketServer } from "./manager/manager.ts";
|
||||
import { initSocketServer } from "./socket/socketManager.ts";
|
||||
const app = express();
|
||||
const PORT = process.env.SOCKET_PORT;
|
||||
const server = http.createServer(app);
|
||||
@@ -12,7 +13,11 @@ const server = http.createServer(app);
|
||||
app.get("/", (req: Request, res: Response) => {
|
||||
res.send("Hello, I am Major-Dwinzo RealTime!");
|
||||
});
|
||||
SocketServer(server)
|
||||
initSocketServer(server);
|
||||
|
||||
|
||||
SocketServer(server);
|
||||
|
||||
server.listen(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 { AddWidgetHandleEvent, WidgetDeleteHandleEvent } from '../controllers/vizualizationController/widget-Controller.ts';
|
||||
import { getUserRole } from '../utils/getUsers.ts';
|
||||
import { initSocketServer } from "../socket/socketManager.ts";
|
||||
|
||||
interface UserSocketInfo {
|
||||
socketId: string;
|
||||
userId: string;
|
||||
|
||||
@@ -254,7 +254,7 @@ const lineHandleEvent = async (
|
||||
data: any,
|
||||
io: any
|
||||
) => {
|
||||
if (!data?.organization) {
|
||||
if (!data?.organization|| typeof data.organization !== 'string') {
|
||||
console.warn(`Missing organization for event: ${event}`);
|
||||
return;
|
||||
}
|
||||
@@ -992,8 +992,19 @@ export const initSocketServer = (httpServer: any) => {
|
||||
namespace: any,
|
||||
...eventHandlers: Function[]
|
||||
) => {
|
||||
namespace.on("connection", (socket: Socket) => {
|
||||
const { organization, email } = socket.handshake.auth;
|
||||
namespace.use((socket: Socket, next: (err?: Error) => void) => {
|
||||
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) {
|
||||
socket.join(organization);
|
||||
@@ -1018,9 +1029,9 @@ export const initSocketServer = (httpServer: any) => {
|
||||
if (onlineUsers[organization]?.size === 0)
|
||||
delete onlineUsers[organization];
|
||||
userStatus(EVENTS.disconnect, socket, socket.handshake.auth, socket);
|
||||
connectedUsersByOrg[organization] = connectedUsersByOrg[
|
||||
organization
|
||||
].filter((u) => u.socketId !== socket.id);
|
||||
// connectedUsersByOrg[organization] = connectedUsersByOrg[
|
||||
// organization
|
||||
// ].filter((u) => u.socketId !== socket.id);
|
||||
});
|
||||
|
||||
socket.on("reconnect", (attempt: number) => {
|
||||
@@ -1079,5 +1090,7 @@ export const initSocketServer = (httpServer: any) => {
|
||||
projectDeleteHandleEvent,
|
||||
projecUpdateHandleEvent
|
||||
);
|
||||
|
||||
return io;
|
||||
|
||||
};
|
||||
|
||||
@@ -10,9 +10,7 @@ interface EmitOptions {
|
||||
status?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit a structured socket event response to a specific organization room.
|
||||
*/
|
||||
|
||||
export const emitEventResponse = (
|
||||
socket: Socket,
|
||||
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 = (
|
||||
io: Server,
|
||||
@@ -68,20 +58,5 @@ export const emitToSenderAndAdmins = (
|
||||
socketId: result.socketId,
|
||||
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