assetmodel creation and adding for namespace socket
This commit is contained in:
@@ -33,8 +33,13 @@ export interface assetData extends Document {
|
|||||||
];
|
];
|
||||||
}[];
|
}[];
|
||||||
}[];
|
}[];
|
||||||
assetPosition: number[];
|
position: [];
|
||||||
assetRotation: number[];
|
// rotation: [];
|
||||||
|
rotation: {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
z: number;
|
||||||
|
};
|
||||||
speed: number | string;
|
speed: number | string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,16 +71,16 @@ const assetDataSchema: Schema = new Schema({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
assetPosition: { type: [Number] },
|
position: { type: Array},
|
||||||
assetRotation: { type: [Number] },
|
// rotation: { type: Array},
|
||||||
|
rotation: {
|
||||||
|
x: { type: Number },
|
||||||
|
y: { type: Number },
|
||||||
|
z: { type: Number },
|
||||||
|
},
|
||||||
speed: { type: Schema.Types.Mixed },
|
speed: { type: Schema.Types.Mixed },
|
||||||
isLocked: { type: Boolean },
|
isLocked: { type: Boolean },
|
||||||
isVisible: { type: Boolean },
|
isVisible: { type: Boolean },
|
||||||
// rotation: {
|
|
||||||
// x: { type: Number },
|
|
||||||
// y: { type: Number },
|
|
||||||
// z: { type: Number },
|
|
||||||
// },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// export default floorItemsModel;
|
// export default floorItemsModel;
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import actionModel from "../../../shared/model/simulation/actionmodel.ts";
|
|||||||
import triggerModel from "../../../shared/model/simulation/triggersmodel.ts";
|
import triggerModel from "../../../shared/model/simulation/triggersmodel.ts";
|
||||||
|
|
||||||
export const setAssetModel = async (data: any) => {
|
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);
|
console.log('data: ', data);
|
||||||
// const points=eventData.points
|
// const position=data.position
|
||||||
// const speed=eventData.speed
|
// const rotation=data.rotation
|
||||||
try {
|
try {
|
||||||
const findvalue = await assetModel(organization).findOne({
|
const findvalue = await assetModel(organization).findOne({
|
||||||
modeluuid: modeluuid,
|
modeluuid: modeluuid,
|
||||||
@@ -14,24 +14,26 @@ export const setAssetModel = async (data: any) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (findvalue) {
|
if (findvalue) {
|
||||||
|
console.log('findvalue: ', findvalue);
|
||||||
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
||||||
{ modeluuid: modeluuid, modelname: modelname },
|
{ modeluuid: modeluuid, modelname: modelname },
|
||||||
{
|
{
|
||||||
assetPosition: assetPosition,
|
position: position,
|
||||||
assetRotation: assetRotation,
|
rotation: rotation,
|
||||||
isVisible: isVisible,
|
isVisible: isVisible,
|
||||||
isLocked: isLocked,
|
isLocked: isLocked,
|
||||||
},
|
},
|
||||||
{ new: true }
|
{ 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 {
|
} else {
|
||||||
let assetData: any = {
|
let assetData: any = {
|
||||||
modeluuid,
|
modeluuid,
|
||||||
modelname,
|
modelname,
|
||||||
assetPosition,
|
position,
|
||||||
modelfileID,
|
modelfileID,
|
||||||
assetRotation,
|
rotation,
|
||||||
isLocked,
|
isLocked,
|
||||||
isVisible,
|
isVisible,
|
||||||
};
|
};
|
||||||
@@ -93,10 +95,33 @@ export const setAssetModel = async (data: any) => {
|
|||||||
const assetDoc = await assetModel(organization).create(assetData);
|
const assetDoc = await assetModel(organization).create(assetData);
|
||||||
await assetDoc.save();
|
await assetDoc.save();
|
||||||
// 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) {
|
} 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 }
|
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 }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@ import cameraModel from "../../../shared/model/camera/camera-Model.ts";
|
|||||||
|
|
||||||
export const createCamera = async (data: any,) => {
|
export const createCamera = async (data: any,) => {
|
||||||
const { userId, position, target, organization,rotation } = data
|
const { userId, position, target, organization,rotation } = data
|
||||||
console.log('data: ', data);
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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) => {
|
export const setZone = async (data: any) => {
|
||||||
try {
|
|
||||||
const { organization, userId, zoneData } = data
|
const { organization, userId, zoneData } = data
|
||||||
console.log('data: ', data);
|
try {
|
||||||
const zoneId = zoneData.zoneId
|
const zoneId = zoneData.zoneId
|
||||||
const points = zoneData.points
|
const points = zoneData.points
|
||||||
const zoneName = zoneData.zoneName
|
const zoneName = zoneData.zoneName
|
||||||
@@ -18,7 +16,7 @@ export const setZone = async (data: any) => {
|
|||||||
return { success: true, message: 'zone updated', data: updateZone, organization: organization }
|
return { success: true, message: 'zone updated', data: updateZone, organization: organization }
|
||||||
} else {
|
} else {
|
||||||
const zoneCreate = await zoneModel(organization).create({
|
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)
|
const createdZone = await zoneModel(organization)
|
||||||
.findById(zoneCreate._id)
|
.findById(zoneCreate._id)
|
||||||
@@ -28,18 +26,18 @@ export const setZone = async (data: any) => {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('error: ', 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) => {
|
export const deleteZone = async (data: any) => {
|
||||||
try {
|
|
||||||
const { organization, userId, zoneId } = data
|
const { organization, userId, zoneId } = data
|
||||||
|
try {
|
||||||
|
|
||||||
const findZoneId = await zoneModel(organization).findOne({ zoneId: zoneId })
|
const findZoneId = await zoneModel(organization).findOne({ zoneId: zoneId })
|
||||||
if (findZoneId) {
|
if (findZoneId) {
|
||||||
const deleteZone = await zoneModel(organization).findOneAndDelete(
|
const deleteZone = await zoneModel(organization).findOneAndDelete(
|
||||||
{ zoneId: zoneId, createBy: userId }
|
{ zoneId: zoneId, createdBy: userId }
|
||||||
).select("-_id -__v")
|
).select("-_id -__v")
|
||||||
return { success: true, message: 'zone deleted', data: deleteZone, organization: organization }
|
return { success: true, message: 'zone deleted', data: deleteZone, organization: organization }
|
||||||
} else {
|
} else {
|
||||||
@@ -48,6 +46,6 @@ export const deleteZone = async (data: any) => {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('error: ', error);
|
console.log('error: ', error);
|
||||||
return { success: false, message: 'Zone not found', error }
|
return { success: false, message: 'Zone not found', error, organization: organization }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ import userModel from "../../../shared/model/user-Model.ts"
|
|||||||
|
|
||||||
export const activeUsers = async (data: any) => {
|
export const activeUsers = async (data: any) => {
|
||||||
const {organization}=data
|
const {organization}=data
|
||||||
|
// console.log('data: ', data);
|
||||||
try {
|
try {
|
||||||
if (data && data.email) {
|
if (data && data.email) {
|
||||||
|
|
||||||
@@ -43,7 +44,7 @@ export const activeUsers = async (data: any) => {
|
|||||||
// Handle the error or return a default value
|
// Handle the error or return a default value
|
||||||
// Example: Return an error response if the email is invalid
|
// 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 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}
|
// 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)!],
|
||||||
|
// });
|
||||||
|
// };
|
||||||
|
|
||||||
|
|
||||||
@@ -2,8 +2,8 @@ export const EVENTS = {
|
|||||||
connection: "connection",
|
connection: "connection",
|
||||||
disconnect:"disconnect",
|
disconnect:"disconnect",
|
||||||
//userActiveStatus
|
//userActiveStatus
|
||||||
userConnect:"userConnectRespones",
|
userConnect:"userConnectResponse",
|
||||||
userDisConnect:"userDisConnectRespones",
|
userDisConnect:"userDisConnectResponse",
|
||||||
// Room management events
|
// Room management events
|
||||||
joinRoom: 'joinRoom',
|
joinRoom: 'joinRoom',
|
||||||
createroom: "createRoom", // When a client joins a room
|
createroom: "createRoom", // When a client joins a room
|
||||||
@@ -73,4 +73,8 @@ export const EVENTS = {
|
|||||||
//model-asset
|
//model-asset
|
||||||
setAssetModel: "v2:model-asset:add",
|
setAssetModel: "v2:model-asset:add",
|
||||||
assetUpdateRespones: "model-asset:response:updates",
|
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