Merge branch 'main' into branch-v2
This commit is contained in:
@@ -35,7 +35,7 @@ export interface assetData extends Document {
|
||||
}[];
|
||||
position: [];
|
||||
// rotation: [];
|
||||
rotation: {
|
||||
rotation: {
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
@@ -72,7 +72,7 @@ const assetDataSchema: Schema = new Schema({
|
||||
},
|
||||
],
|
||||
position: { type: Array},
|
||||
// rotation: { type: Array },
|
||||
// rotation: { type: Array},
|
||||
rotation: {
|
||||
x: { type: Number },
|
||||
y: { type: Number },
|
||||
|
||||
127
src/socket-server/services/assets/asset-Controller.ts
Normal file
127
src/socket-server/services/assets/asset-Controller.ts
Normal file
@@ -0,0 +1,127 @@
|
||||
import assetModel from "../../../shared/model/builder/assets/asset-Model.ts";
|
||||
import actionModel from "../../../shared/model/simulation/actionmodel.ts";
|
||||
import triggerModel from "../../../shared/model/simulation/triggersmodel.ts";
|
||||
|
||||
export const setAssetModel = async (data: any) => {
|
||||
const {modeluuid, modelname,position,rotation, eventData,modelfileID,isLocked,isVisible,organization, }= data
|
||||
console.log('data: ', data);
|
||||
// const position=data.position
|
||||
// const rotation=data.rotation
|
||||
try {
|
||||
const findvalue = await assetModel(organization).findOne({
|
||||
modeluuid: modeluuid,
|
||||
modelname: modelname,
|
||||
});
|
||||
|
||||
if (findvalue) {
|
||||
console.log('findvalue: ', findvalue);
|
||||
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
||||
{ modeluuid: modeluuid, modelname: modelname },
|
||||
{
|
||||
position: position,
|
||||
rotation: rotation,
|
||||
isVisible: isVisible,
|
||||
isLocked: isLocked,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
console.log('updatevalue: ', updatevalue);
|
||||
return { success: true, message: 'Model updated successfully', data: updatevalue, organization: organization }
|
||||
} else {
|
||||
let assetData: any = {
|
||||
modeluuid,
|
||||
modelname,
|
||||
position,
|
||||
modelfileID,
|
||||
rotation,
|
||||
isLocked,
|
||||
isVisible,
|
||||
};
|
||||
if (eventData) {
|
||||
let pointRefs: any[] = [];
|
||||
|
||||
if (Array.isArray(eventData.points)) {
|
||||
for (const point of eventData.points) {
|
||||
let actionRefs: any[] = [];
|
||||
let triggerRefs: any[] = [];
|
||||
|
||||
if (Array.isArray(point.actions)) {
|
||||
for (const action of point.actions) {
|
||||
const actionDoc = await actionModel(organization).create({
|
||||
pointsUUID: point.uuid,
|
||||
isArchive: false,
|
||||
uuid: action.uuid,
|
||||
name: action.name,
|
||||
type: action.type,
|
||||
material: action.material,
|
||||
delay: action.delay,
|
||||
spawn_Interval: action.spawn_Interval,
|
||||
});
|
||||
await actionDoc.save();
|
||||
actionRefs.push(actionDoc._id);
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(point.triggers)) {
|
||||
for (const trigger of point.triggers) {
|
||||
const triggerDoc = await triggerModel(organization).create({
|
||||
pointsUUID: point.uuid,
|
||||
isArchive: false,
|
||||
uuid: trigger.uuid,
|
||||
name: trigger.name,
|
||||
type: trigger.type,
|
||||
bufferTime: trigger.bufferTime,
|
||||
});
|
||||
await triggerDoc.save();
|
||||
triggerRefs.push(triggerDoc._id);
|
||||
}
|
||||
}
|
||||
|
||||
pointRefs.push({
|
||||
uuid: point.uuid,
|
||||
position: point.position || [],
|
||||
rotation: point.rotation || [],
|
||||
actions: actionRefs,
|
||||
triggers: triggerRefs,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
assetData.speed = eventData.speed;
|
||||
assetData.type = eventData.type;
|
||||
assetData.points = pointRefs;
|
||||
}
|
||||
|
||||
const assetDoc = await assetModel(organization).create(assetData);
|
||||
await assetDoc.save();
|
||||
// await assetDoc.save();
|
||||
// if(assetDoc.)
|
||||
const assetDatas={
|
||||
modeluuid:assetDoc.modeluuid,modelname:assetDoc.modelname,modelfileID:assetDoc.modelfileID,position:assetDoc.position,rotation:assetDoc.rotation,isLocked:assetDoc.isLocked,isVisible:assetDoc.isVisible
|
||||
,eventData:{points:assetDoc.points,type:assetDoc.type,speed:assetDoc.speed}
|
||||
}
|
||||
return { success: true, message:"Model created successfully", data: assetDatas, organization: organization }
|
||||
}
|
||||
} catch (error:any) {
|
||||
// console.error("Error creating flooritems:", error);
|
||||
return { success: false, message: error?.message || "Error occurred while ModelAsset", error, organization: organization }
|
||||
}
|
||||
}
|
||||
export const deleteAssetModel = async (data: any)=>{
|
||||
const { modeluuid,modelname,organization } = data;
|
||||
try {
|
||||
|
||||
const findValue = await assetModel(organization).findOneAndDelete({modeluuid:modeluuid,modelname:modelname})
|
||||
if (!findValue) {
|
||||
return { success: false, message: 'model not found',organization:organization }
|
||||
|
||||
} else {
|
||||
|
||||
return { success: true, message: 'Model deleted successfully', data: findValue,organization:organization }
|
||||
}
|
||||
} catch (error) {
|
||||
// console.error('Error get flooritems:', error);
|
||||
return { success: false, message: 'Failed to delete asset', error,organization:organization }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,9 @@ import { Socket } from "socket.io";
|
||||
import cameraModel from "../../../shared/model/camera/camera-Model.ts";
|
||||
|
||||
export const createCamera = async (data: any,) => {
|
||||
const { userId, position, target, organization,rotation } = data
|
||||
try {
|
||||
|
||||
const { userId, position, target, organization,rotation } = data
|
||||
|
||||
const findCamera = await cameraModel(organization).findOne({ userId: userId })
|
||||
if (findCamera) {
|
||||
@@ -18,14 +18,14 @@ export const createCamera = async (data: any,) => {
|
||||
else {
|
||||
const newCamera = await cameraModel(organization).create({ userId, position, target,rotation })
|
||||
|
||||
return { success: false, message: 'Camera created' ,data:newCamera,organization:organization}
|
||||
return { success: true, message: 'Camera created' ,data:newCamera,organization:organization}
|
||||
|
||||
}
|
||||
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error('Error creating camera:', error);
|
||||
return { success: false, message: 'Error creating or updating camera', error, }
|
||||
return { success: false, message: 'Error creating or updating camera', error, organization:organization}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import environmentModel from "../../../shared/model/environments/environments-Mo
|
||||
|
||||
|
||||
export const setEnvironment = async (data: any,) => {
|
||||
const { userId,roofVisibility,wallVisibility,shadowVisibility, organization } = data
|
||||
try {
|
||||
const { userId,roofVisibility,wallVisibility,shadowVisibility, organization } = data
|
||||
|
||||
const findvalue = await environmentModel(organization).findOne({ userId: userId })
|
||||
if (findvalue) {
|
||||
@@ -27,7 +27,7 @@ export const setEnvironment = async (data: any,) => {
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error('Error creating evironments:', error);
|
||||
return { success: false, message: 'Error creating or updating evironments', error }
|
||||
return { success: false, message: 'Error creating or updating evironments', error ,organization:organization}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,21 +3,21 @@ import lineModel from "../../../shared/model/lines/lines-Model.ts";
|
||||
|
||||
|
||||
export const createLineItems = async (data: any)=>{
|
||||
const {organization,layer,line,type}=data
|
||||
try {
|
||||
const {organization,layer,line,type}=data
|
||||
const newLine = await lineModel(organization).create({ layer,line,type });
|
||||
return { success: true, message: 'line create', data: newLine,organization:organization }
|
||||
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
|
||||
return { success: false, message: 'Error create line', error }
|
||||
return { success: false, message: 'Error create line', error,organization:organization }
|
||||
|
||||
}
|
||||
}
|
||||
export const updateLineItems = async (data: any)=>{
|
||||
const {organization,uuid,position,}=data
|
||||
try {
|
||||
const {organization,uuid,position,}=data
|
||||
// const findLine = await lineModel(organization).find({ 'line.uuid': uuid });
|
||||
// Update the position of the line matching the uuid
|
||||
const updateResult = await lineModel(organization).updateMany(
|
||||
@@ -29,13 +29,13 @@ export const updateLineItems = async (data: any)=>{
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error('Error creating Lines:', error);
|
||||
return { success: false, message: 'Error updating line', error }
|
||||
return { success: false, message: 'Error updating line', error,organization:organization }
|
||||
}
|
||||
}
|
||||
|
||||
export const deleteLineItems = async (data: any)=>{
|
||||
const {organization,line}=data
|
||||
try {
|
||||
const {organization,line}=data
|
||||
|
||||
const inputUuids = line.map((item: any) => item.uuid);
|
||||
|
||||
@@ -54,12 +54,12 @@ export const updateLineItems = async (data: any)=>{
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error delete Lines:', error);
|
||||
return { success: false, message: 'Failed to delete line', error }
|
||||
return { success: false, message: 'Failed to delete line', error ,organization:organization}
|
||||
}
|
||||
}
|
||||
export const deleteLayer = async (data: any)=>{
|
||||
const {organization,layer}=data
|
||||
try {
|
||||
const {organization,layer}=data
|
||||
|
||||
const findValue = await lineModel(organization).find({ layer: layer });
|
||||
|
||||
@@ -77,12 +77,12 @@ export const updateLineItems = async (data: any)=>{
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error delete layer:', error);
|
||||
return { success: false, message: 'Failed to delete layer', error }
|
||||
return { success: false, message: 'Failed to delete layer', error ,organization:organization}
|
||||
}
|
||||
}
|
||||
export const deleteLinPoiteItems = async (data: any)=>{
|
||||
const {organization,uuid}=data
|
||||
try {
|
||||
const {organization,uuid}=data
|
||||
|
||||
|
||||
const findValue = await lineModel(organization).deleteMany({ 'line.uuid': uuid })
|
||||
@@ -95,6 +95,6 @@ export const updateLineItems = async (data: any)=>{
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error delete Lines:', error);
|
||||
return { success: false, message: 'Failed to delete point', error }
|
||||
return { success: false, message: 'Failed to delete point', error ,organization:organization}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import zoneModel from "../../../shared/model/lines/zone-Model.ts";
|
||||
|
||||
import zoneModel from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||
export const setZone = async (data: any) => {
|
||||
const { organization, userId, zoneData } = data
|
||||
try {
|
||||
const { organization, userId, zoneData } = data
|
||||
console.log('data: ', data);
|
||||
const zoneId = zoneData.zoneId
|
||||
const points = zoneData.points
|
||||
const zoneName = zoneData.zoneName
|
||||
@@ -18,7 +16,7 @@ export const setZone = async (data: any) => {
|
||||
return { success: true, message: 'zone updated', data: updateZone, organization: organization }
|
||||
} else {
|
||||
const zoneCreate = await zoneModel(organization).create({
|
||||
zoneId, createBy: userId, zoneName: zoneName, points, layer, viewPortCenter, viewPortposition
|
||||
zoneId, createdBy: userId, zoneName: zoneName, points, layer, viewPortCenter, viewPortposition
|
||||
})
|
||||
const createdZone = await zoneModel(organization)
|
||||
.findById(zoneCreate._id)
|
||||
@@ -28,18 +26,18 @@ export const setZone = async (data: any) => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('error: ', error);
|
||||
return { success: false, message: 'Zone not found', error }
|
||||
return { success: false, message: 'Zone not found', error , organization: organization}
|
||||
}
|
||||
}
|
||||
|
||||
export const deleteZone = async (data: any) => {
|
||||
const { organization, userId, zoneId } = data
|
||||
try {
|
||||
const { organization, userId, zoneId } = data
|
||||
|
||||
const findZoneId = await zoneModel(organization).findOne({ zoneId: zoneId })
|
||||
if (findZoneId) {
|
||||
const deleteZone = await zoneModel(organization).findOneAndDelete(
|
||||
{ zoneId: zoneId, createBy: userId }
|
||||
{ zoneId: zoneId, createdBy: userId }
|
||||
).select("-_id -__v")
|
||||
return { success: true, message: 'zone deleted', data: deleteZone, organization: organization }
|
||||
} else {
|
||||
@@ -48,6 +46,6 @@ export const deleteZone = async (data: any) => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('error: ', error);
|
||||
return { success: false, message: 'Zone not found', error }
|
||||
return { success: false, message: 'Zone not found', error, organization: organization }
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ import cameraModel from "../../../shared/model/camera/camera-Model.ts"
|
||||
import userModel from "../../../shared/model/user-Model.ts"
|
||||
|
||||
export const activeUsers = async (data: any) => {
|
||||
const {organization}=data
|
||||
// console.log('data: ', data);
|
||||
try {
|
||||
if (data && data.email) {
|
||||
|
||||
@@ -42,23 +44,25 @@ export const activeUsers = async (data: any) => {
|
||||
// Handle the error or return a default value
|
||||
// Example: Return an error response if the email is invalid
|
||||
|
||||
return { success: false, message: 'Email is missing or invalid', }
|
||||
return { success: false, message: 'Email is missing or invalid', organization:organization }
|
||||
// return res.status(400).send({ message: 'Email is missing or invalid' });
|
||||
}
|
||||
|
||||
|
||||
// // return [];
|
||||
} catch (error) {
|
||||
} catch (error:any) {
|
||||
return { success: false, message: error?.message || "Error occurred while activeUser", error, organization: organization }
|
||||
|
||||
return { success: false, message:error}
|
||||
// return { success: false, message:error}
|
||||
}
|
||||
}
|
||||
|
||||
export const activeUserOffline = async (data: any) => {
|
||||
try {
|
||||
|
||||
const email = data.email
|
||||
const organization = email.split("@")[1].split(".")[0]
|
||||
|
||||
const email = data.email
|
||||
const organization = email.split("@")[1].split(".")[0]
|
||||
try {
|
||||
|
||||
const findUsers = await userModel(organization).findOne({email})
|
||||
// console.log('findUsers: ', findUsers);
|
||||
@@ -90,8 +94,44 @@ export const activeUserOffline = async (data: any) => {
|
||||
}
|
||||
}
|
||||
// // return [];
|
||||
} catch (error) {
|
||||
} catch (error:any) {
|
||||
return { success: false, message: error?.message || "Error occurred while activeUser", error, organization: organization }
|
||||
|
||||
return { success: false, message: error}
|
||||
// return { success: false, message: error}
|
||||
}
|
||||
}
|
||||
type OnlineUsersMap = Map<string, Set<string>>;
|
||||
|
||||
// export const addUserToOnlineList = async (
|
||||
// organization: string,
|
||||
// email: string,
|
||||
// onlineUsers: OnlineUsersMap,
|
||||
// socket: any,
|
||||
// namespace: string
|
||||
// ) => {
|
||||
// if (!organization || !email) return;
|
||||
// console.log('organization: ', organization);
|
||||
|
||||
// // Ensure the organization entry exists
|
||||
// if (!onlineUsers.has(organization)) {
|
||||
// onlineUsers.set(organization, new Set());
|
||||
// }
|
||||
// const findUser = await userModel(organization).findOne({email})
|
||||
// if (!findUser) {
|
||||
// return { success: false, message: "User not found", organization };
|
||||
// }
|
||||
// const userId = findUser._id;
|
||||
// console.log(`🔍 Found user with ID: ${userId}`);
|
||||
// // Add user to the online set
|
||||
// onlineUsers.get(organization)!.add(userId);
|
||||
|
||||
// console.log(`✅ User ${userId} is online (Org: ${organization})`);
|
||||
|
||||
// // Emit updated online users list
|
||||
// socket.emit("users:online", {
|
||||
// organization,
|
||||
// users: [...onlineUsers.get(organization)!],
|
||||
// });
|
||||
// };
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import floatWidgetModel from "../../../shared/model/vizualization/3dwidget.ts";
|
||||
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||
|
||||
export const addfloat = async (data: any) => {
|
||||
const { organization, widget, zoneId } = data;
|
||||
console.log('data: ', data);
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone)
|
||||
return { success: false, message: "Zone not found for the zoneId", organization: organization }
|
||||
|
||||
const existingFloatWidget = await floatWidgetModel(organization).findOne({
|
||||
floatWidgetID: widget.id,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existingFloatWidget) {
|
||||
const updateFloatWidget = await floatWidgetModel(organization).findOneAndUpdate(
|
||||
{
|
||||
floatWidgetID: widget.id,
|
||||
isArchive: false,
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
// Data: {
|
||||
// // measurements: widget.Data.measurements || {},
|
||||
// duration: widget.Data.duration || "1h",
|
||||
// },
|
||||
position: widget.position,
|
||||
},
|
||||
},
|
||||
{
|
||||
upsert: true,
|
||||
new: true,
|
||||
}
|
||||
);
|
||||
return { success: true, message: "Widget updated successfully", data: updateFloatWidget, organization: organization }
|
||||
}
|
||||
|
||||
const newFloadWidget = await floatWidgetModel(organization).create({
|
||||
className: widget.className,
|
||||
header: widget.header,
|
||||
floatWidgetID: widget.id,
|
||||
position: widget.position,
|
||||
per: widget.per,
|
||||
value: widget.value,
|
||||
zoneId: zoneId,
|
||||
});
|
||||
if (newFloadWidget) {
|
||||
return { success: true, message: "FloatWidget created successfully", data: newFloadWidget, organization: organization }
|
||||
}
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error?.message || "Error occurred while float", error, organization: organization }
|
||||
}
|
||||
|
||||
}
|
||||
26
src/socket-server/services/visualization/templateServices.ts
Normal file
26
src/socket-server/services/visualization/templateServices.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import templateModel from "../../../shared/model/vizualization/templatemodel.ts";
|
||||
export const addTemplate = async (data: any) => {
|
||||
const { organization, templateID, name, panelOrder, widgets, snapshot } =data;
|
||||
console.log('data: ', data);
|
||||
try {
|
||||
|
||||
const existingTemplate = await templateModel(organization).findOne({
|
||||
templateID: templateID,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existingTemplate)
|
||||
return { success: false, message: "TemplateID alreay exists", organization: organization }
|
||||
const newTemplate = await templateModel(organization).create({
|
||||
templateID,
|
||||
name,
|
||||
panelOrder,
|
||||
widgets,
|
||||
snapshot,
|
||||
});
|
||||
if (newTemplate)
|
||||
return { success: false, message: "Template saved successfully", data: newTemplate, organization: organization }
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error?.message || "Error occurred while template", error, organization: organization }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,8 +2,8 @@ export const EVENTS = {
|
||||
connection: "connection",
|
||||
disconnect:"disconnect",
|
||||
//userActiveStatus
|
||||
userConnect:"userConnectRespones",
|
||||
userDisConnect:"userDisConnectRespones",
|
||||
userConnect:"userConnectResponse",
|
||||
userDisConnect:"userDisConnectResponse",
|
||||
// Room management events
|
||||
joinRoom: 'joinRoom',
|
||||
createroom: "createRoom", // When a client joins a room
|
||||
@@ -59,4 +59,22 @@ export const EVENTS = {
|
||||
widgetUpdateRespones:"viz-widget:response:updates",
|
||||
deleteWidget:"v2:viz-widget:delete",
|
||||
widgetDeleteRespones:"viz-widget:response:delete",
|
||||
|
||||
//float
|
||||
addFloat: "v2:viz-float:add",
|
||||
floatUpdateRespones: "viz-float:response:updates",
|
||||
deleteFloat: "v2:viz-float:delete",
|
||||
floatDeleteRespones: "viz-float:response:delete",
|
||||
|
||||
//template
|
||||
addTemplate:"v2:viz-template:add",
|
||||
templateUpdateRespones:"viz-template:response:updates",
|
||||
|
||||
//model-asset
|
||||
setAssetModel: "v2:model-asset:add",
|
||||
assetUpdateRespones: "model-asset:response:updates",
|
||||
deleteAssetModel:"v2:model-asset:delete",
|
||||
assetDeleteRespones: "model-asset:response:updates",
|
||||
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user