Files
Dwinzo-Backend-V0.0/src/api-server/controller/environments/environments-controller.ts

51 lines
1.8 KiB
TypeScript

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" });
}
}
}