33 lines
1.4 KiB
TypeScript
33 lines
1.4 KiB
TypeScript
import { Request, Response } from "express";
|
|
import { Socket } from "socket.io";
|
|
import cameraModel from "../../../shared/model/camera/camera-Model";
|
|
|
|
export const createCamera = async (data: any,) => {
|
|
const { userId, position, target, organization,rotation } = data
|
|
console.log('data: ', data);
|
|
try {
|
|
|
|
|
|
const findCamera = await cameraModel(organization).findOne({ userId: userId })
|
|
if (findCamera) {
|
|
const updateCamera = await cameraModel(organization).findOneAndUpdate(
|
|
{ userId: userId }, { position: position, target: target,rotation:rotation }, { new: true });
|
|
// io.emit('cameraUpdateResponse', { success: true, message: 'Camera updated', data: updateCamera });
|
|
return { success: true, message: 'Camera updated', data: updateCamera,organization:organization}
|
|
|
|
}
|
|
else {
|
|
const newCamera = await cameraModel(organization).create({ userId, position, target,rotation })
|
|
|
|
return { success: true, message: 'Camera created' ,data:newCamera,organization:organization}
|
|
|
|
}
|
|
|
|
// Send response with the created document
|
|
} catch (error) {
|
|
console.error('Error creating camera:', error);
|
|
return { success: false, message: 'Error creating or updating camera', error, organization:organization}
|
|
}
|
|
}
|
|
|