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