Initial
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { Request, Response } from "express";
|
||||
import environmentModel from "../../../shared/model/environments/environments-Model";
|
||||
|
||||
|
||||
|
||||
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 }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user