vizualization updates
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import express from 'express';
|
||||
import { camera } from '../controller/camera/camera-Controlle';
|
||||
import { camera } from '../controller/camera/camera-Services.ts';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import express from 'express';
|
||||
import { environment } from '../controller/environments/environments-controller';
|
||||
import { environment } from '../controller/environments/environments-Services.ts';
|
||||
|
||||
const router = express.Router();
|
||||
router.post('/setEvironments',environment.setEnvironment)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import express from 'express';
|
||||
import { floorItems } from '../controller/assets/flooritem-Controller';
|
||||
import { floorItems } from '../controller/assets/flooritem-Services.ts';
|
||||
|
||||
const router = express.Router();
|
||||
router.post('/setfloorItems',floorItems.setFloorItems)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import express from 'express';
|
||||
import { lines } from '../controller/lines/line-Controller';
|
||||
import { lines } from '../controller/lines/line-Services.ts';
|
||||
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
140
src/api-server/Routes/panelRoutes.ts
Normal file
140
src/api-server/Routes/panelRoutes.ts
Normal file
@@ -0,0 +1,140 @@
|
||||
import * as express from "express";
|
||||
import { panelService } from "../controller/visualization/panelService.ts";
|
||||
const router = express.Router();
|
||||
/**
|
||||
* @swagger
|
||||
* tags:
|
||||
* - name: Panels
|
||||
* description: API operations related to panels
|
||||
*/
|
||||
/**
|
||||
* @swagger
|
||||
* components:
|
||||
* schemas:
|
||||
* Panel:
|
||||
* type: object
|
||||
* properties:
|
||||
* _id:
|
||||
* type: string
|
||||
* example: "60d0fe4f5311236168a109ca"
|
||||
* zoneId:
|
||||
* type: string
|
||||
* example: "67e3d030ed12ffa47b4eade3"
|
||||
* panelName:
|
||||
* type: string
|
||||
* example: "New Panel"
|
||||
* widgets:
|
||||
* type: array
|
||||
* items:
|
||||
* type: string
|
||||
* example: []
|
||||
* isArchive:
|
||||
* type: boolean
|
||||
* example: false
|
||||
* required:
|
||||
* - zoneId
|
||||
* - panelName
|
||||
* - widgets
|
||||
* - isArchive
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /panel/save:
|
||||
* post:
|
||||
* summary: Create new panels for a given zone
|
||||
* tags: [Panels]
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* organization:
|
||||
* type: string
|
||||
* example: "NEWORG"
|
||||
* zoneId:
|
||||
* type: string
|
||||
* example: "67e3d030ed12ffa47b4eade3"
|
||||
* panelOrder:
|
||||
* type: array
|
||||
* items:
|
||||
* type: string
|
||||
* example: ["up", "right", "left", "down"]
|
||||
* responses:
|
||||
* 201:
|
||||
* description: Panels created successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* example: "Panels created successfully"
|
||||
* panelID:
|
||||
* type: array
|
||||
* items:
|
||||
* type: string
|
||||
* example: ["60d0fe4f5311236168a109ca", "60d0fe4f5311236168a109cb"]
|
||||
* 200:
|
||||
* description: No new panels were created as they already exist
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* example: "No new panels were created. All panels already exist."
|
||||
* 404:
|
||||
* description: Zone not found
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* example: "Zone not found"
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.post("/panel/save", panelService.AddPanel);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /panel/delete:
|
||||
* patch:
|
||||
* summary: Delete the panel on the Zone
|
||||
* tags: [Panels]
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* organization:
|
||||
* type: string
|
||||
* example: "NEWORG"
|
||||
* zoneId:
|
||||
* type: string
|
||||
* example: "0114-58-064-925"
|
||||
* panelID:
|
||||
* type: string
|
||||
* example: "67e4f754cc778ad6c123394b"
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Panel deleted successfully
|
||||
* 409:
|
||||
* description: Panel Already Deleted
|
||||
* 404:
|
||||
* description: Zone not found
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.patch("/panel/delete", panelService.deletePanel);
|
||||
// router.get("/zone/:sceneID", Zoneservice.allZones);
|
||||
export default router;
|
||||
@@ -1,5 +1,5 @@
|
||||
import express from 'express';
|
||||
import { share } from '../controller/share/share-Controller';
|
||||
import { share } from '../controller/share/share-Controller.ts';
|
||||
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import express from 'express';
|
||||
import { user } from '../controller/user-Controller';
|
||||
import { user } from '../controller/user-Controller.ts';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import express from 'express';
|
||||
import { wallItems } from '../controller/assets/wallitem-Controller';
|
||||
import { wallItems } from '../controller/assets/wallitem-Services.ts';
|
||||
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
143
src/api-server/Routes/widgetRoute.ts
Normal file
143
src/api-server/Routes/widgetRoute.ts
Normal file
@@ -0,0 +1,143 @@
|
||||
import * as express from "express";
|
||||
import { widgetService } from "../controller/visualization/widgetService.ts";
|
||||
const router = express.Router();
|
||||
/**
|
||||
* @swagger
|
||||
* tags:
|
||||
* - name: Widgets
|
||||
* description: API operations related to widgets
|
||||
*/
|
||||
/**
|
||||
* @swagger
|
||||
* components:
|
||||
* schemas:
|
||||
* Widget:
|
||||
* type: object
|
||||
* properties:
|
||||
* _id:
|
||||
* type: string
|
||||
* example: "60d0fe4f5311236168a109cd"
|
||||
* widgetName:
|
||||
* type: string
|
||||
* example: "Temperature Widget"
|
||||
* widgetside:
|
||||
* type: string
|
||||
* example: "right"
|
||||
* widgetID:
|
||||
* type: string
|
||||
* example: "wid-12345"
|
||||
* widgetOrder:
|
||||
* type: string
|
||||
* example: "1"
|
||||
* elementType:
|
||||
* type: string
|
||||
* example: "chart"
|
||||
* elementColor:
|
||||
* type: string
|
||||
* example: "#FF5733"
|
||||
* fontFamily:
|
||||
* type: string
|
||||
* example: "Arial"
|
||||
* fontStyle:
|
||||
* type: string
|
||||
* example: "bold"
|
||||
* fontWeight:
|
||||
* type: string
|
||||
* example: "600"
|
||||
* isArchive:
|
||||
* type: boolean
|
||||
* example: false
|
||||
* panelID:
|
||||
* type: string
|
||||
* example: "67e3d030ed12ffa47b4eade3"
|
||||
* Data:
|
||||
* type: array
|
||||
* items:
|
||||
* type: object
|
||||
* example: []
|
||||
* required:
|
||||
* - widgetName
|
||||
* - widgetID
|
||||
* - widgetOrder
|
||||
* - elementType
|
||||
* - panelID
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @swagger
|
||||
* /widget/save:
|
||||
* post:
|
||||
* summary: Create a new widget inside a panel
|
||||
* tags: [Widgets]
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* organization:
|
||||
* type: string
|
||||
* example: "NEWORG"
|
||||
* panelID:
|
||||
* type: string
|
||||
* example: "67e3d030ed12ffa47b4eade3"
|
||||
* widgetName:
|
||||
* type: string
|
||||
* example: "Temperature Widget"
|
||||
* widgetOrder:
|
||||
* type: string
|
||||
* example: "1"
|
||||
* type:
|
||||
* type: string
|
||||
* example: "chart"
|
||||
* widgetID:
|
||||
* type: string
|
||||
* example: "wid-12345"
|
||||
* panel:
|
||||
* type: string
|
||||
* example: "right"
|
||||
* responses:
|
||||
* 201:
|
||||
* description: Widget created successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* example: "Widget created successfully"
|
||||
* widgetID:
|
||||
* type: string
|
||||
* example: "60d0fe4f5311236168a109cd"
|
||||
* 404:
|
||||
* description: Panel not found
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* example: "PanelID not found"
|
||||
* 409:
|
||||
* description: Widget with the given widgetID already exists
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* example: "Widget already exists for the widgetID"
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.post("/widget/save", widgetService.addWidget);
|
||||
router.patch("/widget/delete", widgetService.deleteWidget);
|
||||
router.get(
|
||||
"/WidgetData/:widgetID/:organization",
|
||||
widgetService.getDatafromWidget
|
||||
);
|
||||
export default router;
|
||||
@@ -1,13 +1,13 @@
|
||||
import express from 'express';
|
||||
|
||||
import { zone } from '../controller/lines/zone-Controller';
|
||||
import { zone } from '../controller/lines/zone-Services.ts';
|
||||
|
||||
|
||||
const router = express.Router();
|
||||
router.post('/setZone',zone.setZone)
|
||||
router.delete('/deleteZone',zone.deleteZone)
|
||||
router.get('/findZones/:organization',zone.getZones)
|
||||
router.get('/A_zone/:zoneID/:organization',zone.ZoneData)
|
||||
router.get('/A_zone/:zoneId/:organization',zone.ZoneData)
|
||||
|
||||
|
||||
|
||||
|
||||
539
src/api-server/Routes/zoneRoutes.ts
Normal file
539
src/api-server/Routes/zoneRoutes.ts
Normal file
@@ -0,0 +1,539 @@
|
||||
import * as express from "express";
|
||||
import { Zoneservice } from "../controller/lines/zoneService.ts";
|
||||
const router = express.Router();
|
||||
/**
|
||||
* @swagger
|
||||
* components:
|
||||
* schemas:
|
||||
* Zone:
|
||||
* type: object
|
||||
* required:
|
||||
* - zoneName
|
||||
* - zoneUUID
|
||||
* - sceneID
|
||||
* - createdBy
|
||||
* - layer
|
||||
* - viewPortCenter
|
||||
* - viewPortposition
|
||||
* properties:
|
||||
* zoneName:
|
||||
* type: string
|
||||
* description: Name of the zone
|
||||
* zoneUUID:
|
||||
* type: string
|
||||
* description: Unique identifier for the zone
|
||||
* sceneID:
|
||||
* type: string
|
||||
* description: ID of the scene associated with the zone
|
||||
* createdBy:
|
||||
* type: string
|
||||
* description: User ID who created the zone
|
||||
* layer:
|
||||
* type: integer
|
||||
* description: Layer number in the scene
|
||||
* zonePoints:
|
||||
* type: array
|
||||
* description: List of points defining the zone
|
||||
* items:
|
||||
* type: array
|
||||
* items:
|
||||
* type: object
|
||||
* properties:
|
||||
* x:
|
||||
* type: number
|
||||
* y:
|
||||
* type: number
|
||||
* viewPortCenter:
|
||||
* type: array
|
||||
* description: Center position of the viewport
|
||||
* items:
|
||||
* type: object
|
||||
* properties:
|
||||
* x:
|
||||
* type: number
|
||||
* y:
|
||||
* type: number
|
||||
* viewPortposition:
|
||||
* type: array
|
||||
* description: Position of the viewport
|
||||
* items:
|
||||
* type: object
|
||||
* properties:
|
||||
* x:
|
||||
* type: number
|
||||
* panelOrder:
|
||||
* type: array
|
||||
* description: Order of panels
|
||||
* items:
|
||||
* type: string
|
||||
* enum: ["left", "right", "up", "down"]
|
||||
* lockedPanel:
|
||||
* type: array
|
||||
* description: Locked panels in the zone
|
||||
* items:
|
||||
* type: string
|
||||
* enum: ["left", "right", "up", "down"]
|
||||
* isArchive:
|
||||
* type: boolean
|
||||
* description: Flag to mark if the zone is archived
|
||||
* createdAt:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* description: Timestamp when the zone was created
|
||||
* updatedAt:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* description: Timestamp when the zone was last updated
|
||||
* example:
|
||||
* zoneName: "Zone 2"
|
||||
* zoneUUID: "0114-58-064-9"
|
||||
* sceneID: "125789632548"
|
||||
* createdBy: "012357894268"
|
||||
* layer: 1
|
||||
* zonePoints: [[{"x":5,"y":5}], [{"x":5,"y":5}], [{"x":5,"y":5}]]
|
||||
* viewPortCenter: [{"x":5, "y":5}]
|
||||
* viewPortposition: [{"x":5}]
|
||||
* panelOrder: ["left", "right"]
|
||||
* lockedPanel: ["up"]
|
||||
* isArchive: false
|
||||
* createdAt: "2025-01-01T00:00:00Z"
|
||||
* updatedAt: "2025-01-01T00:00:00Z"
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* tags:
|
||||
* name: Zones
|
||||
* description: API for managing zones
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /zone/save:
|
||||
* post:
|
||||
* summary: Create or update a zone
|
||||
* tags: [Zones]
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - organization
|
||||
* - zonesdata
|
||||
* properties:
|
||||
* organization:
|
||||
* type: string
|
||||
* description: Organization name
|
||||
* example: "NEWORG"
|
||||
* zonesdata:
|
||||
* type: object
|
||||
* required:
|
||||
* - zonename
|
||||
* - zoneId
|
||||
* - sceneID
|
||||
* - userid
|
||||
* - layer
|
||||
* - points
|
||||
* - viewportPosition
|
||||
* properties:
|
||||
* zonename:
|
||||
* type: string
|
||||
* description: Name of the zone
|
||||
* example: "Zone 2"
|
||||
* zoneId:
|
||||
* type: string
|
||||
* description: Unique identifier for the zone
|
||||
* example: "0114-58-064-9"
|
||||
* sceneID:
|
||||
* type: string
|
||||
* description: ID of the scene associated with the zone
|
||||
* example: "125789632548"
|
||||
* userid:
|
||||
* type: string
|
||||
* description: User ID who created the zone
|
||||
* example: "012357894268"
|
||||
* layer:
|
||||
* type: integer
|
||||
* description: Layer number in the scene
|
||||
* example: 1
|
||||
* points:
|
||||
* type: array
|
||||
* description: List of points defining the zone
|
||||
* items:
|
||||
* type: object
|
||||
* properties:
|
||||
* x:
|
||||
* type: number
|
||||
* y:
|
||||
* type: number
|
||||
* example: [{"x":5,"y":5}, {"x":10,"y":10}]
|
||||
* viewportPosition:
|
||||
* type: array
|
||||
* description: Position of the viewport
|
||||
* items:
|
||||
* type: object
|
||||
* properties:
|
||||
* x:
|
||||
* type: number
|
||||
* y:
|
||||
* type: number
|
||||
* example: [{"x":5, "y":5}]
|
||||
* viewPortCenter:
|
||||
* type: array
|
||||
* description: Center of the viewport
|
||||
* items:
|
||||
* type: object
|
||||
* properties:
|
||||
* x:
|
||||
* type: number
|
||||
* y:
|
||||
* type: number
|
||||
* example: [{"x":10, "y":10}]
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Zone created or updated successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* example: "Zone created successfully"
|
||||
* zoneData:
|
||||
* type: object
|
||||
* properties:
|
||||
* zoneName:
|
||||
* type: string
|
||||
* points:
|
||||
* type: array
|
||||
* items:
|
||||
* type: object
|
||||
* properties:
|
||||
* x:
|
||||
* type: number
|
||||
* y:
|
||||
* type: number
|
||||
* viewPortposition:
|
||||
* type: array
|
||||
* items:
|
||||
* type: object
|
||||
* viewPortCenter:
|
||||
* type: array
|
||||
* items:
|
||||
* type: object
|
||||
* 404:
|
||||
* description: Zone not updated
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* example: "Zone not updated"
|
||||
* 500:
|
||||
* description: Server error
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* error:
|
||||
* type: string
|
||||
* example: "Internal server error"
|
||||
*/
|
||||
router.post("/zone/save", Zoneservice.addandUpdateZone); //Zone create and update for the points
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /zones/{sceneID}:
|
||||
* get:
|
||||
* summary: Get all zones for a scene
|
||||
* tags: [Zones]
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: sceneID
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* description: ID of the scene
|
||||
* - in: query
|
||||
* name: organization
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* description: Organization name
|
||||
* responses:
|
||||
* 200:
|
||||
* description: List of zones retrieved successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: array
|
||||
* items:
|
||||
* type: object
|
||||
* properties:
|
||||
* zoneName:
|
||||
* type: string
|
||||
* description: Name of the zone
|
||||
* sceneID:
|
||||
* type: string
|
||||
* description: Scene ID associated with the zone
|
||||
* zoneUUID:
|
||||
* type: string
|
||||
* description: Unique identifier for the zone
|
||||
* 404:
|
||||
* description: No zones found for the given scene ID
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* example: "Zone not found for the UUID"
|
||||
* 500:
|
||||
* description: Server error
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* error:
|
||||
* type: string
|
||||
* example: "Internal Server Error"
|
||||
* examples:
|
||||
* Successful Response:
|
||||
* value:
|
||||
* - zoneName: "Zone A"
|
||||
* sceneID: "scene123"
|
||||
* zoneUUID: "UUID-12345"
|
||||
* - zoneName: "Zone B"
|
||||
* sceneID: "scene123"
|
||||
* zoneUUID: "UUID-67890"
|
||||
* Not Found Response:
|
||||
* value:
|
||||
* message: "Zone not found for the UUID"
|
||||
*/
|
||||
router.get("/zones/:sceneID", Zoneservice.allZones);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /ZoneVisualization/{zoneId}:
|
||||
* get:
|
||||
* summary: Get Zone Panel Data
|
||||
* tags: [Zones]
|
||||
* description: Fetches zone panel details including widgets, panel order, locked panels, and points.
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: zoneId
|
||||
* required: true
|
||||
* description: The unique identifier of the zone.
|
||||
* schema:
|
||||
* type: string
|
||||
* - in: query
|
||||
* name: organization
|
||||
* required: true
|
||||
* description: The organization name to filter data.
|
||||
* schema:
|
||||
* type: string
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Zone panel data retrieved successfully.
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* zoneName:
|
||||
* type: string
|
||||
* activeSides:
|
||||
* type: array
|
||||
* items:
|
||||
* type: string
|
||||
* panelOrder:
|
||||
* type: array
|
||||
* items:
|
||||
* type: string
|
||||
* lockedPanels:
|
||||
* type: array
|
||||
* items:
|
||||
* type: string
|
||||
* points:
|
||||
* type: array
|
||||
* items:
|
||||
* type: object
|
||||
* properties:
|
||||
* x:
|
||||
* type: number
|
||||
* y:
|
||||
* type: number
|
||||
* widgets:
|
||||
* type: array
|
||||
* items:
|
||||
* type: object
|
||||
* properties:
|
||||
* id:
|
||||
* type: string
|
||||
* type:
|
||||
* type: string
|
||||
* title:
|
||||
* type: string
|
||||
* panel:
|
||||
* type: string
|
||||
* data:
|
||||
* type: array
|
||||
* items:
|
||||
* type: object
|
||||
* example:
|
||||
* zoneName: "Zone 2"
|
||||
* activeSides: []
|
||||
* panelOrder: []
|
||||
* lockedPanels: []
|
||||
* points:
|
||||
* - x: 5
|
||||
* y: 5
|
||||
* - x: 10
|
||||
* y: 10
|
||||
* widgets: []
|
||||
* 404:
|
||||
* description: Zone not found
|
||||
* content:
|
||||
* application/json:
|
||||
* example:
|
||||
* message: "Zone not found for the UUID"
|
||||
* 500:
|
||||
* description: Internal Server Error
|
||||
* content:
|
||||
* application/json:
|
||||
* example:
|
||||
* error: "Internal Server Error"
|
||||
*/
|
||||
router.get("/ZoneVisualization/:zoneId", Zoneservice.singleZonePanelDatas);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /A_zone/{zoneId}:
|
||||
* get:
|
||||
* summary: Get a specific zone's data
|
||||
* tags: [Zones]
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: zoneId
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* description: Unique identifier of the zone
|
||||
* - in: query
|
||||
* name: organization
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* description: Organization name
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Zone data retrieved successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* zoneUUID:
|
||||
* type: string
|
||||
* description: Unique identifier of the zone
|
||||
* zoneName:
|
||||
* type: string
|
||||
* description: Name of the zone
|
||||
* isArchive:
|
||||
* type: boolean
|
||||
* description: Indicates if the zone is archived
|
||||
* 404:
|
||||
* description: Zone not found
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* example: "Zone not found"
|
||||
* 500:
|
||||
* description: Server error
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* error:
|
||||
* type: string
|
||||
* example: "Internal Server Error"
|
||||
* examples:
|
||||
* Successful Response:
|
||||
* value:
|
||||
* zoneUUID: "abc123"
|
||||
* zoneName: "Zone A"
|
||||
* isArchive: false
|
||||
* otherProperties: {}
|
||||
* Not Found Response:
|
||||
* value:
|
||||
* message: "Zone not found"
|
||||
*/
|
||||
router.get("/A_zone/:zoneId", Zoneservice.ZoneData);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /zone/{zoneId}:
|
||||
* patch:
|
||||
* summary: Soft delete a zone
|
||||
* tags: [Zones]
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: zoneId
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* description: Unique identifier of the zone
|
||||
* - in: query
|
||||
* name: organization
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
* description: Organization name
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Zone successfully deleted
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* example: "Zone deleted successfully"
|
||||
* 404:
|
||||
* description: Zone not found
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* message:
|
||||
* type: string
|
||||
* example: "Zone not found for the UUID"
|
||||
* 500:
|
||||
* description: Server error
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* error:
|
||||
* type: string
|
||||
* example: "Internal Server Error"
|
||||
*/
|
||||
router.patch("/zone/:zoneId", Zoneservice.deleteAZone); //delete Zone
|
||||
// router.get("/zone/:sceneID", Zoneservice.allZones);
|
||||
export default router;
|
||||
@@ -1,15 +1,18 @@
|
||||
import express from 'express';
|
||||
import cors from 'cors';
|
||||
import connectDB from '../shared/connect/mongoose';
|
||||
import connectDB from '../shared/connect/mongoose.ts';
|
||||
import dotenv from 'dotenv';
|
||||
import cameraRoutes from './Routes/camera-Routes'
|
||||
import environmentsRoutes from './Routes/environments-Routes'
|
||||
import linesRoutes from './Routes/lines-Routes'
|
||||
import flooritemRoutes from './Routes/flooritem-Routes'
|
||||
import WallitemRoutes from './Routes/wallItems-Routes'
|
||||
import userRoutes from './Routes/user-Routes'
|
||||
import shareRoutes from './Routes/share-Routes'
|
||||
import zoneRoutes from './Routes/zone-Routes'
|
||||
import cameraRoutes from './Routes/camera-Routes.ts'
|
||||
import environmentsRoutes from './Routes/environments-Routes.ts'
|
||||
import linesRoutes from './Routes/lines-Routes.ts'
|
||||
import flooritemRoutes from './Routes/flooritem-Routes.ts'
|
||||
import WallitemRoutes from './Routes/wallItems-Routes.ts'
|
||||
import userRoutes from './Routes/user-Routes.ts'
|
||||
import shareRoutes from './Routes/share-Routes.ts'
|
||||
import zoneRoutes from './Routes/zone-Routes.ts'
|
||||
import zoneRoutes2 from './Routes/zoneRoutes.ts'//update
|
||||
import panelRouter from './Routes/panelRoutes.ts'
|
||||
import widgetRouter from './Routes/widgetRoute.ts'
|
||||
|
||||
|
||||
const app = express();
|
||||
@@ -30,5 +33,9 @@ app.use('/api/v1', flooritemRoutes);
|
||||
app.use('/api/v1', WallitemRoutes);
|
||||
app.use('/api/v1', userRoutes);
|
||||
app.use('/api/v1', shareRoutes);
|
||||
app.use('/api/v2', zoneRoutes);
|
||||
// app.use('/api/v2', zoneRoutes);
|
||||
//update
|
||||
app.use('/api/v2', zoneRoutes2);//updates
|
||||
app.use('/api/v2', panelRouter);
|
||||
app.use('/api/v2', widgetRouter);
|
||||
export default app;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Request, Response } from "express";
|
||||
import floorItemsModel from "../../../shared/model/assets/flooritems-Model";
|
||||
import floorItemsModel from "../../../shared/model/assets/flooritems-Model.ts";
|
||||
|
||||
|
||||
export class floorItems {
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Request, Response } from "express";
|
||||
import wallItenmModel from "../../../shared/model/assets/wallitems-Model";
|
||||
import wallItenmModel from "../../../shared/model/assets/wallitems-Model.ts";
|
||||
|
||||
|
||||
export class wallItems {
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Request, Response } from "express";
|
||||
import cameraModel from "../../../shared/model/camera/camera-Model";
|
||||
import userModel from "../../../shared/model/user-Model";
|
||||
import cameraModel from "../../../shared/model/camera/camera-Model.ts";
|
||||
import userModel from "../../../shared/model/user-Model.ts";
|
||||
|
||||
export class camera {
|
||||
static async createCamera(req: Request, res: Response) {
|
||||
@@ -54,7 +54,7 @@ export class camera {
|
||||
const findactiveUsers = await userModel(organization).find({activeStatus:"online"})
|
||||
|
||||
|
||||
const cameraDataPromises = findactiveUsers.map(async (activeUser) => {
|
||||
const cameraDataPromises = findactiveUsers.map(async (activeUser:any) => {
|
||||
const cameraData = await cameraModel(organization)
|
||||
.findOne({ userId: activeUser._id })
|
||||
.select("position target rotation -_id");
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Request, Response } from "express";
|
||||
import environmentModel from "../../../shared/model/environments/environments-Model";
|
||||
import environmentModel from "../../../shared/model/environments/environments-Model.ts";
|
||||
|
||||
export class environment {
|
||||
static async setEnvironment(req: Request, res: Response) {
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Request, Response } from "express";
|
||||
import lineModel from "../../../shared/model/lines/lines-Model";
|
||||
import lineModel from "../../../shared/model/lines/lines-Model.ts";
|
||||
|
||||
export class lines {
|
||||
static async setLines(req: Request, res: Response) {
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Request, Response } from "express";
|
||||
import zoneModel from "../../../shared/model/lines/zone-Model";
|
||||
import zoneModel from "../../../shared/model/lines/zone-Model.ts";
|
||||
export class zone {
|
||||
static async setZone(req: Request, res: Response) {
|
||||
try {
|
||||
@@ -75,9 +75,9 @@ export class zone {
|
||||
static async ZoneData(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const organization = req.params.organization;
|
||||
const zoneID = req.params.zoneID;
|
||||
const zoneId = req.params.zoneId;
|
||||
const findZone = await zoneModel(organization)
|
||||
.findOne({ zoneId: zoneID })
|
||||
.findOne({ zoneId: zoneId })
|
||||
// .select("zoneName");
|
||||
console.log("findZone: ", findZone);
|
||||
if (findZone) return res.status(200).json(findZone);
|
||||
197
src/api-server/controller/lines/zoneService.ts
Normal file
197
src/api-server/controller/lines/zoneService.ts
Normal file
@@ -0,0 +1,197 @@
|
||||
import { Request, Response } from "express";
|
||||
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||
import panelSchema from "../../../shared/model/vizualization/panelmodel.ts";
|
||||
import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts";
|
||||
export class Zoneservice {
|
||||
static async addandUpdateZone(req: Request, res: Response): Promise<any> {
|
||||
const organization = req.body.organization;
|
||||
const zoneDatas = req.body.zonesdata;
|
||||
|
||||
console.log('organization: ', organization);
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneDatas.zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone) {
|
||||
const newZone = await zoneSchema(organization).create({
|
||||
zoneName: zoneDatas.zonename,
|
||||
zoneId: zoneDatas.zoneId,
|
||||
zonePoints: zoneDatas.points,
|
||||
viewPortposition: zoneDatas.viewportPosition,
|
||||
viewPortCenter: zoneDatas.viewPortCenter,
|
||||
createdBy: zoneDatas.userid,
|
||||
layer: zoneDatas.layer,
|
||||
sceneID: zoneDatas.sceneID,
|
||||
});
|
||||
if (newZone)
|
||||
return res.status(200).json({
|
||||
message: "Zone created successfully",
|
||||
zoneData: {
|
||||
zoneName: newZone.zoneName,
|
||||
points: newZone.zonePoints,
|
||||
viewPortposition: zoneDatas.viewPortposition,
|
||||
viewPortCenter: zoneDatas.viewPortCenter,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const replaceZone = await zoneSchema(organization).findOneAndUpdate(
|
||||
{ zoneId: zoneDatas.zoneId, isArchive: false },
|
||||
{
|
||||
zonePoints: zoneDatas.points,
|
||||
viewPortposition: zoneDatas.viewPortposition,
|
||||
viewPortCenter: zoneDatas.viewPortCenter,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
if (!replaceZone)
|
||||
return res.status(404).json({ message: "Zone not updated" });
|
||||
else
|
||||
return res.status(200).json({
|
||||
message: "updated successfully",
|
||||
zoneData: {
|
||||
zoneName: replaceZone.zoneName,
|
||||
points: replaceZone.zonePoints,
|
||||
viewPortposition: replaceZone.viewPortposition,
|
||||
viewPortCenter: replaceZone.viewPortCenter,
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
static async deleteAZone(req: Request, res: Response): Promise<any> {
|
||||
const organization = req.query.organization;
|
||||
const zoneId = req.params.zoneId;
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone) {
|
||||
return res.status(404).json({ message: "Zone not found for the UUID" });
|
||||
} else {
|
||||
const deleteZone = await zoneSchema(organization).findOneAndUpdate(
|
||||
{ zoneId: zoneId, isArchive: false },
|
||||
{
|
||||
isArchive: true,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
if (deleteZone) {
|
||||
return res.status(200).json({ message: "Zone deleted successfully" });
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
static async singleZonePanelDatas(req: Request, res: Response): Promise<any> {
|
||||
const organization = req.query.organization;
|
||||
const zoneId = req.params.zoneId;
|
||||
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization)
|
||||
.findOne({
|
||||
zoneId: req.params.zoneId,
|
||||
isArchive: false,
|
||||
})
|
||||
.select("panelOrder zoneName zonePoints lockedPanel");
|
||||
if (!existingZone) {
|
||||
return res.send({ message: "Zone not found for the UUID" });
|
||||
} else {
|
||||
const panelData = await panelSchema(organization).find({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
const zoneName = existingZone.zoneName as string;
|
||||
|
||||
const widgets = await Promise.all(
|
||||
panelData.map(async (data) => {
|
||||
const widgetDataArray = await widgetSchema(organization).find({
|
||||
panelID: data._id,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
return widgetDataArray.map((widgetData) => ({
|
||||
id: widgetData.widgetID,
|
||||
type: widgetData.elementType,
|
||||
title: widgetData.widgetName,
|
||||
panel: widgetData.widgetside,
|
||||
data: widgetData.Data || [],
|
||||
}));
|
||||
})
|
||||
);
|
||||
|
||||
const flattenedWidgets = widgets.flat();
|
||||
|
||||
const objectData = {
|
||||
zoneName,
|
||||
activeSides: existingZone.panelOrder || [],
|
||||
panelOrder: existingZone.panelOrder || [],
|
||||
lockedPanels: existingZone.lockedPanel || [],
|
||||
points: existingZone.zonePoints || [],
|
||||
widgets: flattenedWidgets,
|
||||
};
|
||||
|
||||
return res.status(200).json(objectData);
|
||||
}
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
static async allZones(req: Request, res: Response): Promise<any> {
|
||||
const organization = req.query.organization;
|
||||
const sceneID = req.params.sceneID || "scene123";
|
||||
try {
|
||||
const Allzones = await zoneSchema(organization)
|
||||
.find({ sceneID: sceneID, isArchive: false })
|
||||
.select("zoneName sceneID zoneId");
|
||||
|
||||
if (!Allzones || Allzones.length === 0) {
|
||||
return res.status(404).json({ message: "Zone not found for the UUID" });
|
||||
}
|
||||
return res.status(200).json(Allzones);
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
static async ZoneData(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const organization = req.query.organization;
|
||||
console.log("organization: ", organization);
|
||||
const zoneId = req.params.zoneId;
|
||||
console.log("zoneId: ", zoneId);
|
||||
const findZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
});
|
||||
// .select("zoneName");
|
||||
if (findZone) return res.status(200).json(findZone);
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// static async zoneIdgenerate(req: Request, res: Response): Promise<any> {
|
||||
// const organization = req.query.organization;
|
||||
// const sceneID = req.params.sceneID;
|
||||
// try {
|
||||
// const Allzones = await zoneSchema(organization)
|
||||
// .find({ sceneID: sceneID, isArchive: false })
|
||||
// .select("zoneName sceneID zoneId");
|
||||
|
||||
// if (!Allzones || Allzones.length === 0) {
|
||||
// return res.send({ message: "Zone not found for the UUID" });
|
||||
// }
|
||||
// return res.send(Allzones);
|
||||
// } catch (error: any) {
|
||||
// return res.status(500).send(error.message);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Request, Response } from "express";
|
||||
import userModel from "../../../shared/model/user-Model";
|
||||
import userModel from "../../../shared/model/user-Model.ts";
|
||||
|
||||
|
||||
export class share {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Request, Response } from "express";
|
||||
import { Server } from 'http';
|
||||
import userModel from "../../shared/model/user-Model";
|
||||
import userModel from "../../shared/model/user-Model.ts";
|
||||
import { isSharedArrayBuffer } from "util/types";
|
||||
const {hashGenerate,hashValidator} = require("../../shared/security/Hasing.ts")
|
||||
import {hashGenerate,hashValidator} from "../../shared/security/Hasing.ts"
|
||||
// import {hashGenerate} from '../security/Hasing'
|
||||
|
||||
let serverAlive = true;
|
||||
|
||||
113
src/api-server/controller/visualization/panelService.ts
Normal file
113
src/api-server/controller/visualization/panelService.ts
Normal file
@@ -0,0 +1,113 @@
|
||||
import { Request, Response } from "express";
|
||||
import panelSchema from "../../../shared/model/vizualization/panelmodel.ts";
|
||||
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||
import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts";
|
||||
|
||||
export class panelService {
|
||||
static async AddPanel(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
console.log('req.body: ', req.body);
|
||||
const organization = req.body.organization;
|
||||
console.log('organization: ', organization);
|
||||
const zoneId = req.body.zoneId;
|
||||
const panelName = req.body.panelName;
|
||||
const panelOrder = req.body.panelOrder;
|
||||
const findZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
if (!findZone) {
|
||||
return res.status(404).json({ message: "Zone not found" });
|
||||
}
|
||||
const updatezone = await zoneSchema(organization).findOneAndUpdate(
|
||||
{ zoneId: zoneId, isArchive: false },
|
||||
{ panelOrder: panelOrder },
|
||||
{ new: true }
|
||||
);
|
||||
const existingPanels = await panelSchema(organization).find({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
const existingPanelNames = existingPanels.map(
|
||||
(panel: any) => panel.panelName
|
||||
);
|
||||
|
||||
const missingPanels = panelOrder.filter(
|
||||
(panelName: string) => !existingPanelNames.includes(panelName)
|
||||
);
|
||||
|
||||
const createdPanels = [];
|
||||
for (const panelName of missingPanels) {
|
||||
const newPanel = await panelSchema(organization).create({
|
||||
zoneId: zoneId,
|
||||
panelName: panelName,
|
||||
widgets: [],
|
||||
isArchive: false,
|
||||
});
|
||||
createdPanels.push(newPanel);
|
||||
}
|
||||
|
||||
if (createdPanels.length === 0) {
|
||||
return res.status(200).json({
|
||||
message: "No new panels were created. All panels already exist.",
|
||||
});
|
||||
}
|
||||
// const IDdata = createdPanels.map((ID: any) => {
|
||||
// return ID._id;
|
||||
// });
|
||||
console.log("IDdata: ", createdPanels);
|
||||
createdPanels
|
||||
return res.status(201).json({
|
||||
message: "Panels created successfully",
|
||||
panelID: createdPanels,
|
||||
});
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
static async deletePanel(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { organization, panelID, zoneId } = req.body;
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone)
|
||||
return res.status(404).json({ message: "Zone not found" });
|
||||
const existingPanel = await panelSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
_id: panelID,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingPanel)
|
||||
return res.status(409).json({ message: "Panel Already Deleted" });
|
||||
const updatePanel = await panelSchema(organization).updateOne(
|
||||
{ _id: panelID, isArchive: false },
|
||||
{ $set: { isArchive: true } }
|
||||
);
|
||||
const existingWidgets = await widgetSchema(organization).find({
|
||||
panelID: panelID,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
for (const widgetData of existingWidgets) {
|
||||
widgetData.isArchive = true;
|
||||
await widgetData.save();
|
||||
}
|
||||
|
||||
if (existingZone.panelOrder.includes(existingPanel.panelName)) {
|
||||
existingZone.panelOrder = existingZone.panelOrder.filter(
|
||||
(panel: any) => panel !== existingPanel.panelName
|
||||
);
|
||||
|
||||
await existingZone.save();
|
||||
}
|
||||
|
||||
return res.status(200).json({ message: "Panel deleted successfully" });
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
127
src/api-server/controller/visualization/widgetService.ts
Normal file
127
src/api-server/controller/visualization/widgetService.ts
Normal file
@@ -0,0 +1,127 @@
|
||||
import { Request, Response } from "express";
|
||||
import panelSchema from "../../../shared/model/vizualization/panelmodel.ts";
|
||||
import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts";
|
||||
export class widgetService {
|
||||
static async addWidget(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const {
|
||||
organization,
|
||||
panelID,
|
||||
widgetName,
|
||||
widgetOrder,
|
||||
type,
|
||||
widgetID,
|
||||
panel,
|
||||
Data,
|
||||
} = req.body;
|
||||
const existingPanel = await panelSchema(organization).findOne({
|
||||
_id: panelID,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingPanel)
|
||||
return res.status(404).json({ message: "PanelID not found" });
|
||||
|
||||
if (existingPanel.panelName === panel) {
|
||||
const existingWidget = await widgetSchema(organization).findOne({
|
||||
panelID: panelID,
|
||||
widgetID: widgetID,
|
||||
isArchive: false,
|
||||
widgetOrder: widgetOrder,
|
||||
});
|
||||
if (existingWidget)
|
||||
return res
|
||||
.status(409)
|
||||
.json({ message: "Widget already exist for the widgetID" });
|
||||
const newWidget = await widgetSchema(organization).create({
|
||||
widgetID: widgetID,
|
||||
elementType: type,
|
||||
widgetOrder: widgetOrder,
|
||||
widgetName: widgetName,
|
||||
panelID: panelID,
|
||||
widgetside: panel,
|
||||
Data: {
|
||||
measurements: Data.measurements || {},
|
||||
duration: Data.duration || "1hr",
|
||||
},
|
||||
});
|
||||
if (newWidget) {
|
||||
existingPanel.widgets.push(newWidget._id);
|
||||
await existingPanel.save();
|
||||
return res.status(201).json({
|
||||
message: "Widget created successfully",
|
||||
widgetID: newWidget._id,
|
||||
});
|
||||
}
|
||||
}
|
||||
return res.json({ message: "Type mismatch" });
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
static async deleteWidget(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { widgetID, organization } = req.body;
|
||||
const findWidget = await widgetSchema(organization).findOne({
|
||||
_id: widgetID,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!findWidget)
|
||||
return res.status(409).json({ message: "Widget already deleted" });
|
||||
const widgetData = await widgetSchema(organization).updateOne(
|
||||
{ _id: widgetID, isArchive: false },
|
||||
{ $set: { isArchive: true } }
|
||||
);
|
||||
|
||||
if (widgetData) {
|
||||
// Find all widgets in the same panel and sort them by widgetOrder
|
||||
const widgets = await widgetSchema(organization)
|
||||
.find({
|
||||
panelID: findWidget.panelID,
|
||||
isArchive: false,
|
||||
})
|
||||
.sort({ widgetOrder: 1 });
|
||||
|
||||
// Reassign widgetOrder values
|
||||
for (let i = 0; i < widgets.length; i++) {
|
||||
widgets[i].widgetOrder = (i + 1).toString(); // Convert to string
|
||||
await widgets[i].save();
|
||||
}
|
||||
const panelData = await panelSchema(organization).findOne({
|
||||
_id: findWidget.panelID,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
if (panelData.widgets.includes(widgetID)) {
|
||||
panelData.widgets = panelData.widgets.filter(
|
||||
(widget: any) => widget !== findWidget._id
|
||||
);
|
||||
}
|
||||
await panelData.save();
|
||||
}
|
||||
return res.status(200).json({ message: "Widget deleted successfully" });
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
static async getDatafromWidget(req: Request, res: Response): Promise<any> {
|
||||
const { organization, widgetID } = req.params;
|
||||
try {
|
||||
const existingWidget = await widgetSchema(organization)
|
||||
.findOne({
|
||||
_id: widgetID,
|
||||
isArchive: false,
|
||||
})
|
||||
.select("Data -_id");
|
||||
const Datastructure = {
|
||||
measurements: existingWidget.Data.measurements || {},
|
||||
duration: existingWidget.Data.duration || "1hr",
|
||||
};
|
||||
|
||||
if (existingWidget) return res.status(200).json({ Data: Datastructure });
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,27 @@
|
||||
import app from './app';
|
||||
import app from './app.ts';
|
||||
import http from 'http';
|
||||
import ip from 'ip';
|
||||
|
||||
// import { startHealthCheck } from './controller/user-Controller';
|
||||
import swaggerUi from 'swagger-ui-express';
|
||||
import mongoAdminCreation from '../shared/security/mongosecurity';
|
||||
import mongoAdminCreation from '../shared/security/mongosecurity.ts';
|
||||
import fs from 'fs';
|
||||
const server = http.createServer(app);
|
||||
|
||||
let swaggerDocument;
|
||||
try {
|
||||
|
||||
let swaggerDocument = {};
|
||||
// try {
|
||||
// swaggerDocument = require('../../swagger-output.json');
|
||||
|
||||
swaggerDocument = require('../../swagger-output.json');
|
||||
// } catch (error) {
|
||||
// console.error('Error loading Swagger JSON:', error);
|
||||
// swaggerDocument = {}; // Fallback: empty object or some default
|
||||
// }
|
||||
try {
|
||||
swaggerDocument = JSON.parse(fs.readFileSync('swagger-output.json', 'utf-8'));
|
||||
} catch (error) {
|
||||
console.error('Error loading Swagger JSON:', error);
|
||||
swaggerDocument = {}; // Fallback: empty object or some default
|
||||
}
|
||||
|
||||
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
|
||||
const organization = process.env.ORGANIZATION_NAME || 'defaultOrganization'; // Replace with your logic
|
||||
|
||||
|
||||
Reference in New Issue
Block a user