assetmodel creation and adding for namespace socket

This commit is contained in:
2025-04-01 13:27:25 +05:30
parent d8d9a7c837
commit 5db6153bb9
13 changed files with 1241 additions and 828 deletions

View File

@@ -33,8 +33,13 @@ export interface assetData extends Document {
];
}[];
}[];
assetPosition: number[];
assetRotation: number[];
position: [];
// rotation: [];
rotation: {
x: number;
y: number;
z: number;
};
speed: number | string;
}
@@ -66,16 +71,16 @@ const assetDataSchema: Schema = new Schema({
},
},
],
assetPosition: { type: [Number] },
assetRotation: { type: [Number] },
position: { type: Array},
// rotation: { type: Array},
rotation: {
x: { type: Number },
y: { type: Number },
z: { type: Number },
},
speed: { type: Schema.Types.Mixed },
isLocked: { type: Boolean },
isVisible: { type: Boolean },
// rotation: {
// x: { type: Number },
// y: { type: Number },
// z: { type: Number },
// },
});
// export default floorItemsModel;

View File

@@ -3,10 +3,10 @@ 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,assetPosition, eventData,modelfileID,assetRotation,isLocked,isVisible,organization, }= data
const {modeluuid, modelname,position,rotation, eventData,modelfileID,isLocked,isVisible,organization, }= data
console.log('data: ', data);
// const points=eventData.points
// const speed=eventData.speed
// const position=data.position
// const rotation=data.rotation
try {
const findvalue = await assetModel(organization).findOne({
modeluuid: modeluuid,
@@ -14,24 +14,26 @@ export const setAssetModel = async (data: any) => {
});
if (findvalue) {
console.log('findvalue: ', findvalue);
const updatevalue = await assetModel(organization).findOneAndUpdate(
{ modeluuid: modeluuid, modelname: modelname },
{
assetPosition: assetPosition,
assetRotation: assetRotation,
position: position,
rotation: rotation,
isVisible: isVisible,
isLocked: isLocked,
},
{ new: true }
);
return { success: true, message: 'Model updated', data: updatevalue, organization: organization }
console.log('updatevalue: ', updatevalue);
return { success: true, message: 'Model updated successfully', data: updatevalue, organization: organization }
} else {
let assetData: any = {
modeluuid,
modelname,
assetPosition,
position,
modelfileID,
assetRotation,
rotation,
isLocked,
isVisible,
};
@@ -93,10 +95,33 @@ export const setAssetModel = async (data: any) => {
const assetDoc = await assetModel(organization).create(assetData);
await assetDoc.save();
// await assetDoc.save();
return { success: true, message:"Model stored successfully", data: assetDoc, organization: organization }
// 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);
// 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 }
}
}

View File

@@ -4,7 +4,6 @@ import cameraModel from "../../../shared/model/camera/camera-Model.ts";
export const createCamera = async (data: any,) => {
const { userId, position, target, organization,rotation } = data
console.log('data: ', data);
try {

View File

@@ -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 }
}
}

View File

@@ -3,6 +3,7 @@ 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) {
@@ -43,7 +44,7 @@ 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' });
}
@@ -99,3 +100,38 @@ export const activeUserOffline = async (data: any) => {
// 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)!],
// });
// };

View File

@@ -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
@@ -73,4 +73,8 @@ export const EVENTS = {
//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