34 lines
1.4 KiB
TypeScript
34 lines
1.4 KiB
TypeScript
import { Request, Response } from "express";
|
|
import environmentModel from "../../../shared/model/environments/environments-Model.ts";
|
|
|
|
|
|
|
|
export const setEnvironment = async (data: any,) => {
|
|
try {
|
|
const { userId,roofVisibility,wallVisibility,shadowVisibility, organization } = data
|
|
|
|
const findvalue = await environmentModel(organization).findOne({ userId: userId })
|
|
if (findvalue) {
|
|
const updatevalue = await environmentModel(organization).findOneAndUpdate(
|
|
{ userId: userId }, { roofVisibility:roofVisibility,wallVisibility:wallVisibility,shadowVisibility:shadowVisibility }, { new: true });
|
|
// res.status(201).json(updatevalue);
|
|
return { success: true, message: 'evironments updated', data: updatevalue,organization:organization }
|
|
|
|
} else {
|
|
const newValue = await environmentModel(organization).create({ userId, roofVisibility, wallVisibility,shadowVisibility });
|
|
|
|
return { success: true, message: 'evironments created', data: newValue,organization:organization }
|
|
// res.status(201).json(newValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send response with the created document
|
|
} catch (error) {
|
|
console.error('Error creating evironments:', error);
|
|
return { success: false, message: 'Error creating or updating evironments', error }
|
|
}
|
|
}
|
|
|