56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
import environmentModel from "../../../shared/model/environments/environments-Model.ts";
|
|
|
|
export const setEnvironment = async (data: any) => {
|
|
const {
|
|
userId,
|
|
roofVisibility,
|
|
wallVisibility,
|
|
shadowVisibility,
|
|
organization,
|
|
} = data;
|
|
try {
|
|
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 }
|
|
);
|
|
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,
|
|
};
|
|
}
|
|
} catch (error) {
|
|
console.error("Error creating evironments:", error);
|
|
return {
|
|
success: false,
|
|
message: "Error creating or updating evironments",
|
|
error,
|
|
organization: organization,
|
|
};
|
|
}
|
|
};
|