110 lines
3.2 KiB
TypeScript
110 lines
3.2 KiB
TypeScript
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;
|
|
try {
|
|
if (data && data.email) {
|
|
const email = data.email;
|
|
const organization = email.split("@")[1].split(".")[0];
|
|
|
|
const findUser = await userModel(organization).findOne({ email });
|
|
|
|
if (findUser) {
|
|
const updateActiveStatus = await userModel(
|
|
organization
|
|
).findOneAndUpdate(
|
|
{ email: findUser.email },
|
|
{ activeStatus: "online" },
|
|
{ new: true }
|
|
);
|
|
|
|
if (updateActiveStatus) {
|
|
const cameraDatas = await cameraModel(organization)
|
|
.findOne({ userId: updateActiveStatus._id })
|
|
.select("position target rotation -_id");
|
|
|
|
if (cameraDatas) {
|
|
const result = {
|
|
position: cameraDatas.position,
|
|
target: cameraDatas.target,
|
|
rotation: cameraDatas.rotation,
|
|
userData: {
|
|
_id: updateActiveStatus._id,
|
|
userName: updateActiveStatus.userName,
|
|
email: updateActiveStatus.email,
|
|
},
|
|
};
|
|
|
|
return {
|
|
success: true,
|
|
message: "user connect ",
|
|
data: result,
|
|
organization: organization,
|
|
};
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
return {
|
|
success: false,
|
|
message: "Email is missing or invalid",
|
|
organization: organization,
|
|
};
|
|
}
|
|
} catch (error: any) {
|
|
return {
|
|
success: false,
|
|
message: error?.message || "Error occurred while activeUser",
|
|
error,
|
|
organization: organization,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const activeUserOffline = async (data: any) => {
|
|
const email = data.email;
|
|
const organization = email.split("@")[1].split(".")[0];
|
|
try {
|
|
const findUsers = await userModel(organization).findOne({ email });
|
|
if (findUsers) {
|
|
const updateActiveStatus = await userModel(organization).findOneAndUpdate(
|
|
{ email: email },
|
|
{ activeStatus: "offline" },
|
|
{ new: true }
|
|
);
|
|
if (updateActiveStatus) {
|
|
const cameraDatas = await cameraModel(organization)
|
|
.findOne({ userId: updateActiveStatus._id })
|
|
.select("position target rotation -_id");
|
|
if (cameraDatas) {
|
|
const result = {
|
|
position: cameraDatas.position,
|
|
target: cameraDatas.target,
|
|
rotation: cameraDatas.rotation,
|
|
userData: {
|
|
_id: updateActiveStatus._id,
|
|
userName: updateActiveStatus.userName,
|
|
email: updateActiveStatus.email,
|
|
},
|
|
};
|
|
|
|
return {
|
|
success: true,
|
|
message: "user disconnect",
|
|
data: result,
|
|
organization: organization,
|
|
};
|
|
}
|
|
}
|
|
}
|
|
} catch (error: any) {
|
|
return {
|
|
success: false,
|
|
message: error?.message || "Error occurred while activeUser",
|
|
error,
|
|
organization: organization,
|
|
};
|
|
}
|
|
};
|