clear the testing commits
This commit is contained in:
@@ -11,10 +11,8 @@ RUN npm install -g tsx --ignore-scripts
|
||||
|
||||
COPY package.json ./
|
||||
COPY package-lock.json ./
|
||||
RUN npm install --ignore-scripts
|
||||
|
||||
|
||||
RUN addgroup -S appgroup && \
|
||||
RUN npm install --ignore-scripts && \
|
||||
addgroup -S appgroup && \
|
||||
adduser -S appuser -G appgroup && \
|
||||
chown -R appuser:appgroup /usr/src/app
|
||||
|
||||
|
||||
@@ -537,6 +537,7 @@ router.get("/A_zone/:zoneId/:organization", ZoneService.ZoneData);
|
||||
* example: "Internal Server Error"
|
||||
*/
|
||||
router.patch("/zone/:zoneId", ZoneService.deleteAZone);
|
||||
router.get("/findZones/:organization", ZoneService.getZones);
|
||||
|
||||
router.patch("/zones/lockedPanels", ZoneService.lockedPanel);
|
||||
export default router;
|
||||
|
||||
@@ -20,6 +20,7 @@ export const SignupController = async (
|
||||
return;
|
||||
}
|
||||
const result = await AuthSignup(req.body);
|
||||
console.log('result: ', result);
|
||||
|
||||
switch (result.status) {
|
||||
case "User already exists":
|
||||
|
||||
@@ -72,8 +72,8 @@ export const DeleteZoneController = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, userId } = req.user || {};
|
||||
const { zoneId, projectId } = req.body;
|
||||
if (!organization || !userId || !zoneId || !projectId) {
|
||||
const { zoneUuid, projectId } = req.body;
|
||||
if (!organization || !userId || !zoneUuid || !projectId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
@@ -81,7 +81,7 @@ export const DeleteZoneController = async (
|
||||
}
|
||||
const result = await DelZone({
|
||||
organization,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
projectId,
|
||||
userId,
|
||||
});
|
||||
@@ -226,8 +226,8 @@ export const ZoneDataController = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, userId } = req.user || {};
|
||||
const { projectId, zoneId } = req.params;
|
||||
if (!organization || !userId || !projectId || !zoneId) {
|
||||
const { projectId, zoneUuid } = req.params;
|
||||
if (!organization || !userId || !projectId || !zoneUuid) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
@@ -237,7 +237,7 @@ export const ZoneDataController = async (
|
||||
organization,
|
||||
projectId,
|
||||
userId,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
});
|
||||
|
||||
switch (result.status) {
|
||||
@@ -277,8 +277,8 @@ export const SingleZonePanelController = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, userId } = req.user || {};
|
||||
const { projectId, zoneId } = req.params;
|
||||
if (!organization || !userId || !projectId || !zoneId) {
|
||||
const { projectId, zoneUuid } = req.params;
|
||||
if (!organization || !userId || !projectId || !zoneUuid) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
@@ -288,7 +288,7 @@ export const SingleZonePanelController = async (
|
||||
organization,
|
||||
projectId,
|
||||
userId,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
});
|
||||
|
||||
switch (result.status) {
|
||||
|
||||
@@ -14,12 +14,12 @@ export const FloatAddController = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
const { widget, zoneId, index, projectId } = req.body;
|
||||
const { widget, zoneUuid, index, projectId } = req.body;
|
||||
if (
|
||||
!userId ||
|
||||
!organization ||
|
||||
!widget ||
|
||||
!zoneId ||
|
||||
!zoneUuid ||
|
||||
!index ||
|
||||
!projectId
|
||||
) {
|
||||
@@ -31,7 +31,7 @@ export const FloatAddController = async (
|
||||
const result = await AddFloat({
|
||||
organization,
|
||||
widget,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
index,
|
||||
projectId,
|
||||
userId,
|
||||
@@ -48,9 +48,9 @@ export const FloatAddController = async (
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "Zone not found for the zoneId":
|
||||
case "Zone not found for the zoneUuid":
|
||||
res.status(404).json({
|
||||
message: "Zone not found for the zoneId",
|
||||
message: "Zone not found for the zoneUuid",
|
||||
});
|
||||
break;
|
||||
case "Widget updated successfully":
|
||||
@@ -87,8 +87,8 @@ export const DeleteFloatController = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
const { floatWidgetID, projectId, zoneId } = req.body;
|
||||
if (!userId || !organization || !floatWidgetID || !projectId || !zoneId) {
|
||||
const { floatWidgetID, projectId, zoneUuid } = req.body;
|
||||
if (!userId || !organization || !floatWidgetID || !projectId || !zoneUuid) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
@@ -97,7 +97,7 @@ export const DeleteFloatController = async (
|
||||
const result = await DelFloat({
|
||||
organization,
|
||||
floatWidgetID,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
projectId,
|
||||
userId,
|
||||
});
|
||||
@@ -112,9 +112,9 @@ export const DeleteFloatController = async (
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "Zone not found for the zoneId":
|
||||
case "Zone not found for the zoneUuid":
|
||||
res.status(404).json({
|
||||
message: "Zone not found for the zoneId",
|
||||
message: "Zone not found for the zoneUuid",
|
||||
});
|
||||
break;
|
||||
case "FloatWidget not found for the Id":
|
||||
@@ -151,13 +151,13 @@ export const DuplicateFloatController = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
const { widget, projectId, zoneId, index } = req.body;
|
||||
const { widget, projectId, zoneUuid, index } = req.body;
|
||||
if (
|
||||
!userId ||
|
||||
!organization ||
|
||||
!widget ||
|
||||
!projectId ||
|
||||
!zoneId ||
|
||||
!zoneUuid ||
|
||||
!index
|
||||
) {
|
||||
res.status(400).json({
|
||||
@@ -168,7 +168,7 @@ export const DuplicateFloatController = async (
|
||||
const result = await DuplicateFloat({
|
||||
organization,
|
||||
widget,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
index,
|
||||
projectId,
|
||||
userId,
|
||||
@@ -184,9 +184,9 @@ export const DuplicateFloatController = async (
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "Zone not found for the zoneId":
|
||||
case "Zone not found for the zoneUuid":
|
||||
res.status(404).json({
|
||||
message: "Zone not found for the zoneId",
|
||||
message: "Zone not found for the zoneUuid",
|
||||
});
|
||||
break;
|
||||
case "FloatWidget update unsuccessfull":
|
||||
@@ -228,8 +228,8 @@ export const GetFloatController = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
const { projectId, zoneId } = req.params;
|
||||
if (!userId || !organization || !projectId || !zoneId) {
|
||||
const { projectId, zoneUuid } = req.params;
|
||||
if (!userId || !organization || !projectId || !zoneUuid) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
@@ -237,7 +237,7 @@ export const GetFloatController = async (
|
||||
}
|
||||
const result = await GetFloatWidget({
|
||||
organization,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
projectId,
|
||||
userId,
|
||||
});
|
||||
|
||||
@@ -13,8 +13,8 @@ export const AddPanelController = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
const { panelOrder, zoneId, projectId } = req.body;
|
||||
if (!userId || !organization || !panelOrder || !zoneId || !projectId) {
|
||||
const { panelOrder, zoneUuid, projectId } = req.body;
|
||||
if (!userId || !organization || !panelOrder || !zoneUuid || !projectId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
@@ -23,7 +23,7 @@ export const AddPanelController = async (
|
||||
const result = await AddPanel({
|
||||
organization,
|
||||
panelOrder,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
projectId,
|
||||
userId,
|
||||
});
|
||||
@@ -74,8 +74,8 @@ export const DeletePanelController = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
const { panelName, projectId, zoneId } = req.body;
|
||||
if (!userId || !organization || !panelName || !projectId || !zoneId) {
|
||||
const { panelName, projectId, zoneUuid } = req.body;
|
||||
if (!userId || !organization || !panelName || !projectId || !zoneUuid) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
@@ -84,7 +84,7 @@ export const DeletePanelController = async (
|
||||
const result = await DelPanel({
|
||||
organization,
|
||||
panelName,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
projectId,
|
||||
userId,
|
||||
});
|
||||
@@ -133,8 +133,8 @@ export const ClearPanelController = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
const { panelName, projectId, zoneId } = req.body;
|
||||
if (!userId || !organization || !panelName || !projectId || !zoneId) {
|
||||
const { panelName, projectId, zoneUuid } = req.body;
|
||||
if (!userId || !organization || !panelName || !projectId || !zoneUuid) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
@@ -143,7 +143,7 @@ export const ClearPanelController = async (
|
||||
const result = await ClearPanel({
|
||||
organization,
|
||||
panelName,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
projectId,
|
||||
userId,
|
||||
});
|
||||
@@ -197,8 +197,8 @@ export const LockedPanelController = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
const { projectId, zoneId, lockedPanel } = req.body;
|
||||
if (!userId || !organization || !projectId || !zoneId || !lockedPanel) {
|
||||
const { projectId, zoneUuid, lockedPanel } = req.body;
|
||||
if (!userId || !organization || !projectId || !zoneUuid || !lockedPanel) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
@@ -206,7 +206,7 @@ export const LockedPanelController = async (
|
||||
}
|
||||
const result = await LockedPanel({
|
||||
organization,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
lockedPanel,
|
||||
userId,
|
||||
projectId,
|
||||
|
||||
@@ -72,8 +72,8 @@ export const AddTemToZoneController = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
const { templateID, projectId, zoneId } = req.body;
|
||||
if (!userId || !organization || !templateID || !projectId || !zoneId) {
|
||||
const { templateID, projectId, zoneUuid } = req.body;
|
||||
if (!userId || !organization || !templateID || !projectId || !zoneUuid) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
@@ -82,7 +82,7 @@ export const AddTemToZoneController = async (
|
||||
const result = await AddTemplateToZone({
|
||||
organization,
|
||||
templateID,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
projectId,
|
||||
userId,
|
||||
});
|
||||
|
||||
@@ -13,8 +13,8 @@ export const AddWidgetController = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
const { widget, projectId, zoneId } = req.body;
|
||||
if (!userId || !organization || !widget || !projectId || !zoneId) {
|
||||
const { widget, projectId, zoneUuid } = req.body;
|
||||
if (!userId || !organization || !widget || !projectId || !zoneUuid) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
@@ -25,7 +25,7 @@ export const AddWidgetController = async (
|
||||
widget,
|
||||
projectId,
|
||||
userId,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
});
|
||||
|
||||
switch (result.status) {
|
||||
@@ -39,7 +39,7 @@ export const AddWidgetController = async (
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "Zone not found for the zoneId":
|
||||
case "Zone not found for the zoneUuid":
|
||||
res.status(404).json({
|
||||
message: "Zone not found",
|
||||
});
|
||||
@@ -88,8 +88,8 @@ export const WidgetDeleteController = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
const { widgetID, projectId, zoneId } = req.body;
|
||||
if (!userId || !organization || !widgetID || !projectId || !zoneId) {
|
||||
const { widgetID, projectId, zoneUuid } = req.body;
|
||||
if (!userId || !organization || !widgetID || !projectId || !zoneUuid) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
@@ -98,7 +98,7 @@ export const WidgetDeleteController = async (
|
||||
const result = await WidgetDelete({
|
||||
organization,
|
||||
widgetID,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
projectId,
|
||||
userId,
|
||||
});
|
||||
@@ -113,9 +113,9 @@ export const WidgetDeleteController = async (
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "Zone not found for the zoneId":
|
||||
case "Zone not found for the zoneUuid":
|
||||
res.status(404).json({
|
||||
message: "Zone not found for the zoneId",
|
||||
message: "Zone not found for the zoneUuid",
|
||||
});
|
||||
break;
|
||||
case "Widget not found":
|
||||
@@ -147,14 +147,14 @@ export const WidgetUpdateController = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
const { values, projectId, zoneId, widgetID } = req.body;
|
||||
const { values, projectId, zoneUuid, widgetID } = req.body;
|
||||
if (
|
||||
!userId ||
|
||||
!organization ||
|
||||
!widgetID ||
|
||||
!values ||
|
||||
!projectId ||
|
||||
!zoneId
|
||||
!zoneUuid
|
||||
) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
@@ -164,7 +164,7 @@ export const WidgetUpdateController = async (
|
||||
const result = await UpdateWidget({
|
||||
organization,
|
||||
values,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
widgetID,
|
||||
projectId,
|
||||
userId,
|
||||
@@ -180,9 +180,9 @@ export const WidgetUpdateController = async (
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "Zone not found for the zoneId":
|
||||
case "Zone not found for the zoneUuid":
|
||||
res.status(404).json({
|
||||
message: "Zone not found for the zoneId",
|
||||
message: "Zone not found for the zoneUuid",
|
||||
});
|
||||
break;
|
||||
case "Data not found":
|
||||
@@ -214,12 +214,12 @@ export const GetWidgetController = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
const { projectId, zoneId, widgetID } = req.query as {
|
||||
const { projectId, zoneUuid, widgetID } = req.query as {
|
||||
projectId: string;
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
widgetID: string;
|
||||
};
|
||||
if (!userId || !organization || !widgetID || !projectId || !zoneId) {
|
||||
if (!userId || !organization || !widgetID || !projectId || !zoneUuid) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
@@ -227,7 +227,7 @@ export const GetWidgetController = async (
|
||||
}
|
||||
const result = await GetWidget({
|
||||
organization,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
widgetID,
|
||||
projectId,
|
||||
userId,
|
||||
@@ -243,9 +243,9 @@ export const GetWidgetController = async (
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "Zone not found for the zoneId":
|
||||
case "Zone not found for the zoneUuid":
|
||||
res.status(404).json({
|
||||
message: "Zone not found for the zoneId",
|
||||
message: "Zone not found for the zoneUuid",
|
||||
});
|
||||
break;
|
||||
case "Widget not found for the widgetID":
|
||||
|
||||
@@ -13,8 +13,8 @@ export const Add3dWidgetController = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
const { widget, projectId, zoneId } = req.body;
|
||||
if (!userId || !organization || !widget || !projectId || !zoneId) {
|
||||
const { widget, projectId, zoneUuid } = req.body;
|
||||
if (!userId || !organization || !widget || !projectId || !zoneUuid) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
@@ -24,7 +24,7 @@ export const Add3dWidgetController = async (
|
||||
organization,
|
||||
widget,
|
||||
userId,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
projectId,
|
||||
});
|
||||
|
||||
@@ -39,7 +39,7 @@ export const Add3dWidgetController = async (
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "Zone not found for the zoneId":
|
||||
case "Zone not found for the zoneUuid":
|
||||
res.status(200).json({
|
||||
message: "Zone not found",
|
||||
});
|
||||
@@ -83,7 +83,7 @@ export const Update3DwidgetController = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
const { id, position, rotation, projectId, zoneId } = req.body;
|
||||
const { id, position, rotation, projectId, zoneUuid } = req.body;
|
||||
if (
|
||||
!userId ||
|
||||
!organization ||
|
||||
@@ -91,7 +91,7 @@ export const Update3DwidgetController = async (
|
||||
!position ||
|
||||
!rotation ||
|
||||
!projectId ||
|
||||
!zoneId
|
||||
!zoneUuid
|
||||
) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
@@ -104,7 +104,7 @@ export const Update3DwidgetController = async (
|
||||
position,
|
||||
rotation,
|
||||
userId,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
projectId,
|
||||
});
|
||||
switch (result.status) {
|
||||
@@ -157,8 +157,8 @@ export const Delete3DwidgetController = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
const { id, projectId, zoneId } = req.body;
|
||||
if (!userId || !organization || !id || !projectId || !zoneId) {
|
||||
const { id, projectId, zoneUuid } = req.body;
|
||||
if (!userId || !organization || !id || !projectId || !zoneUuid) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
@@ -168,7 +168,7 @@ export const Delete3DwidgetController = async (
|
||||
organization,
|
||||
id,
|
||||
userId,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
projectId,
|
||||
});
|
||||
switch (result.status) {
|
||||
@@ -221,7 +221,7 @@ export const Get3DWidgetController = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
const { projectId, zoneId } = req.params;
|
||||
const { projectId, zoneUuid } = req.params;
|
||||
if (!userId || !organization || !projectId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
@@ -231,7 +231,7 @@ export const Get3DWidgetController = async (
|
||||
const result = await Get3Dwidget({
|
||||
organization,
|
||||
userId,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
projectId,
|
||||
});
|
||||
switch (result.status) {
|
||||
|
||||
@@ -29,12 +29,12 @@ v1Zone.get(
|
||||
);
|
||||
|
||||
v1Zone.get(
|
||||
"/zones/:projectId/:zoneId",
|
||||
"/zones/:projectId/:zoneUuid",
|
||||
tokenValidator,
|
||||
ZoneDataController
|
||||
);
|
||||
v1Zone.get(
|
||||
"/zones/panel/:projectId/:zoneId",
|
||||
"/zones/panel/:projectId/:zoneUuid",
|
||||
tokenValidator,
|
||||
SingleZonePanelController
|
||||
);
|
||||
|
||||
@@ -21,7 +21,7 @@ v1FloatWidget.patch(
|
||||
DeleteFloatController
|
||||
);
|
||||
v1FloatWidget.get(
|
||||
"/floatWidgets/:zoneId/:projectId",
|
||||
"/floatWidgets/:zoneUuid/:projectId",
|
||||
tokenValidator,
|
||||
GetFloatController
|
||||
);
|
||||
|
||||
@@ -23,7 +23,7 @@ v1Widget3d.patch(
|
||||
Update3DwidgetController
|
||||
);
|
||||
v1Widget3d.get(
|
||||
"/widget3d/data/:zoneId/:projectId",
|
||||
"/widget3d/data/:zoneUuid/:projectId",
|
||||
tokenValidator,
|
||||
Get3DWidgetController
|
||||
);
|
||||
|
||||
@@ -238,7 +238,25 @@ export class ZoneService {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
static async getZones(req: Request, res: Response) {
|
||||
try {
|
||||
const { organization } = req.params;
|
||||
|
||||
const findZoneId = await zoneSchema(organization)
|
||||
.find({isArchive:false})
|
||||
.select(
|
||||
"zoneId zoneName layer points viewPortCenter viewPortposition -_id"
|
||||
);
|
||||
|
||||
if (!findZoneId) {
|
||||
res.status(500).json({ message: "Invalid zone" });
|
||||
}
|
||||
res.status(201).json({ data: findZoneId, organization: organization });
|
||||
} catch (error) {
|
||||
console.log("error: ", error);
|
||||
res.status(500).json({ message: "Zone not found", error });
|
||||
}
|
||||
}
|
||||
static async lockedPanel(req: Request, res: Response): Promise<any> {
|
||||
console.log(req.body);
|
||||
const organization = req.body.organization;
|
||||
|
||||
@@ -3,7 +3,7 @@ import MainModel from "../../connect/mongoose.ts";
|
||||
import { User } from "./userAuthModel.ts";
|
||||
export interface UserData extends Document {
|
||||
userId: User["_id"];
|
||||
isShare: Boolean;
|
||||
isShare: boolean;
|
||||
activeStatus: string;
|
||||
notificationEnable: boolean;
|
||||
About: string;
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Project } from "../Project/project-model.ts";
|
||||
import { Version } from "../Version/versionModel.ts";
|
||||
export interface Zone extends Document {
|
||||
zoneName: string;
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
points: [];
|
||||
viewPortCenter: [];
|
||||
viewPortposition: [];
|
||||
@@ -20,7 +20,7 @@ export interface Zone extends Document {
|
||||
const zoneSchema: Schema = new Schema(
|
||||
{
|
||||
zoneName: { type: String },
|
||||
zoneId: { type: String },
|
||||
zoneUuid: { type: String },
|
||||
createdBy: { type: Schema.Types.ObjectId, ref: "User" },
|
||||
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Schema, Document } from "mongoose";
|
||||
import MainModel from "../../connect/mongoose.ts";
|
||||
import { Zone } from "../Builder/zoneModel.ts";
|
||||
export interface Widget3d extends Document {
|
||||
type: string;
|
||||
widgetID: string;
|
||||
@@ -8,7 +7,7 @@ export interface Widget3d extends Document {
|
||||
position: [];
|
||||
rotation: [];
|
||||
isArchive: boolean;
|
||||
zoneId: Zone["_id"];
|
||||
zoneUuid:string
|
||||
Data: {
|
||||
measurements: {};
|
||||
duration: string;
|
||||
@@ -21,7 +20,7 @@ const Widget3dSchema: Schema = new Schema(
|
||||
widgetName: { type: String, default: "Widget3D" },
|
||||
position: { type: Array },
|
||||
rotation: { type: Array },
|
||||
zoneId:{ type: Schema.Types.ObjectId, ref: "Zone" },
|
||||
zoneUuid:{ type: String },
|
||||
Data: {
|
||||
measurements: { type: Object, default: {} },
|
||||
duration: { type: String, default: "1h" },
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Schema, Document } from "mongoose";
|
||||
import MainModel from "../../connect/mongoose.ts";
|
||||
import { Zone } from "../Builder/zoneModel.ts";
|
||||
export interface FloatingWidget extends Document {
|
||||
className: string;
|
||||
iconName: string;
|
||||
@@ -10,7 +9,7 @@ export interface FloatingWidget extends Document {
|
||||
per: string;
|
||||
value: string;
|
||||
isArchive: boolean;
|
||||
zoneId: Zone["_id"];
|
||||
zoneUuid: string
|
||||
Data: {
|
||||
measurements: {};
|
||||
duration: string;
|
||||
@@ -25,7 +24,7 @@ const floatingWidgetSchema: Schema = new Schema(
|
||||
position: { type: Object },
|
||||
per: { type: String },
|
||||
value: { type: String },
|
||||
zoneId: { type: Schema.Types.ObjectId, ref: "Zone" },
|
||||
zoneUuid: { type: String },
|
||||
Data: {
|
||||
measurements: { type: Object, default: {} },
|
||||
duration: { type: String, default: "1h" },
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
import mongoose, { Schema, Document } from "mongoose";
|
||||
import MainModel from "../../connect/mongoose.ts";
|
||||
import { Zone } from "../Builder/zoneModel.ts";
|
||||
export interface Panel extends Document {
|
||||
zoneId: Zone["_id"];
|
||||
zoneUuid: string
|
||||
panelName: string;
|
||||
widgets: [mongoose.Types.ObjectId];
|
||||
isArchive: boolean;
|
||||
}
|
||||
const panelSchema: Schema = new Schema(
|
||||
{
|
||||
zoneId: { type: Schema.Types.ObjectId, ref: "Zone" },
|
||||
zoneUuid: { type: String },
|
||||
panelName: { type: String },
|
||||
widgets: [{ type: mongoose.Schema.Types.ObjectId, ref: "Widget" }],
|
||||
isArchive: { type: Boolean, default: false },
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import mongoose, { Schema, Document } from "mongoose";
|
||||
import MainModel from "../../connect/mongoose.ts";
|
||||
import { Zone } from "../Builder/zoneModel.ts";
|
||||
export interface Widget extends Document {
|
||||
widgetName: string;
|
||||
widgetside: string;
|
||||
@@ -17,7 +16,7 @@ export interface Widget extends Document {
|
||||
measurements: {};
|
||||
duration: string;
|
||||
};
|
||||
zoneId: Zone["_id"];
|
||||
zoneUuid: string
|
||||
}
|
||||
const widgetSchema: Schema = new Schema(
|
||||
{
|
||||
@@ -36,7 +35,7 @@ const widgetSchema: Schema = new Schema(
|
||||
fontWeight: { type: String },
|
||||
isArchive: { type: Boolean, default: false },
|
||||
panelID: { type: mongoose.Schema.Types.ObjectId, ref: "Panel" },
|
||||
zoneId: { type: Schema.Types.ObjectId, ref: "Zone" },
|
||||
zoneUuid: { type: String }
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
@@ -9,7 +9,7 @@ interface ISetZone {
|
||||
organization: string;
|
||||
projectId: string;
|
||||
zoneData: {
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
points: [];
|
||||
zoneName: string;
|
||||
layer: number;
|
||||
@@ -21,7 +21,7 @@ interface ISetZone {
|
||||
interface IZone {
|
||||
organization: string;
|
||||
projectId: string;
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
userId: string;
|
||||
}
|
||||
interface IVizZone {
|
||||
@@ -42,7 +42,7 @@ interface IGetZones {
|
||||
export const SetZone = async (data: ISetZone): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, projectId, zoneData, userId } = data;
|
||||
const zoneId = zoneData.zoneId;
|
||||
const zoneUuid = zoneData.zoneUuid;
|
||||
const points = zoneData.points;
|
||||
const zoneName = zoneData.zoneName;
|
||||
const layer = zoneData.layer;
|
||||
@@ -58,12 +58,12 @@ export const SetZone = async (data: ISetZone): Promise<IResult> => {
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const findZoneId = await zoneModel(organization).findOne({
|
||||
projectId: projectId,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
});
|
||||
if (findZoneId) {
|
||||
const updateZone = await zoneModel(organization)
|
||||
.findOneAndUpdate(
|
||||
{ zoneId: zoneId, projectId: projectId, isArchive: false },
|
||||
{ zoneUuid: zoneUuid, projectId: projectId, isArchive: false },
|
||||
{
|
||||
points: points,
|
||||
viewPortposition: viewPortposition,
|
||||
@@ -75,7 +75,7 @@ export const SetZone = async (data: ISetZone): Promise<IResult> => {
|
||||
return { status: "zone updated", data: updateZone };
|
||||
} else {
|
||||
const zoneCreate = await zoneModel(organization).create({
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
createdBy: userId,
|
||||
projectId,
|
||||
zoneName: zoneName,
|
||||
@@ -103,9 +103,9 @@ export const SetZone = async (data: ISetZone): Promise<IResult> => {
|
||||
};
|
||||
export const DelZone = async (data: IZone): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, userId, zoneId, projectId } = data;
|
||||
const { organization, userId, zoneUuid, projectId } = data;
|
||||
const findZoneId = await zoneModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
projectId: projectId,
|
||||
isArchive: false,
|
||||
});
|
||||
@@ -120,7 +120,7 @@ export const DelZone = async (data: IZone): Promise<IResult> => {
|
||||
if (findZoneId) {
|
||||
const deleteZone = await zoneModel(organization)
|
||||
.findOneAndUpdate({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
createdBy: userId,
|
||||
projectId: projectId,
|
||||
isArchive: false,
|
||||
@@ -128,7 +128,7 @@ export const DelZone = async (data: IZone): Promise<IResult> => {
|
||||
.select("-_id -__v");
|
||||
if (deleteZone) {
|
||||
const panels = await panelModel(organization).find({
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
@@ -142,21 +142,21 @@ export const DelZone = async (data: IZone): Promise<IResult> => {
|
||||
);
|
||||
|
||||
await panelModel(organization).updateMany(
|
||||
{ zoneId, isArchive: false },
|
||||
{ zoneUuid, isArchive: false },
|
||||
{ $set: { isArchive: true } }
|
||||
);
|
||||
|
||||
await Promise.all([
|
||||
widget3dModel(organization).updateMany(
|
||||
{ zoneId, isArchive: false },
|
||||
{ zoneUuid, isArchive: false },
|
||||
{ $set: { isArchive: true } }
|
||||
),
|
||||
templateModel(organization).updateMany(
|
||||
{ zoneId, isArchive: false },
|
||||
{ zoneUuid, isArchive: false },
|
||||
{ $set: { isArchive: true } }
|
||||
),
|
||||
floatWidgetModel(organization).updateMany(
|
||||
{ zoneId, isArchive: false },
|
||||
{ zoneUuid, isArchive: false },
|
||||
{ $set: { isArchive: true } }
|
||||
),
|
||||
]);
|
||||
@@ -191,7 +191,7 @@ export const GetZones = async (data: IGetZones): Promise<IResult> => {
|
||||
const findZoneId = await zoneModel(organization)
|
||||
.find({ projectId: projectId, isArchive: false })
|
||||
.select(
|
||||
"zoneId zoneName layer points viewPortCenter viewPortposition -_id"
|
||||
"zoneUuid zoneName layer points viewPortCenter viewPortposition -_id"
|
||||
);
|
||||
|
||||
if (!findZoneId) {
|
||||
@@ -212,7 +212,7 @@ export const GetZones = async (data: IGetZones): Promise<IResult> => {
|
||||
};
|
||||
export const ZoneData = async (data: IZone): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, userId, projectId, zoneId } = data;
|
||||
const { organization, userId, projectId, zoneUuid } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -222,7 +222,7 @@ export const ZoneData = async (data: IZone): Promise<IResult> => {
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const findZone = await zoneModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
projectId: projectId,
|
||||
isArchive: false,
|
||||
});
|
||||
@@ -248,7 +248,7 @@ export const ZoneData = async (data: IZone): Promise<IResult> => {
|
||||
};
|
||||
export const SingleZonePanelData = async (data: IZone): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, userId, projectId, zoneId } = data;
|
||||
const { organization, userId, projectId, zoneUuid } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -260,17 +260,17 @@ export const SingleZonePanelData = async (data: IZone): Promise<IResult> => {
|
||||
const existingZone = await zoneModel(organization)
|
||||
.findOne({
|
||||
projectId: projectId,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
})
|
||||
.select(
|
||||
"panelOrder zoneName zonePoints lockedPanel zoneId viewPortCenter viewPortposition points"
|
||||
"panelOrder zoneName zonePoints lockedPanel zoneUuid viewPortCenter viewPortposition points"
|
||||
);
|
||||
if (!existingZone) {
|
||||
return { status: "Zone not found for the UUID" };
|
||||
} else {
|
||||
const panelData = await panelModel(organization).find({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
});
|
||||
const zoneName = existingZone.zoneName as string;
|
||||
@@ -297,7 +297,7 @@ export const SingleZonePanelData = async (data: IZone): Promise<IResult> => {
|
||||
const objectData = {
|
||||
zoneName,
|
||||
viewPortposition: existingZone.viewPortposition,
|
||||
zoneId: existingZone.zoneId,
|
||||
zoneUuid: existingZone.zoneUuid,
|
||||
viewPortCenter: existingZone.viewPortCenter,
|
||||
activeSides: existingZone.panelOrder || [],
|
||||
panelOrder: existingZone.panelOrder || [],
|
||||
@@ -337,7 +337,7 @@ export const VizZoneDatas = async (data: IVizZone): Promise<IResult> => {
|
||||
isArchive: false,
|
||||
})
|
||||
.select(
|
||||
"panelOrder zoneName zonePoints lockedPanel zoneId viewPortCenter viewPortposition points"
|
||||
"panelOrder zoneName zonePoints lockedPanel zoneUuid viewPortCenter viewPortposition points"
|
||||
);
|
||||
if (!existingZones) {
|
||||
return { status: "Zone not found for the UUID" };
|
||||
@@ -345,7 +345,7 @@ export const VizZoneDatas = async (data: IVizZone): Promise<IResult> => {
|
||||
const response = await Promise.all(
|
||||
existingZones.map(async (zone) => {
|
||||
const panelData = await panelModel(organization).find({
|
||||
zoneId: zone._id,
|
||||
zoneUuid: zone._id,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
@@ -368,7 +368,7 @@ export const VizZoneDatas = async (data: IVizZone): Promise<IResult> => {
|
||||
|
||||
return {
|
||||
zoneName: zone.zoneName,
|
||||
zoneId: zone.zoneId,
|
||||
zoneUuid: zone.zoneUuid,
|
||||
viewPortposition: zone.viewPortposition,
|
||||
viewPortCenter: zone.viewPortCenter,
|
||||
activeSides: zone.panelOrder || [],
|
||||
|
||||
@@ -22,20 +22,20 @@ interface IAddFloatData {
|
||||
per: string;
|
||||
value: string;
|
||||
isArchive: boolean;
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
Data: {
|
||||
measurements: {};
|
||||
duration: string;
|
||||
};
|
||||
};
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
index: number;
|
||||
projectId: string;
|
||||
}
|
||||
interface IDelFloat {
|
||||
userId: string;
|
||||
organization: string;
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
floatWidgetID: string;
|
||||
projectId: string;
|
||||
}
|
||||
@@ -47,7 +47,7 @@ interface ISingleFloat {
|
||||
interface IGetZoneFloat {
|
||||
userId: string;
|
||||
organization: string;
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
projectId: string;
|
||||
}
|
||||
interface IDuplicateFloatData {
|
||||
@@ -63,19 +63,19 @@ interface IDuplicateFloatData {
|
||||
per: string;
|
||||
value: string;
|
||||
isArchive: boolean;
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
Data: {
|
||||
measurements: {};
|
||||
duration: string;
|
||||
};
|
||||
};
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
index: number;
|
||||
projectId: string;
|
||||
}
|
||||
export const AddFloat = async (data: IAddFloatData): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, widget, zoneId, index, projectId, userId } = data;
|
||||
const { organization, widget, zoneUuid, index, projectId, userId } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -85,16 +85,16 @@ export const AddFloat = async (data: IAddFloatData): Promise<IResult> => {
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingZone = await zoneModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
});
|
||||
if (!existingZone) return { status: "Zone not found for the zoneId" };
|
||||
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
||||
|
||||
const existingFloatWidget = await floatWidgetModel(organization).findOne({
|
||||
floatWidgetID: widget.id,
|
||||
isArchive: false,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
});
|
||||
if (existingFloatWidget) {
|
||||
const updateFloatWidget = await floatWidgetModel(
|
||||
@@ -122,7 +122,7 @@ export const AddFloat = async (data: IAddFloatData): Promise<IResult> => {
|
||||
const floatUpdateDatas = {
|
||||
position: updateFloatWidget.position,
|
||||
index: index,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
zoneName: existingZone.zoneName,
|
||||
};
|
||||
return { status: "Widget updated successfully", data: floatUpdateDatas };
|
||||
@@ -135,7 +135,7 @@ export const AddFloat = async (data: IAddFloatData): Promise<IResult> => {
|
||||
position: widget.position,
|
||||
per: widget.per,
|
||||
value: widget.value,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
});
|
||||
if (newFloadWidget) {
|
||||
const floatDatas = {
|
||||
@@ -147,7 +147,7 @@ export const AddFloat = async (data: IAddFloatData): Promise<IResult> => {
|
||||
className: newFloadWidget.className,
|
||||
id: newFloadWidget.floatWidgetID,
|
||||
},
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
zoneName: existingZone.zoneName,
|
||||
};
|
||||
return { status: "Success", data: floatDatas };
|
||||
@@ -169,7 +169,7 @@ export const AddFloat = async (data: IAddFloatData): Promise<IResult> => {
|
||||
|
||||
export const DelFloat = async (data: IDelFloat): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, floatWidgetID, zoneId, projectId, userId } = data;
|
||||
const { organization, floatWidgetID, zoneUuid, projectId, userId } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) { return { status: "User not found" } }
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -179,11 +179,11 @@ export const DelFloat = async (data: IDelFloat): Promise<IResult> => {
|
||||
);
|
||||
if (!LivingProject) { return { status: "Project not found" } }
|
||||
const existingZone = await zoneModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
});
|
||||
if (!existingZone) return { status: "Zone not found for the zoneId" };
|
||||
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
||||
|
||||
const findfloatWidget = await floatWidgetModel(organization).findOne({
|
||||
floatWidgetID: floatWidgetID,
|
||||
@@ -199,7 +199,7 @@ export const DelFloat = async (data: IDelFloat): Promise<IResult> => {
|
||||
if (widgetData) {
|
||||
const floatDeleteData = {
|
||||
floatWidgetID: findfloatWidget.floatWidgetID,
|
||||
zoneId: findfloatWidget.zoneId,
|
||||
zoneUuid: findfloatWidget.zoneUuid,
|
||||
zoneName: existingZone.zoneName,
|
||||
};
|
||||
return { status: "Success", data: floatDeleteData };
|
||||
@@ -222,7 +222,7 @@ export const DuplicateFloat = async (
|
||||
data: IDuplicateFloatData
|
||||
): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, widget, zoneId, index, projectId, userId } = data;
|
||||
const { organization, widget, zoneUuid, index, projectId, userId } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) {return { status: "User not found" }};
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -232,16 +232,16 @@ export const DuplicateFloat = async (
|
||||
);
|
||||
if (!LivingProject) {return { status: "Project not found" }};
|
||||
const existingZone = await zoneModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
});
|
||||
if (!existingZone) return { status: "Zone not found for the zoneId" };
|
||||
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
||||
|
||||
const existingFloatWidget = await floatWidgetModel(organization).findOne({
|
||||
floatWidgetID: widget.id,
|
||||
isArchive: false,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
});
|
||||
if (existingFloatWidget) {
|
||||
const updateFloatWidget = await floatWidgetModel(
|
||||
@@ -272,7 +272,7 @@ export const DuplicateFloat = async (
|
||||
const floatUpdateDatas = {
|
||||
position: updateFloatWidget.position,
|
||||
index: index,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
zoneName: existingZone.zoneName,
|
||||
};
|
||||
return {
|
||||
@@ -287,7 +287,7 @@ export const DuplicateFloat = async (
|
||||
position: widget.position,
|
||||
per: widget.per,
|
||||
value: widget.value,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
Data: {
|
||||
measurements: widget?.Data?.measurements,
|
||||
duration: widget?.Data?.duration,
|
||||
@@ -303,7 +303,7 @@ export const DuplicateFloat = async (
|
||||
className: newFloadWidget.className,
|
||||
id: newFloadWidget.floatWidgetID,
|
||||
},
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
zoneName: existingZone.zoneName,
|
||||
index: index,
|
||||
};
|
||||
@@ -330,7 +330,7 @@ export const DuplicateFloat = async (
|
||||
|
||||
export const GetFloatWidget = async (data: IGetZoneFloat): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, zoneId, projectId, userId } = data;
|
||||
const { organization, zoneUuid, projectId, userId } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) {return { status: "User not found" }}
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -340,17 +340,17 @@ export const GetFloatWidget = async (data: IGetZoneFloat): Promise<IResult> => {
|
||||
);
|
||||
if (!LivingProject) {return { status: "Project not found" }};
|
||||
const existingZone = await zoneModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
});
|
||||
if (!existingZone) return { status: "Zone not found" };
|
||||
const widgetData = await floatWidgetModel(organization)
|
||||
.find({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
})
|
||||
.select("-_id -zoneId -createdAt -updatedAt -__v");
|
||||
.select("-_id -zoneUuid -createdAt -updatedAt -__v");
|
||||
if (!widgetData || widgetData.length === 0) {
|
||||
return { status: "All Datas" };
|
||||
}
|
||||
@@ -394,7 +394,7 @@ export const SingleFloatWidget = async (
|
||||
floatWidgetID: floatWidgetID,
|
||||
isArchive: false,
|
||||
})
|
||||
.select("-_id -zoneId -createdAt -updatedAt -__v");
|
||||
.select("-_id -zoneUuid -createdAt -updatedAt -__v");
|
||||
if (!widgetData || widgetData.length === 0) {
|
||||
return { status: "Widget not found" };
|
||||
}
|
||||
|
||||
@@ -11,28 +11,28 @@ interface IResult {
|
||||
}
|
||||
interface IAddPanel {
|
||||
organization: string;
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
panelOrder: string[];
|
||||
userId: string;
|
||||
projectId: string;
|
||||
}
|
||||
interface IPanel {
|
||||
organization: string;
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
panelName: string;
|
||||
userId: string;
|
||||
projectId: string;
|
||||
}
|
||||
interface ILockedPanel {
|
||||
organization: string;
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
lockedPanel: string[];
|
||||
userId: string;
|
||||
projectId: string;
|
||||
}
|
||||
export const AddPanel = async (data: IAddPanel): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, zoneId, panelOrder, userId, projectId } = data;
|
||||
const { organization, zoneUuid, panelOrder, userId, projectId } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -42,18 +42,18 @@ export const AddPanel = async (data: IAddPanel): Promise<IResult> => {
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingZone = await zoneModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
});
|
||||
if (!existingZone) return { status: "Zone not found" };
|
||||
await zoneModel(organization).findOneAndUpdate(
|
||||
{ zoneId: zoneId, isArchive: false },
|
||||
{ zoneUuid: zoneUuid, isArchive: false },
|
||||
{ panelOrder: panelOrder },
|
||||
{ new: true }
|
||||
);
|
||||
const existingPanels = await panelModel(organization).find({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
@@ -68,7 +68,7 @@ export const AddPanel = async (data: IAddPanel): Promise<IResult> => {
|
||||
const createdPanels = [];
|
||||
for (const panelName of missingPanels) {
|
||||
const newPanel = await panelModel(organization).create({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
panelName: panelName,
|
||||
widgets: [],
|
||||
isArchive: false,
|
||||
@@ -82,7 +82,7 @@ export const AddPanel = async (data: IAddPanel): Promise<IResult> => {
|
||||
|
||||
const zoneAndPanelData = await getZoneAndPanelData(
|
||||
organization,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
projectId
|
||||
);
|
||||
if (!zoneAndPanelData) {
|
||||
@@ -103,7 +103,7 @@ export const AddPanel = async (data: IAddPanel): Promise<IResult> => {
|
||||
};
|
||||
export const DelPanel = async (data: IPanel): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, zoneId, panelName, userId, projectId } = data;
|
||||
const { organization, zoneUuid, panelName, userId, projectId } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -113,13 +113,13 @@ export const DelPanel = async (data: IPanel): Promise<IResult> => {
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingZone = await zoneModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
});
|
||||
if (!existingZone) return { status: "Zone not found" };
|
||||
const existingPanel = await panelModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
panelName: panelName,
|
||||
isArchive: false,
|
||||
});
|
||||
@@ -147,7 +147,7 @@ export const DelPanel = async (data: IPanel): Promise<IResult> => {
|
||||
}
|
||||
const zoneAndPanelData = await getZoneAndPanelData(
|
||||
organization,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
projectId
|
||||
);
|
||||
if (!zoneAndPanelData) {
|
||||
@@ -168,7 +168,7 @@ export const DelPanel = async (data: IPanel): Promise<IResult> => {
|
||||
};
|
||||
export const ClearPanel = async (data: IPanel): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, zoneId, panelName, userId, projectId } = data;
|
||||
const { organization, zoneUuid, panelName, userId, projectId } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -178,13 +178,13 @@ export const ClearPanel = async (data: IPanel): Promise<IResult> => {
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingZone = await zoneModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
});
|
||||
if (!existingZone) return { status: "Zone not found" };
|
||||
const existingPanel = await panelModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
panelName: panelName,
|
||||
isArchive: false,
|
||||
});
|
||||
@@ -212,7 +212,7 @@ export const ClearPanel = async (data: IPanel): Promise<IResult> => {
|
||||
|
||||
const zoneAndPanelData = await getZoneAndPanelData(
|
||||
organization,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
projectId
|
||||
);
|
||||
if (!zoneAndPanelData) {
|
||||
@@ -237,7 +237,7 @@ export const ClearPanel = async (data: IPanel): Promise<IResult> => {
|
||||
};
|
||||
export const LockedPanel = async (data: ILockedPanel): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, zoneId, lockedPanel, userId, projectId } = data;
|
||||
const { organization, zoneUuid, lockedPanel, userId, projectId } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -247,14 +247,14 @@ export const LockedPanel = async (data: ILockedPanel): Promise<IResult> => {
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingZone = await zoneModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
});
|
||||
if (!existingZone) return { status: "Zone not found" };
|
||||
else {
|
||||
const updateLockedPanel = await zoneModel(organization).findOneAndUpdate(
|
||||
{ zoneId: zoneId, isArchive: false },
|
||||
{ zoneUuid: zoneUuid, isArchive: false },
|
||||
{
|
||||
lockedPanel: lockedPanel,
|
||||
},
|
||||
@@ -262,7 +262,7 @@ export const LockedPanel = async (data: ILockedPanel): Promise<IResult> => {
|
||||
);
|
||||
const zoneAndPanelData = await getZoneAndPanelData(
|
||||
organization,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
projectId
|
||||
);
|
||||
if (!zoneAndPanelData) {
|
||||
@@ -290,7 +290,7 @@ export const LockedPanel = async (data: ILockedPanel): Promise<IResult> => {
|
||||
};
|
||||
const getZoneAndPanelData = async (
|
||||
organization: string,
|
||||
zoneId: string,
|
||||
zoneUuid: string,
|
||||
projectId: string
|
||||
) => {
|
||||
try {
|
||||
@@ -298,18 +298,18 @@ const getZoneAndPanelData = async (
|
||||
|
||||
const existingZone = await zoneModel(organization)
|
||||
.findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
})
|
||||
.select(
|
||||
"panelOrder zoneName zonePoints lockedPanel zoneId viewPortCenter viewPortposition"
|
||||
"panelOrder zoneName zonePoints lockedPanel zoneUuid viewPortCenter viewPortposition"
|
||||
);
|
||||
if (!existingZone) {
|
||||
return { status: "Zone not found" };
|
||||
} else {
|
||||
const panelData = await panelModel(organization).find({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
});
|
||||
const zoneName = existingZone.zoneName as string;
|
||||
@@ -336,7 +336,7 @@ const getZoneAndPanelData = async (
|
||||
const objectData = {
|
||||
zoneName,
|
||||
viewPortposition: existingZone.viewPortposition,
|
||||
zoneId: existingZone.zoneId,
|
||||
zoneUuid: existingZone.zoneUuid,
|
||||
viewPortCenter: existingZone.viewPortCenter,
|
||||
activeSides: existingZone.panelOrder || [],
|
||||
panelOrder: existingZone.panelOrder || [],
|
||||
|
||||
@@ -29,7 +29,7 @@ interface ITemplateToZone {
|
||||
organization: string;
|
||||
templateID: string;
|
||||
projectId: string;
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
userId: string;
|
||||
}
|
||||
interface ITemplate {
|
||||
@@ -102,7 +102,7 @@ export const AddTemplateToZone = async (
|
||||
data: ITemplateToZone
|
||||
): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, templateID, projectId, zoneId, userId } = data;
|
||||
const { organization, templateID, projectId, zoneUuid, userId } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -112,7 +112,7 @@ export const AddTemplateToZone = async (
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingZone = await zoneModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
});
|
||||
@@ -135,7 +135,7 @@ export const AddTemplateToZone = async (
|
||||
existingZone.panelOrder = existingTemplate.panelOrder;
|
||||
await existingZone.save();
|
||||
const archivePanelDatas = await panelModel(organization).find({
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
isArchive: false,
|
||||
});
|
||||
for (const panelData of archivePanelDatas) {
|
||||
@@ -145,18 +145,18 @@ export const AddTemplateToZone = async (
|
||||
});
|
||||
}
|
||||
await panelModel(organization).deleteMany({
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
isArchive: false,
|
||||
});
|
||||
await floatWidgetModel(organization).deleteMany({
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
isArchive: false,
|
||||
});
|
||||
}
|
||||
existingZone.panelOrder = existingTemplate.panelOrder;
|
||||
await existingZone.save();
|
||||
const existingPanels = await panelModel(organization).find({
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
isArchive: false,
|
||||
});
|
||||
const existingPanelNames = existingPanels.map(
|
||||
@@ -169,7 +169,7 @@ export const AddTemplateToZone = async (
|
||||
await Promise.all(
|
||||
missingPanels.map((panelName: any) =>
|
||||
panelModel(organization).create({
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
panelName,
|
||||
widgets: [],
|
||||
isArchive: false,
|
||||
@@ -180,7 +180,7 @@ export const AddTemplateToZone = async (
|
||||
for (const widgetData of existingTemplate.widgets) {
|
||||
const addedExistingPanel = await panelModel(organization).findOne({
|
||||
panelName: widgetData.panel,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!addedExistingPanel) continue;
|
||||
@@ -195,7 +195,7 @@ export const AddTemplateToZone = async (
|
||||
const newWidget = await widgetModel(organization).create({
|
||||
widgetID: widgetData.id,
|
||||
elementType: widgetData.type,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
widgetName: widgetData.widgetName || "Widget",
|
||||
panelID: addedExistingPanel._id,
|
||||
widgetside: widgetData.panel,
|
||||
@@ -208,7 +208,7 @@ export const AddTemplateToZone = async (
|
||||
const existingFloatWidget = await floatWidgetModel(organization).findOne({
|
||||
floatWidgetID: floatData.id,
|
||||
isArchive: false,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
});
|
||||
if (existingFloatWidget) continue;
|
||||
|
||||
@@ -219,7 +219,7 @@ export const AddTemplateToZone = async (
|
||||
position: floatData.position,
|
||||
per: floatData.per,
|
||||
value: floatData.value,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
});
|
||||
}
|
||||
const templateZoneDatas = {
|
||||
@@ -231,7 +231,7 @@ export const AddTemplateToZone = async (
|
||||
snapshot: existingTemplate.snapshot,
|
||||
floatingWidget: existingTemplate.floatWidgets,
|
||||
},
|
||||
zoneId: existingZone.zoneId,
|
||||
zoneUuid: existingZone.zoneUuid,
|
||||
zoneName: existingZone.zoneName,
|
||||
};
|
||||
|
||||
|
||||
@@ -20,14 +20,14 @@ interface IWidget3DAdd {
|
||||
};
|
||||
};
|
||||
projectId: string;
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
userId: string;
|
||||
}
|
||||
interface IWidget3dUpdate {
|
||||
organization: string;
|
||||
id: string;
|
||||
projectId: string;
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
userId: string;
|
||||
}
|
||||
interface IWidgetUpdate {
|
||||
@@ -36,18 +36,18 @@ interface IWidgetUpdate {
|
||||
position: [];
|
||||
rotation: [];
|
||||
projectId: string;
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
userId: string;
|
||||
}
|
||||
interface I3dWidgetGet {
|
||||
organization: string;
|
||||
projectId: string;
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
userId: string;
|
||||
}
|
||||
export const Add3DWidget = async (data: IWidget3DAdd): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, widget, userId, zoneId, projectId } = data;
|
||||
const { organization, widget, userId, zoneUuid, projectId } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -57,11 +57,11 @@ export const Add3DWidget = async (data: IWidget3DAdd): Promise<IResult> => {
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingZone = await zoneModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
});
|
||||
if (!existingZone) return { status: "Zone not found for the zoneId" };
|
||||
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
||||
|
||||
const existing3Dwidget = await widget3dModel(organization).findOne({
|
||||
widgetID: widget.id,
|
||||
@@ -71,7 +71,7 @@ export const Add3DWidget = async (data: IWidget3DAdd): Promise<IResult> => {
|
||||
const update3dwidget = await widget3dModel(organization).findOneAndUpdate(
|
||||
{
|
||||
widgetID: widget.id,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
},
|
||||
{ position: widget.position },
|
||||
@@ -87,7 +87,7 @@ export const Add3DWidget = async (data: IWidget3DAdd): Promise<IResult> => {
|
||||
type: widget.type,
|
||||
widgetID: widget.id,
|
||||
position: widget.position,
|
||||
zoneId,
|
||||
zoneUuid,
|
||||
Data: {
|
||||
measurements: widget?.Data?.measurements || {},
|
||||
duration: widget?.Data?.duration || "1h",
|
||||
@@ -101,7 +101,7 @@ export const Add3DWidget = async (data: IWidget3DAdd): Promise<IResult> => {
|
||||
position: newWidget3d.position,
|
||||
},
|
||||
Data: newWidget3d.Data,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -125,7 +125,7 @@ export const Add3DWidget = async (data: IWidget3DAdd): Promise<IResult> => {
|
||||
};
|
||||
export const Update3Dwidget = async (data: IWidgetUpdate): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, id, position, rotation, userId, zoneId, projectId } =
|
||||
const { organization, id, position, rotation, userId, zoneUuid, projectId } =
|
||||
data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
@@ -137,7 +137,7 @@ export const Update3Dwidget = async (data: IWidgetUpdate): Promise<IResult> => {
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingZone = await zoneModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
});
|
||||
@@ -148,14 +148,14 @@ export const Update3Dwidget = async (data: IWidgetUpdate): Promise<IResult> => {
|
||||
|
||||
const existing3Dwidget = await widget3dModel(organization).findOne({
|
||||
widgetID: id,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existing3Dwidget) {
|
||||
const update3dwidget = await widget3dModel(organization).findOneAndUpdate(
|
||||
{
|
||||
widgetID: id,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
},
|
||||
{ position: position, rotation: rotation },
|
||||
@@ -169,7 +169,7 @@ export const Update3Dwidget = async (data: IWidgetUpdate): Promise<IResult> => {
|
||||
position: update3dwidget.position,
|
||||
rotation: update3dwidget.rotation,
|
||||
},
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
};
|
||||
return {
|
||||
status: "Success",
|
||||
@@ -196,7 +196,7 @@ export const Delete3Dwidget = async (
|
||||
data: IWidget3dUpdate
|
||||
): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, id, userId, zoneId, projectId } = data;
|
||||
const { organization, id, userId, zoneUuid, projectId } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -206,7 +206,7 @@ export const Delete3Dwidget = async (
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingZone = await zoneModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
});
|
||||
@@ -218,7 +218,7 @@ export const Delete3Dwidget = async (
|
||||
const existing3Dwidget = await widget3dModel(organization).findOne({
|
||||
widgetID: id,
|
||||
isArchive: false,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
});
|
||||
if (!existing3Dwidget) {
|
||||
return { status: "3D widget not found for the ID" };
|
||||
@@ -226,7 +226,7 @@ export const Delete3Dwidget = async (
|
||||
const updateWidget = await widget3dModel(organization).findOneAndUpdate(
|
||||
{
|
||||
widgetID: id,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
},
|
||||
{ isArchive: true },
|
||||
@@ -234,7 +234,7 @@ export const Delete3Dwidget = async (
|
||||
);
|
||||
if (updateWidget) {
|
||||
const delete_Datas = {
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
id: existing3Dwidget.widgetID,
|
||||
};
|
||||
return {
|
||||
@@ -257,7 +257,7 @@ export const Delete3Dwidget = async (
|
||||
};
|
||||
export const Get3Dwidget = async (data: I3dWidgetGet): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, userId, zoneId, projectId } = data;
|
||||
const { organization, userId, zoneUuid, projectId } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -267,7 +267,7 @@ export const Get3Dwidget = async (data: I3dWidgetGet): Promise<IResult> => {
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingZone = await zoneModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
});
|
||||
@@ -276,7 +276,7 @@ export const Get3Dwidget = async (data: I3dWidgetGet): Promise<IResult> => {
|
||||
status: "Zone not found",
|
||||
};
|
||||
const widgetData = await widget3dModel(organization).find({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!widgetData || widgetData.length === 0) {
|
||||
|
||||
@@ -12,7 +12,7 @@ interface IResult {
|
||||
interface IWidgetCreate {
|
||||
organization: string;
|
||||
userId: string;
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
projectId: string;
|
||||
widget: {
|
||||
type: string;
|
||||
@@ -28,14 +28,14 @@ interface IWidgetCreate {
|
||||
interface IWidgetDelete {
|
||||
organization: string;
|
||||
userId: string;
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
projectId: string;
|
||||
widgetID: string;
|
||||
}
|
||||
interface IWidgetUpdate {
|
||||
organization: string;
|
||||
userId: string;
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
projectId: string;
|
||||
widgetID: string;
|
||||
values: {
|
||||
@@ -55,13 +55,13 @@ interface IWidgetUpdate {
|
||||
interface IGetWidget {
|
||||
organization: string;
|
||||
userId: string;
|
||||
zoneId: string;
|
||||
zoneUuid: string;
|
||||
projectId: string;
|
||||
widgetID: string;
|
||||
}
|
||||
export const AddWidget = async (data: IWidgetCreate): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, widget, userId, zoneId, projectId } = data;
|
||||
const { organization, widget, userId, zoneUuid, projectId } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -71,15 +71,15 @@ export const AddWidget = async (data: IWidgetCreate): Promise<IResult> => {
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingZone = await zoneModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
});
|
||||
if (!existingZone) return { status: "Zone not found for the zoneId" };
|
||||
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
||||
|
||||
const existingPanel = await panelModel(organization).findOne({
|
||||
panelName: widget.panel,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingPanel) return { status: "panelName not found" };
|
||||
@@ -121,7 +121,7 @@ export const AddWidget = async (data: IWidgetCreate): Promise<IResult> => {
|
||||
widgetName: widget.title,
|
||||
panelID: existingPanel._id,
|
||||
widgetside: widget.panel,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
Data: {
|
||||
measurements: widget?.Data?.measurements || {},
|
||||
duration: widget?.Data?.duration || "1hr",
|
||||
@@ -138,7 +138,7 @@ export const AddWidget = async (data: IWidgetCreate): Promise<IResult> => {
|
||||
};
|
||||
const finaldata = {
|
||||
widgetData: widgetData,
|
||||
zoneId: existingZone.zoneId,
|
||||
zoneUuid: existingZone.zoneUuid,
|
||||
zoneName: existingZone.zoneName,
|
||||
};
|
||||
return {
|
||||
@@ -164,7 +164,7 @@ export const AddWidget = async (data: IWidgetCreate): Promise<IResult> => {
|
||||
};
|
||||
export const WidgetDelete = async (data: IWidgetDelete): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, widgetID, userId, zoneId, projectId } = data;
|
||||
const { organization, widgetID, userId, zoneUuid, projectId } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -174,35 +174,35 @@ export const WidgetDelete = async (data: IWidgetDelete): Promise<IResult> => {
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingZone = await zoneModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
});
|
||||
if (!existingZone) return { status: "Zone not found for the zoneId" };
|
||||
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
||||
|
||||
const findWidget = await widgetModel(organization).findOne({
|
||||
widgetID: widgetID,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!findWidget) return { status: "Widget not found" };
|
||||
|
||||
const widgetData = await widgetModel(organization).updateOne(
|
||||
{ _id: findWidget._id, isArchive: false, zoneId: zoneId },
|
||||
{ _id: findWidget._id, isArchive: false, zoneUuid: zoneUuid },
|
||||
{ $set: { isArchive: true } }
|
||||
);
|
||||
|
||||
if (widgetData) {
|
||||
await widgetModel(organization).find({
|
||||
panelID: findWidget.panelID,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
const panelData = await panelModel(organization).findOne({
|
||||
_id: findWidget.panelID,
|
||||
isArchive: false,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
});
|
||||
if (panelData.widgets.includes(findWidget._id)) {
|
||||
const index1 = panelData.widgets.indexOf(findWidget._id);
|
||||
@@ -211,7 +211,7 @@ export const WidgetDelete = async (data: IWidgetDelete): Promise<IResult> => {
|
||||
await panelData.save();
|
||||
|
||||
const activeWidgets = await widgetModel(organization).find({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
@@ -227,7 +227,7 @@ export const WidgetDelete = async (data: IWidgetDelete): Promise<IResult> => {
|
||||
}));
|
||||
const widgetData1 = {
|
||||
widgetDeleteDatas: formattedWidgets,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
zoneName: existingZone.zoneName,
|
||||
};
|
||||
return { status: "Success", data: widgetData1 };
|
||||
@@ -247,7 +247,7 @@ export const WidgetDelete = async (data: IWidgetDelete): Promise<IResult> => {
|
||||
};
|
||||
export const UpdateWidget = async (data: IWidgetUpdate): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, widgetID, userId, projectId, zoneId, values } = data;
|
||||
const { organization, widgetID, userId, projectId, zoneUuid, values } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -257,15 +257,15 @@ export const UpdateWidget = async (data: IWidgetUpdate): Promise<IResult> => {
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingZone = await zoneModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
});
|
||||
if (!existingZone) return { status: "Zone not found for the zoneId" };
|
||||
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
||||
|
||||
const findWidget = await widgetModel(organization).findOne({
|
||||
widgetID: widgetID,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!findWidget) return { status: "Data not found" };
|
||||
@@ -311,7 +311,7 @@ export const UpdateWidget = async (data: IWidgetUpdate): Promise<IResult> => {
|
||||
};
|
||||
export const GetWidget = async (data: IGetWidget): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, widgetID, userId, projectId, zoneId } = data;
|
||||
const { organization, widgetID, userId, projectId, zoneUuid } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -321,16 +321,16 @@ export const GetWidget = async (data: IGetWidget): Promise<IResult> => {
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingZone = await zoneModel(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
projectId: projectId,
|
||||
});
|
||||
if (!existingZone) return { status: "Zone not found for the zoneId" };
|
||||
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
||||
|
||||
const existingWidget = await widgetModel(organization)
|
||||
.findOne({
|
||||
widgetID: widgetID,
|
||||
zoneId: zoneId,
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
})
|
||||
.select("Data widgetName -_id");
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Socket, Server } from "socket.io";
|
||||
import { EVENTS } from "../../socket/events.ts";
|
||||
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||
import { deleteAssetModel, replaceEventDatas, setAssetModel } from "../../../shared/services/builder/assetService.ts";
|
||||
import { ErrorResponse, FinalResponse, validateFields } from "../../utils/socketfunctionHelpers.ts";
|
||||
export const setAssetHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
@@ -23,18 +24,11 @@ export const setAssetHandleEvent = async (
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
const response = {
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: data?.organization ?? "unknown",
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1UpdateResponse, response, connectedUsersByOrg)
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1UpdateResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await setAssetModel(data);
|
||||
@@ -54,24 +48,12 @@ export const setAssetHandleEvent = async (
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(Asset_Datas ? { data: Asset_Datas } : {}),
|
||||
};
|
||||
|
||||
const response = FinalResponse(status, socket, data.organization, messages, Asset_Datas);
|
||||
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1UpdateResponse, response, connectedUsersByOrg)
|
||||
@@ -91,18 +73,11 @@ export const deleteAssetHandleEvent = async (
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
const response = {
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: data?.organization ?? "unknown",
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1DeleteResponse, response, connectedUsersByOrg)
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1DeleteResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await deleteAssetModel(data);
|
||||
@@ -123,24 +98,10 @@ export const deleteAssetHandleEvent = async (
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(Asset_Datas ? { data: Asset_Datas } : {}),
|
||||
};
|
||||
const response = FinalResponse(status, socket, data.organization, messages, Asset_Datas);
|
||||
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1DeleteResponse, response, connectedUsersByOrg)
|
||||
@@ -160,18 +121,10 @@ export const replaceEventDatasHandleEvent = async (
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
if (missingFields.length > 0) {
|
||||
const response = {
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: data?.organization ?? "unknown",
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1EventDataResponse, response, connectedUsersByOrg)
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1EventDataResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await replaceEventDatas(data);
|
||||
@@ -192,25 +145,11 @@ export const replaceEventDatasHandleEvent = async (
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(Asset_Datas ? { data: Asset_Datas } : {}),
|
||||
};
|
||||
|
||||
const response = FinalResponse(status, socket, data.organization, messages, Asset_Datas);
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1EventDataResponse, response, connectedUsersByOrg)
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { Socket, Server } from "socket.io";
|
||||
import { EVENTS } from "../../socket/events.ts";
|
||||
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||
import { SetCamera } from "../../../shared/services/builder/cameraService.ts";
|
||||
import { ErrorResponse, FinalResponse, validateFields } from "../../utils/socketfunctionHelpers.ts";
|
||||
export const SetCameraHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
@@ -18,20 +19,13 @@ export const SetCameraHandleEvent = async (
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
const response = {
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: data?.organization ?? "unknown",
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.camera_v1CreateResponse, response, connectedUsersByOrg)
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.camera_v1CreateResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
const result = await SetCamera(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
@@ -49,24 +43,11 @@ export const SetCameraHandleEvent = async (
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(Camera_Datas ? { data: Camera_Datas } : {}),
|
||||
};
|
||||
const response = FinalResponse(status, socket, data.organization, messages, Camera_Datas);
|
||||
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.camera_v1CreateResponse, response, connectedUsersByOrg)
|
||||
|
||||
@@ -2,6 +2,8 @@ import { Socket, Server } from "socket.io";
|
||||
import { EVENTS } from "../../socket/events.ts";
|
||||
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||
import { setEnvironment } from "../../../shared/services/builder/EnvironmentService.ts";
|
||||
import { ErrorResponse, FinalResponse, validateFields } from "../../utils/socketfunctionHelpers.ts";
|
||||
|
||||
export const setEnvironmentHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
@@ -16,20 +18,13 @@ export const setEnvironmentHandleEvent = async (
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
const response = {
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: data?.organization ?? "unknown",
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.Environment_v1UpdateResponse, response, connectedUsersByOrg)
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.Environment_v1UpdateResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
const result = await setEnvironment(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
@@ -43,28 +38,14 @@ export const setEnvironmentHandleEvent = async (
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const Camera_Datas =
|
||||
const environment_Datas =
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(Camera_Datas ? { data: Camera_Datas } : {}),
|
||||
};
|
||||
const response = FinalResponse(status, socket, data.organization, messages, environment_Datas);
|
||||
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.Environment_v1UpdateResponse, response, connectedUsersByOrg)
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Socket, Server } from "socket.io";
|
||||
import { EVENTS } from "../../socket/events.ts";
|
||||
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||
import { CreateLineItems, DeleteLayer, DeleteLineItems, DeleteLinePoints, UpdateLineItems } from "../../../shared/services/builder/lineService.ts";
|
||||
import { ErrorResponse, FinalResponse, validateFields } from "../../utils/socketfunctionHelpers.ts";
|
||||
export const CreateLineHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
@@ -18,18 +19,10 @@ export const CreateLineHandleEvent = async (
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
if (missingFields.length > 0) {
|
||||
const response = {
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: data?.organization ?? "unknown",
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.createLine_v1Response, response, connectedUsersByOrg)
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.createLine_v1Response,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await CreateLineItems(data);
|
||||
@@ -49,24 +42,11 @@ export const CreateLineHandleEvent = async (
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(Line_Datas ? { data: Line_Datas } : {}),
|
||||
};
|
||||
const response = FinalResponse(status, socket, data.organization, messages, Line_Datas);
|
||||
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.createLine_v1Response, response, connectedUsersByOrg)
|
||||
@@ -86,18 +66,11 @@ export const UpdateLineHandleEvent = async (
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
const response = {
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: data?.organization ?? "unknown",
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.updateLine_v1Response, response, connectedUsersByOrg)
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.updateLine_v1Response,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await UpdateLineItems(data);
|
||||
@@ -116,24 +89,12 @@ export const UpdateLineHandleEvent = async (
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(Line_Datas ? { data: Line_Datas } : {}),
|
||||
};
|
||||
const response = FinalResponse(status, socket, data.organization, messages, Line_Datas);
|
||||
|
||||
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.updateLine_v1Response, response, connectedUsersByOrg)
|
||||
@@ -152,18 +113,12 @@ export const DeleteLineHandleEvent = async (
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
const response = {
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: data?.organization ?? "unknown",
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deleteLine_v1Response, response, connectedUsersByOrg)
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deleteLine_v1Response,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await DeleteLineItems(data);
|
||||
@@ -183,25 +138,11 @@ export const DeleteLineHandleEvent = async (
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(Line_Datas ? { data: Line_Datas } : {}),
|
||||
};
|
||||
|
||||
const response = FinalResponse(status, socket, data.organization, messages, Line_Datas);
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deleteLine_v1Response, response, connectedUsersByOrg)
|
||||
}
|
||||
@@ -219,18 +160,11 @@ export const DeleteLayerHandleEvent = async (
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
const response = {
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: data?.organization ?? "unknown",
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deleteLineLayer_v1Response, response, connectedUsersByOrg)
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deleteLineLayer_v1Response,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await DeleteLayer(data);
|
||||
@@ -250,25 +184,11 @@ export const DeleteLayerHandleEvent = async (
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(Line_Datas ? { data: Line_Datas } : {}),
|
||||
};
|
||||
|
||||
const response = FinalResponse(status, socket, data.organization, messages, Line_Datas);
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deleteLineLayer_v1Response, response, connectedUsersByOrg)
|
||||
}
|
||||
@@ -286,18 +206,12 @@ export const DeleteLinePointsHandleEvent = async (
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
const response = {
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: data?.organization ?? "unknown",
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deletePoint_v1Response, response, connectedUsersByOrg)
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deletePoint_v1Response,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await DeleteLinePoints(data);
|
||||
@@ -317,25 +231,11 @@ export const DeleteLinePointsHandleEvent = async (
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(Line_Datas ? { data: Line_Datas } : {}),
|
||||
};
|
||||
|
||||
const response = FinalResponse(status, socket, data.organization, messages, Line_Datas);
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deletePoint_v1Response, response, connectedUsersByOrg)
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { Socket, Server } from "socket.io";
|
||||
import { EVENTS } from "../../socket/events.ts";
|
||||
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||
import { deleteWallItems, setWallItems } from "../../../shared/services/builder/wallService.ts";
|
||||
import { ErrorResponse, FinalResponse, validateFields } from "../../utils/socketfunctionHelpers.ts";
|
||||
|
||||
export const setWallItemsHandleEvent = async (
|
||||
event: string,
|
||||
@@ -24,18 +25,12 @@ export const setWallItemsHandleEvent = async (
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
const response = {
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: data?.organization ?? "unknown",
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.wallItems_v1UpdateResponse, response, connectedUsersByOrg)
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.wallItems_v1UpdateResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await setWallItems(data);
|
||||
@@ -51,29 +46,15 @@ export const setWallItemsHandleEvent = async (
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const Camera_Datas =
|
||||
const wall_Datas =
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(Camera_Datas ? { data: Camera_Datas } : {}),
|
||||
};
|
||||
|
||||
const response = FinalResponse(status, socket, data.organization, messages, wall_Datas);
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.wallItems_v1UpdateResponse, response, connectedUsersByOrg)
|
||||
}
|
||||
@@ -92,23 +73,16 @@ export const deleteWallItemsHandleEvent = async (
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
const response = {
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: data?.organization ?? "unknown",
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.wallItems_v1DeleteResponse, response, connectedUsersByOrg)
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.wallItems_v1DeleteResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await deleteWallItems(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "wall Item deleted successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
@@ -119,7 +93,7 @@ export const deleteWallItemsHandleEvent = async (
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const Camera_Datas =
|
||||
const wall_Datas =
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
@@ -132,15 +106,8 @@ export const deleteWallItemsHandleEvent = async (
|
||||
// zoneId: result.data.zoneId,
|
||||
}
|
||||
: undefined;
|
||||
const response = FinalResponse(status, socket, data.organization, messages, wall_Datas);
|
||||
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(Camera_Datas ? { data: Camera_Datas } : {}),
|
||||
};
|
||||
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.wallItems_v1DeleteResponse, response, connectedUsersByOrg)
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Socket, Server } from "socket.io";
|
||||
import { EVENTS } from "../../socket/events.ts";
|
||||
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||
import { DelZone, SetZone } from "../../../shared/services/builder/zoneService.ts";
|
||||
import { ErrorResponse, FinalResponse, validateFields } from "../../utils/socketfunctionHelpers.ts";
|
||||
|
||||
|
||||
export const SetZoneHandleEvent = async (
|
||||
@@ -18,18 +19,11 @@ export const SetZoneHandleEvent = async (
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
const response = {
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: data?.organization ?? "unknown",
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.zone_v1UpdateResponse, response, connectedUsersByOrg)
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.zone_v1UpdateResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await SetZone(data);
|
||||
@@ -45,28 +39,15 @@ export const SetZoneHandleEvent = async (
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const Camera_Datas =
|
||||
const zone_Datas =
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(Camera_Datas ? { data: Camera_Datas } : {}),
|
||||
};
|
||||
const response = FinalResponse(status, socket, data.organization, messages, zone_Datas);
|
||||
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.zone_v1UpdateResponse, response, connectedUsersByOrg)
|
||||
@@ -80,23 +61,17 @@ export const DeleteZoneHandleEvent = async (
|
||||
) => {
|
||||
if (event !== EVENTS.deleteZone_v1 || !data?.organization) return;
|
||||
const requiredFields = [
|
||||
"zoneId",
|
||||
"zoneUuid",
|
||||
"projectId",
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
const response = {
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: data?.organization ?? "unknown",
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.Zone_v1DeleteResponse, response, connectedUsersByOrg)
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.Zone_v1DeleteResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await DelZone(data);
|
||||
@@ -111,29 +86,15 @@ export const DeleteZoneHandleEvent = async (
|
||||
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const Camera_Datas =
|
||||
const zone_Datas =
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(Camera_Datas ? { data: Camera_Datas } : {}),
|
||||
};
|
||||
const response = FinalResponse(status, socket, data.organization, messages, zone_Datas);
|
||||
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.Zone_v1DeleteResponse, response, connectedUsersByOrg)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Socket, Server } from "socket.io";
|
||||
import { EVENTS } from "../../socket/events.ts";
|
||||
import { emitEventResponse, emitToSenderAndAdmins, } from "../../utils/emitEventResponse.ts";
|
||||
import { emitToSenderAndAdmins, } from "../../utils/emitEventResponse.ts";
|
||||
import { createProject, DeleteProject, DuplicateProject, updateProject } from "../../../shared/services/v1Project/v1projectservice.ts";
|
||||
import { ErrorResponse, FinalResponse, validateFields } from "../../utils/socketfunctionHelpers.ts";
|
||||
|
||||
export const projectHandleEvent = async (
|
||||
event: string,
|
||||
@@ -13,18 +14,11 @@ export const projectHandleEvent = async (
|
||||
console.log('event: ', event);
|
||||
if (event !== EVENTS.addProject || !data?.organization) return;
|
||||
const requiredFields = ["projectUuid", "userId", "thumbnail", "organization"];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
const response = {
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: data?.organization ?? "unknown",
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.projectResponse, response, connectedUsersByOrg)
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.projectResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
console.log('data:controller ', data);
|
||||
@@ -36,29 +30,18 @@ export const projectHandleEvent = async (
|
||||
"user_not_found": { message: "User not found" },
|
||||
"project_exists": { message: "Project already exists" },
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error", };
|
||||
|
||||
let projectDatas = undefined;
|
||||
let responseData = undefined;
|
||||
if (status === "Success" && result?.project) {
|
||||
projectDatas = {
|
||||
responseData = {
|
||||
projectUuid: result.project.projectUuid,
|
||||
projectName: result.project.projectName,
|
||||
thumbnail: result.project.thumbnail,
|
||||
createdBy: result.project.createdBy,
|
||||
projectId: result.project._id,
|
||||
};
|
||||
}
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(status === "Success" ? { data: projectDatas, projectId: result.project._id } : {}),
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.projectResponse, response, connectedUsersByOrg)
|
||||
|
||||
const response = FinalResponse(status, socket, data.organization, messages, responseData);
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.projectResponse, response, connectedUsersByOrg);
|
||||
}
|
||||
export const projectDeleteHandleEvent = async (
|
||||
event: string,
|
||||
@@ -71,18 +54,11 @@ export const projectDeleteHandleEvent = async (
|
||||
|
||||
if (event !== EVENTS.deleteProject || !data?.organization) return;
|
||||
const requiredFields = ["projectId", "userId", "organization"];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
const response = {
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: data?.organization ?? "unknown",
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deleteProjectResponse, response, connectedUsersByOrg)
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deleteProjectResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await DeleteProject(data);
|
||||
@@ -105,17 +81,8 @@ export const projectDeleteHandleEvent = async (
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(projectDeleteDatas ? { data: projectDeleteDatas } : {}),
|
||||
};
|
||||
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deleteProjectResponse, response, connectedUsersByOrg)
|
||||
const response = FinalResponse(status, socket, data.organization, messages, projectDeleteDatas);
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.projectResponse, response, connectedUsersByOrg);
|
||||
}
|
||||
|
||||
export const projecUpdateHandleEvent = async (
|
||||
@@ -128,18 +95,11 @@ export const projecUpdateHandleEvent = async (
|
||||
console.log('event: ', event);
|
||||
if (event !== EVENTS.ProjectUpdate || !data?.organization) return;
|
||||
const requiredFields = ["projectId", "userId", "organization"];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
const response = {
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: data?.organization ?? "unknown",
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.projectUpdateResponse, response, connectedUsersByOrg)
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.projectUpdateResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await updateProject(data);
|
||||
@@ -163,16 +123,7 @@ export const projecUpdateHandleEvent = async (
|
||||
: undefined;
|
||||
|
||||
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(projectDeleteDatas ? { data: projectDeleteDatas } : {}),
|
||||
};
|
||||
|
||||
|
||||
const response = FinalResponse(status, socket, data.organization, messages, projectDeleteDatas);
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.projectUpdateResponse, response, connectedUsersByOrg)
|
||||
|
||||
}
|
||||
@@ -185,19 +136,12 @@ export const DuplicateProjectHandleEvent = async (
|
||||
) => {
|
||||
console.log('event: ', event);
|
||||
if (event !== EVENTS.DuplicateProject || !data?.organization) return;
|
||||
const requiredFields = ["projectUuid", "projectName","userId", "thumbnail", "organization"];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
const requiredFields = ["projectUuid", "projectName", "userId", "thumbnail", "organization"];
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
const response = {
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: data?.organization ?? "unknown",
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.DuplicateprojectResponse, response, connectedUsersByOrg)
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.DuplicateprojectResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
console.log('data:controller ', data);
|
||||
@@ -221,14 +165,8 @@ export const DuplicateProjectHandleEvent = async (
|
||||
createdBy: result.project.createdBy,
|
||||
};
|
||||
}
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(status === "Success" ? { data: projectDatas, projectId: result.project._id } : {}),
|
||||
};
|
||||
const response = FinalResponse(status, socket, data.organization, messages, projectDatas);
|
||||
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.DuplicateprojectResponse, response, connectedUsersByOrg)
|
||||
|
||||
|
||||
@@ -48,13 +48,7 @@ export const productAddHandleEvent = async (
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Socket, Server } from "socket.io";
|
||||
import { EVENTS } from "../../socket/events.ts";
|
||||
import { emitEventResponse, emitToSenderAndAdmins, } from "../../utils/emitEventResponse.ts";
|
||||
import { emitToSenderAndAdmins, } from "../../utils/emitEventResponse.ts";
|
||||
import {
|
||||
TrashDelete,
|
||||
} from "../../../shared/services/v1trash/v1trashservice.ts";
|
||||
@@ -43,13 +43,7 @@ export const TrashDeleteHandleEvent = async (
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
const response = {
|
||||
|
||||
@@ -10,7 +10,7 @@ export const add3DwidgetHandleEvent = async (
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
) => {
|
||||
if (event !== EVENTS.addWidget3D || !data?.organization) return;
|
||||
const requiredFields = ["projectId", "userId", "organization", "zoneId", "widget"];
|
||||
const requiredFields = ["projectId", "userId", "organization", "zoneUuid", "widget"];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
@@ -31,7 +31,7 @@ export const add3DwidgetHandleEvent = async (
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "Widget created successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Zone not found for the zoneId": { message: "Zone not found for the zoneId" },
|
||||
"Zone not found for the zoneUuid": { message: "Zone not found for the zoneUuid" },
|
||||
"3dwidget update successfully": { message: "widget update successfully" },
|
||||
"3dWidget not updated": { message: "3dWidget not updated" },
|
||||
"Widget 3d not created": { message: "Widget 3d not created" },
|
||||
@@ -42,13 +42,6 @@ export const add3DwidgetHandleEvent = async (
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
@@ -72,7 +65,7 @@ export const update3DHandleEvent = async (
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
) => {
|
||||
if (event !== EVENTS.updateWidget3DPosition || !data?.organization) return;
|
||||
const requiredFields = ["projectId", "id", "position", "rotation", "userId", "organization", "zoneId", "widget"];
|
||||
const requiredFields = ["projectId", "id", "position", "rotation", "userId", "organization", "zoneUuid", "widget"];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
@@ -127,7 +120,7 @@ export const Delete3DwidgetHandleEvent = async (
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
) => {
|
||||
if (event !== EVENTS.deleteWidget3D || !data?.organization) return;
|
||||
const requiredFields = ["projectId", "id", "userId", "organization", "zoneId",];
|
||||
const requiredFields = ["projectId", "id", "userId", "organization", "zoneUuid",];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
|
||||
@@ -10,7 +10,7 @@ export const AddFloatHandleEvent = async (
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
) => {
|
||||
if (event !== EVENTS.addFloat_v1 || !data?.organization) return;
|
||||
const requiredFields = ["zoneId", "index", "widget", "projectId", "userId", "organization",];
|
||||
const requiredFields = ["zoneUuid", "index", "widget", "projectId", "userId", "organization",];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
@@ -31,7 +31,7 @@ export const AddFloatHandleEvent = async (
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "FloatWidget created successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Zone not found for the zoneId": { message: "Zone not found for the zoneId" },
|
||||
"Zone not found for the zoneUuid": { message: "Zone not found for the zoneUuid" },
|
||||
"Widget updated successfully": { message: "Widget updated successfully" },
|
||||
"Failed to create FloatWidget": { message: "Failed to create FloatWidget" },
|
||||
};
|
||||
@@ -41,13 +41,7 @@ export const AddFloatHandleEvent = async (
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
@@ -71,7 +65,7 @@ export const DeleteFloatHandleEvent = async (
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
) => {
|
||||
if (event !== EVENTS.deleteFloat_v1 || !data?.organization) return;
|
||||
const requiredFields = ["zoneId", "floatWidgetID", "projectId", "userId", "organization",];
|
||||
const requiredFields = ["zoneUuid", "floatWidgetID", "projectId", "userId", "organization",];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
@@ -92,7 +86,7 @@ export const DeleteFloatHandleEvent = async (
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "FloatingWidget deleted successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Zone not found for the zoneId": { message: "Zone not found for the zoneId" },
|
||||
"Zone not found for the zoneUuid": { message: "Zone not found for the zoneUuid" },
|
||||
"FloatWidget not found for the Id": { message: "FloatWidget not found for the Id" },
|
||||
"FloatWidget not deleted": { message: "FloatWidget not deleted" },
|
||||
};
|
||||
@@ -102,13 +96,7 @@ export const DeleteFloatHandleEvent = async (
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
@@ -132,7 +120,7 @@ export const DuplicateFloatHandleEvent = async (
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
) => {
|
||||
if (event !== EVENTS.duplicatefloat_v1 || !data?.organization) return;
|
||||
const requiredFields = ["zoneId", "index", "widget", "projectId", "userId", "organization",];
|
||||
const requiredFields = ["zoneUuid", "index", "widget", "projectId", "userId", "organization",];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
@@ -153,7 +141,7 @@ export const DuplicateFloatHandleEvent = async (
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "duplicate FloatWidget created successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Zone not found for the zoneId": { message: "Zone not found for the zoneId" },
|
||||
"Zone not found for the zoneUuid": { message: "Zone not found for the zoneUuid" },
|
||||
"FloatWidget update unsuccessfull": { message: "FloatWidget update unsuccessfull" },
|
||||
"FloatWidget not deleted": { message: "FloatWidget not deleted" },
|
||||
};
|
||||
@@ -163,13 +151,7 @@ export const DuplicateFloatHandleEvent = async (
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ export const AddPanelHandleEvent = async (
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
) => {
|
||||
if (event !== EVENTS.addPanel_v1 || !data?.organization) return;
|
||||
const requiredFields = ["zoneId", "panelOrder", "projectId", "userId", "organization",];
|
||||
const requiredFields = ["zoneUuid", "panelOrder", "projectId", "userId", "organization",];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
@@ -40,13 +40,7 @@ export const AddPanelHandleEvent = async (
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
@@ -70,7 +64,7 @@ export const DeletePanelHandleEvent = async (
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
) => {
|
||||
if (event !== EVENTS.deletePanel_v1 || !data?.organization) return;
|
||||
const requiredFields = ["zoneId", "panelName", "projectId", "userId", "organization",];
|
||||
const requiredFields = ["zoneUuid", "panelName", "projectId", "userId", "organization",];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
@@ -100,13 +94,7 @@ export const DeletePanelHandleEvent = async (
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
@@ -130,7 +118,7 @@ export const ClearPanelHandleEvent = async (
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
) => {
|
||||
if (event !== EVENTS.clearPanel_v1 || !data?.organization) return;
|
||||
const requiredFields = ["zoneId", "panelName", "projectId", "userId", "organization",];
|
||||
const requiredFields = ["zoneUuid", "panelName", "projectId", "userId", "organization",];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
@@ -162,14 +150,7 @@ export const ClearPanelHandleEvent = async (
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
}
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = {
|
||||
@@ -192,7 +173,7 @@ export const LockedPanelHandleEvent = async (
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
) => {
|
||||
if (event !== EVENTS.lockedPanel_v1 || !data?.organization) return;
|
||||
const requiredFields = ["zoneId", "lockedPanel", "projectId", "userId", "organization",];
|
||||
const requiredFields = ["zoneUuid", "lockedPanel", "projectId", "userId", "organization",];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
@@ -223,13 +204,7 @@ export const LockedPanelHandleEvent = async (
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
|
||||
@@ -40,13 +40,7 @@ export const AddTemplateHandleEvent = async (
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
@@ -109,7 +103,7 @@ export const addTemplateZoneHandleEvent = async (
|
||||
// snapshot: existingTemplate.snapshot,
|
||||
// floatingWidget: existingTemplate.floatWidgets,
|
||||
// },
|
||||
// zoneId: existingZone.zoneId,
|
||||
// zoneUuid: existingZone.zoneUuid,
|
||||
// zoneName: existingZone.zoneName,
|
||||
// };
|
||||
}
|
||||
@@ -171,7 +165,7 @@ export const TemplateDeleteHandleEvent = async (
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
// zoneUuid: result.data.zoneUuid,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ export const AddWidgetHandleEvent = async (
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
) => {
|
||||
if (event !== EVENTS.addWidget_v1 || !data?.organization) return;
|
||||
const requiredFields = ["zoneId", "widget", "projectId", "userId", "organization",];
|
||||
const requiredFields = ["zoneUuid", "widget", "projectId", "userId", "organization",];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
@@ -31,7 +31,7 @@ export const AddWidgetHandleEvent = async (
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "Widget created successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Zone not found for the zoneId": { message: "Zone not found for the zoneId" },
|
||||
"Zone not found for the zoneUuid": { message: "Zone not found for the zoneUuid" },
|
||||
"panelName not found": { message: "panelName not found" },
|
||||
"Widget update unsuccessfull": { message: "Widget update unsuccessfull" },
|
||||
"Type mismatch": { message: "Type mismatch" },
|
||||
@@ -43,13 +43,7 @@ export const AddWidgetHandleEvent = async (
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
// widget: {
|
||||
// id: result.data.widgetID,
|
||||
// type: result.data.projectName,
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
@@ -73,7 +67,7 @@ export const WidgetDeleteHandleEvent = async (
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
) => {
|
||||
if (event !== EVENTS.deleteWidget_v1 || !data?.organization) return;
|
||||
const requiredFields = ["zoneId", "widgetID", "projectId", "userId", "organization",];
|
||||
const requiredFields = ["zoneUuid", "widgetID", "projectId", "userId", "organization",];
|
||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
@@ -94,7 +88,7 @@ export const WidgetDeleteHandleEvent = async (
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "Widget deleted successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Zone not found for the zoneId": { message: "Zone not found for the zoneId" },
|
||||
"Zone not found for the zoneUuid": { message: "Zone not found for the zoneUuid" },
|
||||
"Widget not found": { message: "Widget not found" },
|
||||
|
||||
};
|
||||
@@ -110,7 +104,7 @@ export const WidgetDeleteHandleEvent = async (
|
||||
// position: result.data.position,
|
||||
// },
|
||||
// Data: result.data.Data,
|
||||
// zoneId: result.data.zoneId,
|
||||
// zoneUuid: result.data.zoneUuid,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
|
||||
@@ -18,25 +18,25 @@ import { AddPanelHandleEvent, ClearPanelHandleEvent, DeletePanelHandleEvent, Loc
|
||||
import { AddTemplateHandleEvent, addTemplateZoneHandleEvent, TemplateDeleteHandleEvent } from '../controllers/vizualizationController/template-Controller.ts';
|
||||
import { AddWidgetHandleEvent, WidgetDeleteHandleEvent } from '../controllers/vizualizationController/widget-Controller.ts';
|
||||
import { getUserRole } from '../utils/getUsers.ts';
|
||||
import { initSocketServer } from "../socket/socketManager.ts";
|
||||
|
||||
|
||||
interface UserSocketInfo {
|
||||
socketId: string;
|
||||
userId: string;
|
||||
role: string;
|
||||
role: string;
|
||||
}
|
||||
|
||||
const connectedUsersByOrg: { [organization: string]: UserSocketInfo[] } = {};
|
||||
export const SocketServer = (io: Server) => {
|
||||
|
||||
|
||||
|
||||
|
||||
const namespaces = {
|
||||
dashboard: io.of('/dashboard'),
|
||||
dashboard: io.of('/dashboard'),
|
||||
project: io.of('/project'),
|
||||
thread: io.of('/thread'),
|
||||
Builder: io.of("/Builder_v1"),
|
||||
visualization: io.of("/Visualization_v1"),
|
||||
Builder_v1: io.of("/Builder_v1"),
|
||||
visualization_v1: io.of("/Visualization_v1"),
|
||||
};
|
||||
|
||||
|
||||
@@ -73,12 +73,12 @@ export const SocketServer = (io: Server) => {
|
||||
return next(new Error("Authentication error: User not found"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
(socket as any).user = {
|
||||
|
||||
organization: decoded.organization,
|
||||
Email: decoded.Email,
|
||||
userId: decoded.userId,
|
||||
organization: decoded.organization,
|
||||
Email: decoded.Email,
|
||||
userId: decoded.userId,
|
||||
};
|
||||
|
||||
next();
|
||||
@@ -88,10 +88,9 @@ export const SocketServer = (io: Server) => {
|
||||
|
||||
}
|
||||
});
|
||||
namespace.on("connection",async (socket: Socket) => {
|
||||
namespace.on("connection", async (socket: Socket) => {
|
||||
const user = (socket as any).user;
|
||||
const organization = user.organization;
|
||||
const Email = user.Email;
|
||||
const userId = user.userId;
|
||||
|
||||
|
||||
@@ -99,7 +98,7 @@ export const SocketServer = (io: Server) => {
|
||||
if (organization) {
|
||||
socket.join(organization);
|
||||
}
|
||||
|
||||
|
||||
const role = await getUserRole(userId, organization);
|
||||
if (role === "Admin") {
|
||||
socket.join(`${organization}_admins`);
|
||||
@@ -120,10 +119,9 @@ export const SocketServer = (io: Server) => {
|
||||
}
|
||||
|
||||
socket.onAny((event: string, data: any, callback: any) => {
|
||||
console.log('data: dahbord', data);
|
||||
eventHandlers.forEach(handler =>
|
||||
handler(event, socket, io, data, connectedUsersByOrg, callback)
|
||||
);
|
||||
handler(event, socket, io, data, connectedUsersByOrg, callback)
|
||||
);
|
||||
});
|
||||
|
||||
socket.on("disconnect", () => {
|
||||
@@ -144,14 +142,23 @@ export const SocketServer = (io: Server) => {
|
||||
|
||||
|
||||
|
||||
handleNamespace(namespaces.dashboard);
|
||||
handleNamespace(namespaces.thread,createThreadHandleEvent,deleteThreadHandleEvent,addCommentHandleEvent,deleteCommentHandleEvent)
|
||||
handleNamespace(namespaces.dashboard);
|
||||
handleNamespace(namespaces.thread,
|
||||
createThreadHandleEvent,
|
||||
deleteThreadHandleEvent,
|
||||
addCommentHandleEvent,
|
||||
deleteCommentHandleEvent)
|
||||
|
||||
|
||||
|
||||
|
||||
handleNamespace(namespaces.project, projectHandleEvent, projectDeleteHandleEvent, projecUpdateHandleEvent,DuplicateProjectHandleEvent,TrashDeleteHandleEvent )
|
||||
handleNamespace(namespaces.Builder,
|
||||
handleNamespace(namespaces.project,
|
||||
projectHandleEvent,
|
||||
projectDeleteHandleEvent,
|
||||
projecUpdateHandleEvent,
|
||||
DuplicateProjectHandleEvent,
|
||||
TrashDeleteHandleEvent)
|
||||
handleNamespace(namespaces.Builder_v1,
|
||||
setAssetHandleEvent,
|
||||
deleteAssetHandleEvent,
|
||||
replaceEventDatasHandleEvent,
|
||||
@@ -167,7 +174,7 @@ handleNamespace(namespaces.thread,createThreadHandleEvent,deleteThreadHandleEven
|
||||
SetZoneHandleEvent,
|
||||
DeleteZoneHandleEvent
|
||||
)
|
||||
handleNamespace(namespaces.visualization,
|
||||
handleNamespace(namespaces.visualization_v1,
|
||||
add3DwidgetHandleEvent,
|
||||
update3DHandleEvent,
|
||||
Delete3DwidgetHandleEvent,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Request, Response } from "express";
|
||||
import wallItemModel from "../../../shared/model/builder/assets/wallitems-Model.ts";
|
||||
|
||||
export const setWallItems = async (data: any) => {
|
||||
|
||||
@@ -108,8 +108,7 @@ export const EVENTS = {
|
||||
addWidget3D: "v1:viz-3D-widget:add",
|
||||
addWidget3DResponse: "v1:viz-widget3D:response:add",
|
||||
updateWidget3DPosition: "v1:viz-3D-widget:modifyPositionRotation",
|
||||
updateWidget3DPositionResponse:
|
||||
"v1:viz-widget3D:response:modifyPositionRotation",
|
||||
updateWidget3DPositionResponse:"v1:viz-widget3D:response:modifyPositionRotation",
|
||||
deleteWidget3D: "v1:viz-3D-widget:delete",
|
||||
deletewidget3DResponse: "v1:viz-widget3D:response:delete",
|
||||
|
||||
@@ -142,7 +141,7 @@ export const EVENTS = {
|
||||
widget_v1DeleteResponse: "v1:viz-widget:response:delete",
|
||||
|
||||
setAssetModel_v1: "v1:model-asset:add",
|
||||
asset_v1UpdateResponse: "v1:model-asset:response:updates",
|
||||
asset_v1UpdateResponse: "v1:model-asset:response:add",
|
||||
delete_v1AssetModel: "v1:model-asset:delete",
|
||||
asset_v1DeleteResponse: "v1:model-asset:response:delete",
|
||||
asset_v1EventData: "v1:model-asset:updateEventData",
|
||||
@@ -163,12 +162,12 @@ export const EVENTS = {
|
||||
deleteLineLayer_v1Response: "v1:Line:response:delete:layer",
|
||||
|
||||
setenvironment_v1: "v1:Environment:set",
|
||||
Environment_v1UpdateResponse: "v1:EnvironmentUpdateResponse",
|
||||
Environment_v1UpdateResponse: "v1:Environment:Response:set",
|
||||
|
||||
setWallItems_v1: "v1:wallItems:set",
|
||||
wallItems_v1UpdateResponse: "v1:wallItemsUpdateResponse",
|
||||
wallItems_v1UpdateResponse: "v1:wallItems:Response:Update",
|
||||
deleteWallItems_v1: "v1:wallItems:delete",
|
||||
wallItems_v1DeleteResponse: "v1:wallItemsDeleteResponse",
|
||||
wallItems_v1DeleteResponse: "v1:wallItem:Response:Delete",
|
||||
|
||||
setZone_v1: "v1:zone:set",
|
||||
zone_v1UpdateResponse: "v1:zone:response:updates",
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
deleteLinPoiteItems,
|
||||
updateLineItems,
|
||||
createLineItems,
|
||||
deleteLayer,
|
||||
|
||||
} from "../services/lines/line-Controller.ts";
|
||||
import {
|
||||
activeUserOffline,
|
||||
@@ -57,14 +57,11 @@ import {
|
||||
projectHandleEvent,
|
||||
projecUpdateHandleEvent,
|
||||
} from "../controllers/projectController/projectController.ts";
|
||||
import { getUserRole } from "../utils/getUsers.ts";
|
||||
|
||||
const cameraHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
data: any,
|
||||
namespace: any,
|
||||
notifySender: boolean = false
|
||||
) => {
|
||||
if (!data?.organization) {
|
||||
console.warn(`Missing organization for event: ${event}`);
|
||||
@@ -100,7 +97,7 @@ const EnvironmentHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
data: any,
|
||||
io: any
|
||||
|
||||
) => {
|
||||
if (!data?.organization) {
|
||||
console.warn(`Missing organization for event: ${event}`);
|
||||
@@ -469,8 +466,6 @@ const panelHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
data: any,
|
||||
namespace: any,
|
||||
notifySender: boolean = false
|
||||
) => {
|
||||
if (!data?.organization) {
|
||||
console.warn(`Missing organization for event: ${event}`);
|
||||
@@ -565,8 +560,6 @@ const widgetHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
data: any,
|
||||
namespace: any,
|
||||
notifySender: boolean = false,
|
||||
callback: any
|
||||
) => {
|
||||
if (!data?.organization) {
|
||||
@@ -627,8 +620,6 @@ const floatHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
data: any,
|
||||
namespace: any,
|
||||
notifySender: boolean = false,
|
||||
callback: any
|
||||
) => {
|
||||
if (!data?.organization) {
|
||||
@@ -707,8 +698,6 @@ const templateHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
data: any,
|
||||
namespace: any,
|
||||
notifySender: boolean = false
|
||||
) => {
|
||||
if (!data?.organization) {
|
||||
console.warn(`Missing organization for event: ${event}`);
|
||||
@@ -787,8 +776,6 @@ const Widget3DHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
data: any,
|
||||
namespace: any,
|
||||
notifySender: boolean = false,
|
||||
callback: any
|
||||
) => {
|
||||
if (!data?.organization) {
|
||||
@@ -870,8 +857,6 @@ const modelAssetHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
data: any,
|
||||
namespace: any,
|
||||
notifySender: boolean = false
|
||||
) => {
|
||||
if (!data?.organization) {
|
||||
console.warn(`Missing organization for event: ${event}`);
|
||||
@@ -969,7 +954,6 @@ interface UserSocketInfo {
|
||||
role: string;
|
||||
}
|
||||
|
||||
const connectedUsersByOrg: { [organization: string]: UserSocketInfo[] } = {};
|
||||
|
||||
export const initSocketServer = (io: Server) => {
|
||||
|
||||
@@ -987,6 +971,8 @@ export const initSocketServer = (io: Server) => {
|
||||
namespace: any,
|
||||
...eventHandlers: Function[]
|
||||
) => {
|
||||
if (namespace._handlersRegistered) return;
|
||||
namespace._handlersRegistered = true;
|
||||
namespace.use((socket: Socket, next: (err?: Error) => void) => {
|
||||
const token = socket.handshake.auth.token;
|
||||
|
||||
@@ -998,11 +984,12 @@ namespace.use((socket: Socket, next: (err?: Error) => void) => {
|
||||
});
|
||||
|
||||
namespace.on("connection", async (socket: Socket) => {
|
||||
|
||||
const { organization, email, userId } = socket.handshake.auth;
|
||||
|
||||
const { organization, email,} = socket.handshake.auth;
|
||||
|
||||
if (organization) {
|
||||
socket.join(organization);
|
||||
|
||||
}
|
||||
if (organization && email) {
|
||||
if (!onlineUsers[organization]) {
|
||||
@@ -1014,7 +1001,6 @@ namespace.use((socket: Socket, next: (err?: Error) => void) => {
|
||||
userStatus(EVENTS.connection, socket, socket.handshake.auth, socket);
|
||||
|
||||
socket.onAny((event: string, data: any, callback: any) => {
|
||||
console.log('data: socketmanager', data);
|
||||
eventHandlers.forEach((handler) =>
|
||||
handler(event, socket, data, namespace, io, callback)
|
||||
);
|
||||
@@ -1025,9 +1011,6 @@ namespace.use((socket: Socket, next: (err?: Error) => void) => {
|
||||
if (onlineUsers[organization]?.size === 0)
|
||||
delete onlineUsers[organization];
|
||||
userStatus(EVENTS.disconnect, socket, socket.handshake.auth, socket);
|
||||
// connectedUsersByOrg[organization] = connectedUsersByOrg[
|
||||
// organization
|
||||
// ].filter((u) => u.socketId !== socket.id);
|
||||
});
|
||||
|
||||
socket.on("reconnect", (attempt: number) => {
|
||||
|
||||
32
src/socket-server/utils/socketfunctionHelpers.ts
Normal file
32
src/socket-server/utils/socketfunctionHelpers.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { Socket, Server } from "socket.io";
|
||||
|
||||
export const validateFields = (data: any, requiredFields: string[]): string[] => {
|
||||
return requiredFields.filter(field => !data?.[field]);
|
||||
};
|
||||
|
||||
|
||||
export const ErrorResponse = (missingFields: string[], socket: Socket, organization: string) => ({
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: organization ?? "unknown",
|
||||
});
|
||||
|
||||
export const FinalResponse = (
|
||||
status: string,
|
||||
socket: Socket,
|
||||
organization: string,
|
||||
messages: Record<string, { message: string }>,
|
||||
data?: any
|
||||
) => {
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
return {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization,
|
||||
...(status === "Success" && data ? { data } : {}),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user