73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
import { Request, Response } from "express";
|
|
import environmentModel from "../../../shared/model/environments/environments-Model.ts";
|
|
|
|
export class Environment {
|
|
static async setEnvironment(req: Request, res: Response) {
|
|
try {
|
|
const {
|
|
userId,
|
|
roofVisibility,
|
|
wallVisibility,
|
|
shadowVisibility,
|
|
organization,
|
|
renderDistance,
|
|
limitDistance,
|
|
} = req.body;
|
|
|
|
const findvalue = await environmentModel(organization).findOne({
|
|
userId: userId,
|
|
});
|
|
|
|
if (findvalue) {
|
|
const updatevalue = await environmentModel(
|
|
organization
|
|
).findOneAndUpdate(
|
|
{ userId: userId },
|
|
{
|
|
roofVisibility: roofVisibility,
|
|
renderDistance: renderDistance,
|
|
wallVisibility: wallVisibility,
|
|
shadowVisibility: shadowVisibility,
|
|
limitDistance: limitDistance,
|
|
},
|
|
{ new: true }
|
|
);
|
|
res.status(201).json(updatevalue);
|
|
} else {
|
|
const newValue = await environmentModel(organization).create({
|
|
userId,
|
|
roofVisibility,
|
|
wallVisibility,
|
|
renderDistance,
|
|
shadowVisibility,
|
|
limitDistance,
|
|
});
|
|
|
|
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" });
|
|
}
|
|
}
|
|
}
|