Initial
This commit is contained in:
68
src/api-server/controller/assets/flooritem-Controller.ts
Normal file
68
src/api-server/controller/assets/flooritem-Controller.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { Request, Response } from "express";
|
||||
import floorItemsModel from "../../../shared/model/assets/flooritems-Model";
|
||||
|
||||
|
||||
export class floorItems {
|
||||
static async setFloorItems(req: Request, res: Response) {
|
||||
try {
|
||||
const { modeluuid, modelname, position, modelfileID,rotation,isLocked,isVisible,organization } = req.body
|
||||
|
||||
|
||||
const findvalue = await floorItemsModel(organization).findOne({ modeluuid: modeluuid,modelname:modelname })
|
||||
|
||||
if (findvalue) {
|
||||
|
||||
const updatevalue = await floorItemsModel(organization).findOneAndUpdate(
|
||||
{ modeluuid: modeluuid,modelname:modelname }, { position: position, rotation: rotation,isVisible:isVisible,isLocked:isLocked }, { new: true });
|
||||
res.status(201).json(updatevalue);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
const newValue = await floorItemsModel(organization).create({ modeluuid, modelfileID,modelname, position, rotation,isLocked,isVisible, });
|
||||
|
||||
|
||||
res.status(201).json(newValue);
|
||||
|
||||
}
|
||||
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error('Error creating flooritems:', error);
|
||||
res.status(500).json({ message: "Failed to create flooritems" });
|
||||
}
|
||||
}
|
||||
static async getFloorItems(req: Request, res: Response) {
|
||||
try {
|
||||
const { organization } = req.params;
|
||||
// console.log('req.params: ', req.params);
|
||||
|
||||
const findValue = await floorItemsModel(organization).find()
|
||||
if (!findValue) {
|
||||
res.status(200).json("floorItems not found");
|
||||
} else {
|
||||
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error get flooritems:', error);
|
||||
res.status(500).json({ error: "Failed to get flooritems" });
|
||||
}
|
||||
}
|
||||
static async deleteFloorItems(req: Request, res: Response) {
|
||||
try {
|
||||
const { modeluuid,modelname,organization } = req.body;
|
||||
|
||||
const findValue = await floorItemsModel(organization).findOneAndDelete({modeluuid:modeluuid,modelname:modelname})
|
||||
if (!findValue) {
|
||||
res.status(200).json("user not found");
|
||||
} else {
|
||||
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error get flooritems:', error);
|
||||
res.status(500).json({ error: "Failed to get flooritems" });
|
||||
}
|
||||
}
|
||||
}
|
||||
80
src/api-server/controller/assets/wallitem-Controller.ts
Normal file
80
src/api-server/controller/assets/wallitem-Controller.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { Request, Response } from "express";
|
||||
import wallItenmModel from "../../../shared/model/assets/wallitems-Model";
|
||||
|
||||
|
||||
export class wallItems {
|
||||
static async setWallItems(req: Request, res: Response) {
|
||||
try {
|
||||
const { modeluuid, modelname, position, type, csgposition,csgscale,quaternion,scale,organization } = req.body
|
||||
|
||||
|
||||
const findvalue = await wallItenmModel(organization).findOne({ modeluuid: modeluuid})
|
||||
|
||||
if (findvalue) {
|
||||
const updatevalue = await wallItenmModel(organization).findOneAndUpdate(
|
||||
{ modeluuid: modeluuid },
|
||||
{
|
||||
modelname,
|
||||
position,
|
||||
type,
|
||||
csgposition,
|
||||
csgscale,
|
||||
quaternion,
|
||||
scale,
|
||||
},
|
||||
{ new: true } // Return the updated document
|
||||
);
|
||||
res.status(201).json(updatevalue);
|
||||
|
||||
|
||||
} else {
|
||||
const newValue = await wallItenmModel(organization).create({ modeluuid,modelname, position, type, csgposition,csgscale,quaternion,scale });
|
||||
|
||||
|
||||
res.status(201).json(newValue);
|
||||
|
||||
}
|
||||
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error('Error creating wallitems:', error);
|
||||
res.status(500).json({ message: "Failed to create wallitems" });
|
||||
}
|
||||
}
|
||||
static async getWallItems(req: Request, res: Response) {
|
||||
try {
|
||||
const { organization } = req.params;
|
||||
|
||||
|
||||
const findValue = await wallItenmModel
|
||||
(organization).find()
|
||||
if (!findValue) {
|
||||
res.status(200).json("wallitems not found");
|
||||
} else {
|
||||
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error get wallitems:', error);
|
||||
res.status(500).json({ error: "Failed to get wallitems" });
|
||||
}
|
||||
}
|
||||
static async deleteWallItems(req: Request, res: Response) {
|
||||
try {
|
||||
const { modeluuid,modelname,organization } = req.body;
|
||||
|
||||
|
||||
const findValue = await wallItenmModel
|
||||
(organization).findOneAndDelete({modeluuid:modeluuid,modelname:modelname})
|
||||
if (!findValue) {
|
||||
res.status(200).json("user not found");
|
||||
} else {
|
||||
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error get wallitems:', error);
|
||||
res.status(500).json({ error: "Failed to get wallitems" });
|
||||
}
|
||||
}
|
||||
}
|
||||
89
src/api-server/controller/camera/camera-Controlle.ts
Normal file
89
src/api-server/controller/camera/camera-Controlle.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import { Request, Response } from "express";
|
||||
import cameraModel from "../../../shared/model/camera/camera-Model";
|
||||
import userModel from "../../../shared/model/user-Model";
|
||||
|
||||
export class camera {
|
||||
static async createCamera(req: Request, res: Response) {
|
||||
try {
|
||||
const { userId, position, target, rotation,organization } = req.body
|
||||
|
||||
|
||||
const findCamera = await cameraModel(organization).findOne({ userId: userId })
|
||||
|
||||
if (findCamera) {
|
||||
const updateCamera = await cameraModel(organization).findOneAndUpdate(
|
||||
{ userId: userId }, { position: position, target: target,rotation:rotation }, { new: true });
|
||||
res.status(201).json(updateCamera);
|
||||
|
||||
} else {
|
||||
const newCamera = await cameraModel(organization).create({ userId, position, target,rotation });
|
||||
|
||||
res.status(201).json(newCamera);
|
||||
|
||||
}
|
||||
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error('Error creating camera:', error);
|
||||
res.status(500).json({message:"Failed to create camera"});
|
||||
}
|
||||
}
|
||||
static async getCamera(req: Request, res: Response) {
|
||||
try {
|
||||
const { userId, organization } = req.params;
|
||||
|
||||
// if (!userId) {
|
||||
// res.status(201).json("User data is insufficient");
|
||||
// }
|
||||
const findCamera = await cameraModel(organization).findOne({ userId: userId })
|
||||
if (!findCamera) {
|
||||
res.status(200).json("user not found");
|
||||
} else {
|
||||
|
||||
res.status(201).json(findCamera);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error get camera:', error);
|
||||
res.status(500).json({ error: "Failed to get camera" });
|
||||
}
|
||||
}
|
||||
|
||||
static async onlineActiveDatas(req: Request, res: Response) {
|
||||
const {organization } = req.params;
|
||||
try {
|
||||
const findactiveUsers = await userModel(organization).find({activeStatus:"online"})
|
||||
|
||||
|
||||
const cameraDataPromises = findactiveUsers.map(async (activeUser) => {
|
||||
const cameraData = await cameraModel(organization)
|
||||
.findOne({ userId: activeUser._id })
|
||||
.select("position target rotation -_id");
|
||||
|
||||
if (cameraData) {
|
||||
return {
|
||||
position: cameraData.position,
|
||||
target: cameraData.target,
|
||||
rotation:cameraData.rotation,
|
||||
userData: {
|
||||
_id: activeUser._id,
|
||||
userName: activeUser.userName,
|
||||
email: activeUser.email,
|
||||
activeStatus: activeUser.activeStatus,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// Return null if no camera data is found for the user
|
||||
return null;
|
||||
});
|
||||
|
||||
const cameraDatas = (await Promise.all(cameraDataPromises)).filter((singledata:any) => singledata !== null);
|
||||
|
||||
|
||||
res.status(200).send({ cameraDatas });
|
||||
|
||||
} catch (error:any) {
|
||||
res.status(500).send(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import { Request, Response } from "express";
|
||||
import environmentModel from "../../../shared/model/environments/environments-Model";
|
||||
|
||||
export class environment {
|
||||
static async setEnvironment(req: Request, res: Response) {
|
||||
try {
|
||||
const { userId,roofVisibility,wallVisibility, organization } = req.body
|
||||
|
||||
|
||||
const findvalue = await environmentModel(organization).findOne({ userId: userId })
|
||||
|
||||
if (findvalue) {
|
||||
|
||||
const updatevalue = await environmentModel(organization).findOneAndUpdate(
|
||||
{ userId: userId }, { roofVisibility:roofVisibility,wallVisibility:wallVisibility }, { new: true });
|
||||
res.status(201).json(updatevalue);
|
||||
|
||||
|
||||
} else {
|
||||
const newValue = await environmentModel(organization).create({ userId, roofVisibility, wallVisibility });
|
||||
|
||||
|
||||
res.status(201).json(newValue);
|
||||
|
||||
}
|
||||
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error('Error creating environments:', error);
|
||||
res.status(500).json({message:"Failed to create environments"});
|
||||
}
|
||||
}
|
||||
static async getEnvironment(req: Request, res: Response) {
|
||||
try {
|
||||
const { userId, organization } = req.params;
|
||||
|
||||
|
||||
const findValue = await environmentModel(organization).findOne({ userId: userId })
|
||||
if (!findValue) {
|
||||
res.status(200).json("user not found");
|
||||
} else {
|
||||
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error get environments:', error);
|
||||
res.status(500).json({ error: "Failed to get environments" });
|
||||
}
|
||||
}
|
||||
}
|
||||
125
src/api-server/controller/lines/line-Controller.ts
Normal file
125
src/api-server/controller/lines/line-Controller.ts
Normal file
@@ -0,0 +1,125 @@
|
||||
import { Request, Response } from "express";
|
||||
import lineModel from "../../../shared/model/lines/lines-Model";
|
||||
|
||||
export class lines {
|
||||
static async setLines(req: Request, res: Response) {
|
||||
try {
|
||||
const {organization,layer,line,type}=req.body
|
||||
const newLine = await lineModel(organization).create({ layer,line,type });
|
||||
|
||||
|
||||
res.status(201).json(newLine);
|
||||
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error('Error creating Lines:', error);
|
||||
res.status(500).json({message:"Failed to create Lines"});
|
||||
}
|
||||
}
|
||||
static async updateLines(req: Request, res: Response) {
|
||||
try {
|
||||
const {organization,uuid,position,}=req.body
|
||||
// const findLine = await lineModel(organization).find({ 'line.uuid': uuid });
|
||||
// Update the position of the line matching the uuid
|
||||
const updateResult = await lineModel(organization).updateMany(
|
||||
{ 'line.uuid': uuid }, // Filter: Find the line with the given uuid
|
||||
{ $set: { 'line.$.position': position } } // Update the position and type
|
||||
);
|
||||
|
||||
res.status(201).json(updateResult);
|
||||
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error('Error creating Lines:', error);
|
||||
res.status(500).json({message:"Failed to create Lines"});
|
||||
}
|
||||
}
|
||||
static async getLines(req: Request, res: Response) {
|
||||
try {
|
||||
const { organization } = req.params;
|
||||
|
||||
|
||||
const findValue = await lineModel(organization).find()
|
||||
if (!findValue) {
|
||||
res.status(200).json("user not found");
|
||||
} else {
|
||||
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error get Lines:', error);
|
||||
res.status(500).json({ error: "Failed to get Lines" });
|
||||
}
|
||||
}
|
||||
static async deleteLineItems(req: Request, res: Response) {
|
||||
try {
|
||||
const {organization,layer,line,type}=req.body
|
||||
|
||||
const inputUuids = line.map((item: any) => item.uuid);
|
||||
|
||||
|
||||
// const findValue = await lineModel(organization).findOneAndDelete({
|
||||
|
||||
// line: { $elemMatch: { uuid: { $in: inputUuids } } },
|
||||
// });
|
||||
const findValue = await lineModel(organization).findOneAndDelete({
|
||||
"line.uuid": { $all: inputUuids } // Ensure all UUIDs are present in the `line` key
|
||||
});
|
||||
|
||||
if (!findValue) {
|
||||
res.status(200).json("data not found");
|
||||
} else {
|
||||
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error delete Lines:', error);
|
||||
res.status(500).json({ error: "Failed to delete Lines" });
|
||||
}
|
||||
}
|
||||
static async deleteLinPoiteItems(req: Request, res: Response) {
|
||||
try {
|
||||
const {organization,layer,uuid,type}=req.body
|
||||
|
||||
const findValue = await lineModel(organization).deleteMany({ 'line.uuid': uuid })
|
||||
|
||||
if (!findValue) {
|
||||
res.status(200).json("data not found");
|
||||
} else {
|
||||
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error delete Lines:', error);
|
||||
res.status(500).json({ error: "Failed to delete Lines" });
|
||||
}
|
||||
}
|
||||
|
||||
static async deleteLayer(req: Request, res: Response) {
|
||||
try {
|
||||
const {organization,layer}=req.body
|
||||
|
||||
// Fetch the documents with the specified layer value
|
||||
const findValue = await lineModel(organization).find({ layer: layer });
|
||||
|
||||
if (!findValue) {
|
||||
res.status(200).json("data not found");
|
||||
} else {
|
||||
await lineModel(organization).deleteMany({ layer: layer });
|
||||
// console.log(`Documents with layer ${layer} have been deleted.`);
|
||||
|
||||
// Update documents with layer greater than -1
|
||||
const updateResult = await lineModel(organization).updateMany(
|
||||
{ layer: { $gt:layer} },
|
||||
{ $inc: { layer: -1 } } // Example operation: decrementing layer by 1
|
||||
);
|
||||
|
||||
|
||||
res.status(201).json(updateResult);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error delete Lines:', error);
|
||||
res.status(500).json({ error: "Failed to delete Lines" });
|
||||
}
|
||||
}
|
||||
}
|
||||
43
src/api-server/controller/share/share-Controller.ts
Normal file
43
src/api-server/controller/share/share-Controller.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { Request, Response } from "express";
|
||||
import userModel from "../../../shared/model/user-Model";
|
||||
|
||||
|
||||
export class share {
|
||||
static async shareUser(req: Request, res: Response) {
|
||||
try {
|
||||
const { email, isShare, organization } = req.body
|
||||
|
||||
|
||||
const findValue = await userModel(organization).findOneAndUpdate({email:email},{isShare:isShare},{new:true})
|
||||
|
||||
res.status(201).json({message:"scene shared successfully",data:findValue});
|
||||
if (!findValue) {
|
||||
res.status(404).json({message:"Not found"})
|
||||
}
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error('Error creating Share:', error);
|
||||
res.status(500).json({message:"Failed to create Share"});
|
||||
}
|
||||
}
|
||||
|
||||
static async findshareUser(req: Request, res: Response) {
|
||||
try {
|
||||
const organization = req.query.organization as string;
|
||||
|
||||
|
||||
const findValue = await userModel(organization).find({}).select("isShare email userName -_id")
|
||||
// console.log('findValue: ', findValue);
|
||||
|
||||
res.status(201).json({message:"scene shared datas",data:findValue});
|
||||
if (!findValue) {
|
||||
res.status(404).json({message:"Not found"})
|
||||
}
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error('Error Share:', error);
|
||||
res.status(500).json({message:"Failed to Share datas "});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
103
src/api-server/controller/user-Controller.ts
Normal file
103
src/api-server/controller/user-Controller.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
import { Request, Response } from "express";
|
||||
import { Server } from 'http';
|
||||
import userModel from "../../shared/model/user-Model";
|
||||
import { isSharedArrayBuffer } from "util/types";
|
||||
const {hashGenerate,hashValidator} = require("../../shared/security/Hasing.ts")
|
||||
// import {hashGenerate} from '../security/Hasing'
|
||||
|
||||
let serverAlive = true;
|
||||
export class user {
|
||||
static async signup(req: Request, res: Response) {
|
||||
try {
|
||||
let role;
|
||||
const { userName, email, password,organization,profilePicture } = req.body;
|
||||
const caseChange = email.toLowerCase();
|
||||
const emailcheck = await userModel(organization).findOne({ email: caseChange });
|
||||
if (emailcheck!==null) {
|
||||
res.json({
|
||||
message:"User already exists"
|
||||
});
|
||||
} else {
|
||||
const hashpassword=await hashGenerate(password)
|
||||
const userCount = await userModel(organization).countDocuments({});
|
||||
role = userCount === 0 ? "Admin" : "User";
|
||||
const isShare = role === "Admin" ? "true" : "false";
|
||||
const newuser = await userModel(organization).create({
|
||||
userName: userName,
|
||||
email: caseChange,
|
||||
isShare:isShare,
|
||||
password: hashpassword,
|
||||
role:role,
|
||||
profilePicture:profilePicture
|
||||
});
|
||||
newuser.save();
|
||||
res.status(200).json({
|
||||
message:"New User created"
|
||||
});
|
||||
}
|
||||
} catch (error:any) {
|
||||
res.status(500).send(error);
|
||||
}
|
||||
}
|
||||
static async login(req: Request, res: Response) {
|
||||
try {
|
||||
let role;
|
||||
const { email, password,organization } = req.body;
|
||||
// console.log(' req.body: ', req.body);
|
||||
|
||||
const existingMail = await userModel(organization).findOne({
|
||||
email:email
|
||||
});
|
||||
|
||||
if (existingMail === null || !existingMail) {
|
||||
res.status(404).json({ message: "User Not Found!!! Kindly signup..." });
|
||||
} else {
|
||||
const hashedpassword= existingMail.password
|
||||
const checkpassword = await hashValidator(
|
||||
password,
|
||||
hashedpassword
|
||||
)
|
||||
// console.log('checkpassword: ', checkpassword);
|
||||
if (checkpassword) {
|
||||
// const tokenValidation=await tokenGenerator(existingMail.email)
|
||||
res.status(200).send({
|
||||
message: "login successfull",
|
||||
email: existingMail.email,
|
||||
name: existingMail.userName,
|
||||
userId: existingMail._id,
|
||||
isShare:existingMail.isShare,
|
||||
// token:tokenValidation
|
||||
|
||||
});
|
||||
} else {
|
||||
res.status(404).json({message:"email & password is invalid...Check the credentials"})
|
||||
}
|
||||
}
|
||||
} catch (error:any) {
|
||||
res.status(500).send(error);
|
||||
}
|
||||
}
|
||||
|
||||
// static async checkserverHealth(server:Server,organization: string){
|
||||
// try {
|
||||
// if (server.listening) {
|
||||
// console.log('Server is running');
|
||||
// serverAlive = true;
|
||||
// // Update all users to online status
|
||||
// } else {
|
||||
// // await userModel(organization).updateMany({}, { activeStatus: "offline" }); // Replace `activeStatus` with your actual field
|
||||
// throw new Error('Server is not running');
|
||||
// }
|
||||
// } catch (error:any) {
|
||||
// console.error('Server health check failed:', error.message);
|
||||
// serverAlive = false;
|
||||
|
||||
// // Update all users to offline status
|
||||
// // await userModel(organization).updateMany({}, { activeStatus: "offline" });
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
// export const startHealthCheck = (server: Server, organization: string) => {
|
||||
// setInterval(() => user.checkserverHealth(server, organization), 5000);
|
||||
// };
|
||||
Reference in New Issue
Block a user