socket Manager duplication of zone controller
This commit is contained in:
1
.env
1
.env
@@ -23,6 +23,5 @@ REFRESH_JWT_SECRET="RefreshDwinzoProject"
|
||||
|
||||
|
||||
REDIS_ENV= true
|
||||
|
||||
REDIS_DOCKER =185.100.212.76
|
||||
REDIS_PORT=6666
|
||||
@@ -11,16 +11,8 @@ import {
|
||||
|
||||
const v1Zone = express.Router();
|
||||
|
||||
v1Zone.post(
|
||||
"/zones",
|
||||
tokenValidator,
|
||||
CreateZoneController
|
||||
);
|
||||
v1Zone.patch(
|
||||
"/zones/delete",
|
||||
tokenValidator,
|
||||
DeleteZoneController
|
||||
);
|
||||
v1Zone.post("/zones", tokenValidator, CreateZoneController);
|
||||
v1Zone.patch("/zones/delete", tokenValidator, DeleteZoneController);
|
||||
|
||||
v1Zone.get(
|
||||
"/zones/visualization/:projectId",
|
||||
@@ -28,19 +20,11 @@ v1Zone.get(
|
||||
VizZoneController
|
||||
);
|
||||
|
||||
v1Zone.get(
|
||||
"/zones/:projectId/:zoneId",
|
||||
tokenValidator,
|
||||
ZoneDataController
|
||||
);
|
||||
v1Zone.get("/zones/:projectId/:zoneId", tokenValidator, ZoneDataController);
|
||||
v1Zone.get(
|
||||
"/zones/panel/:projectId/:zoneId",
|
||||
tokenValidator,
|
||||
SingleZonePanelController
|
||||
);
|
||||
v1Zone.get(
|
||||
"/zones/:projectId",
|
||||
tokenValidator,
|
||||
GetZoneController
|
||||
);
|
||||
v1Zone.get("/zones/:projectId", tokenValidator, GetZoneController);
|
||||
export default v1Zone;
|
||||
|
||||
@@ -278,7 +278,7 @@ export class ZoneService {
|
||||
const { organization } = req.params;
|
||||
|
||||
const findZoneId = await zoneSchema(organization)
|
||||
.find()
|
||||
.find({ isArchive: false })
|
||||
.select(
|
||||
"zoneId zoneName layer points viewPortCenter viewPortposition -_id"
|
||||
);
|
||||
@@ -286,7 +286,7 @@ export class ZoneService {
|
||||
if (!findZoneId) {
|
||||
res.status(500).json({ message: "Invalid zone" });
|
||||
}
|
||||
res.status(201).json({ data: findZoneId, organization: organization });
|
||||
res.status(200).json({ data: findZoneId, organization: organization });
|
||||
} catch (error) {
|
||||
console.log("error: ", error);
|
||||
res.status(500).json({ message: "Zone not found", error });
|
||||
|
||||
@@ -6,7 +6,7 @@ import templateModel from "../../../shared/model/vizualization/templatemodel.ts"
|
||||
import widgetModel from "../../../shared/model/vizualization/widgemodel.ts";
|
||||
export const setZone = async (data: any) => {
|
||||
const { organization, userId, zoneData } = data;
|
||||
console.log('data:zone ', data);
|
||||
console.log("data service: ", data);
|
||||
try {
|
||||
const zoneId = zoneData.zoneId;
|
||||
const points = zoneData.points;
|
||||
@@ -16,6 +16,7 @@ export const setZone = async (data: any) => {
|
||||
const viewPortposition = zoneData.viewPortposition;
|
||||
const findZoneId = await zoneModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (findZoneId) {
|
||||
const updateZone = await zoneModel(organization)
|
||||
|
||||
@@ -254,7 +254,7 @@ const lineHandleEvent = async (
|
||||
data: any,
|
||||
io: any
|
||||
) => {
|
||||
if (!data?.organization|| typeof data.organization !== 'string') {
|
||||
if (!data?.organization || typeof data.organization !== "string") {
|
||||
console.warn(`Missing organization for event: ${event}`);
|
||||
return;
|
||||
}
|
||||
@@ -423,6 +423,7 @@ const zoneHandleEvent = async (
|
||||
let result;
|
||||
switch (event) {
|
||||
case EVENTS.setZone: {
|
||||
// console.log("create zonedata: ", data);
|
||||
result = await setZone(data);
|
||||
|
||||
if (result) {
|
||||
@@ -966,14 +967,12 @@ const emitEventResponse = (
|
||||
interface UserSocketInfo {
|
||||
socketId: string;
|
||||
userId: string;
|
||||
role: string;
|
||||
role: string;
|
||||
}
|
||||
|
||||
const connectedUsersByOrg: { [organization: string]: UserSocketInfo[] } = {};
|
||||
|
||||
export const initSocketServer = (io: Server) => {
|
||||
|
||||
|
||||
const namespaces = {
|
||||
Builder: io.of("/Builder"),
|
||||
visualization: io.of("/Visualization"),
|
||||
@@ -987,18 +986,19 @@ export const initSocketServer = (io: Server) => {
|
||||
namespace: any,
|
||||
...eventHandlers: Function[]
|
||||
) => {
|
||||
namespace.use((socket: Socket, next: (err?: Error) => void) => {
|
||||
const token = socket.handshake.auth.token;
|
||||
if (namespace._handlersRegistered) return;
|
||||
namespace._handlersRegistered = true;
|
||||
namespace.use((socket: Socket, next: (err?: Error) => void) => {
|
||||
const token = socket.handshake.auth.token;
|
||||
|
||||
if (!token) {
|
||||
console.log("No token provided");
|
||||
}
|
||||
if (!token) {
|
||||
console.log("No token provided");
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
next();
|
||||
});
|
||||
|
||||
namespace.on("connection", async (socket: Socket) => {
|
||||
|
||||
const { organization, email, userId } = socket.handshake.auth;
|
||||
|
||||
if (organization) {
|
||||
@@ -1014,7 +1014,7 @@ namespace.use((socket: Socket, next: (err?: Error) => void) => {
|
||||
userStatus(EVENTS.connection, socket, socket.handshake.auth, socket);
|
||||
|
||||
socket.onAny((event: string, data: any, callback: any) => {
|
||||
console.log('data: socketmanager', data);
|
||||
// console.log("data: socketmanager", data);
|
||||
eventHandlers.forEach((handler) =>
|
||||
handler(event, socket, data, namespace, io, callback)
|
||||
);
|
||||
@@ -1088,5 +1088,4 @@ namespace.use((socket: Socket, next: (err?: Error) => void) => {
|
||||
);
|
||||
|
||||
return io;
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user