Collaboration completed for builder,dashboard, visualization for API and socket
This commit is contained in:
1
.env
1
.env
@@ -4,7 +4,6 @@ MONGO_USER=admin
|
||||
MONGO_PASSWORD=admin321
|
||||
MONGO_AUTH_DB=admin
|
||||
|
||||
|
||||
API_PORT=5000
|
||||
SOCKET_PORT=8000
|
||||
NODE_ENV=development
|
||||
|
||||
@@ -11,7 +11,6 @@ export const SignupController = async (
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
console.log("req.body: ", req.body);
|
||||
const { userName, Email, Password } = req.body;
|
||||
if (!userName || !Email || !Password) {
|
||||
res.status(400).json({
|
||||
@@ -20,7 +19,6 @@ export const SignupController = async (
|
||||
return;
|
||||
}
|
||||
const result = await AuthSignup(req.body);
|
||||
console.log('result: ', result);
|
||||
|
||||
switch (result.status) {
|
||||
case "User already exists":
|
||||
@@ -53,7 +51,6 @@ export const SignInController = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { Email, Password, fingerprint } = req.body;
|
||||
console.log("req.body: ", req.body);
|
||||
if (!fingerprint || !Email || !Password) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
|
||||
@@ -20,16 +20,7 @@ export const SetEnvironmentController = async (
|
||||
shadowVisibility,
|
||||
projectId,
|
||||
} = req.body;
|
||||
if (
|
||||
!organization ||
|
||||
!userId ||
|
||||
!roofVisibility ||
|
||||
!wallVisibility ||
|
||||
!renderDistance ||
|
||||
!limitDistance ||
|
||||
!shadowVisibility ||
|
||||
!projectId
|
||||
) {
|
||||
if (!organization || !userId || !projectId) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
@@ -45,7 +36,7 @@ export const SetEnvironmentController = async (
|
||||
renderDistance,
|
||||
limitDistance,
|
||||
};
|
||||
const result = await setEnvironment(data);
|
||||
const result = await setEnvironment(req.body);
|
||||
|
||||
switch (result.status) {
|
||||
case "User not found":
|
||||
@@ -71,7 +62,6 @@ export const SetEnvironmentController = async (
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("error: ", error);
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
@@ -109,9 +99,7 @@ export const GetEnvironmentController = async (
|
||||
});
|
||||
break;
|
||||
case "Environment Not found for the User":
|
||||
res.status(404).json({
|
||||
message: "Environment Not found for the User",
|
||||
});
|
||||
res.status(200).json(result.data);
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json(result.data);
|
||||
@@ -123,7 +111,6 @@ export const GetEnvironmentController = async (
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("error: ", error);
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
|
||||
@@ -53,7 +53,6 @@ export const NewLineController = async (
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("error: ", error);
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
@@ -290,6 +289,9 @@ export const GetLinesController = async (
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "Line not found":
|
||||
res.status(200).json(result.data);
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json(result.data);
|
||||
break;
|
||||
|
||||
@@ -84,7 +84,6 @@ export const CreateAssetController = async (
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("error: ", error);
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
@@ -180,9 +179,7 @@ export const GetAssetController = async (
|
||||
});
|
||||
break;
|
||||
case "floorItems not found":
|
||||
res.status(404).json({
|
||||
message: "floorItems not found",
|
||||
});
|
||||
res.status(200).json([]);
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json(result.data);
|
||||
|
||||
@@ -13,14 +13,14 @@ export const SetNewCamera = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, userId } = req.user || {};
|
||||
const { position, target, rotation, projectId} = req.body;
|
||||
const { position, target, rotation, projectId } = req.body;
|
||||
if (
|
||||
!organization ||
|
||||
!userId ||
|
||||
!position ||
|
||||
!target ||
|
||||
!rotation ||
|
||||
!projectId
|
||||
!projectId
|
||||
) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
@@ -62,7 +62,6 @@ export const SetNewCamera = async (
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("error: ", error);
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
@@ -98,6 +97,9 @@ export const CameraList = async (
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "Camera not found":
|
||||
res.status(200).json(result.data);
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json(result.data);
|
||||
break;
|
||||
|
||||
@@ -113,9 +113,7 @@ export const WallGet = async (
|
||||
});
|
||||
break;
|
||||
case "wallitems not found":
|
||||
res.status(404).json({
|
||||
message: "wallitems not found",
|
||||
});
|
||||
res.status(200).json(result.data);
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json(result.data);
|
||||
|
||||
@@ -60,7 +60,6 @@ export const CreateZoneController = async (
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("error: ", error);
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
@@ -104,7 +103,7 @@ export const DeleteZoneController = async (
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
message:"Zone deleted successfully"
|
||||
message: "Zone deleted successfully",
|
||||
});
|
||||
break;
|
||||
default:
|
||||
@@ -200,9 +199,7 @@ export const VizZoneController = async (
|
||||
});
|
||||
break;
|
||||
case "Zone not found for the UUID":
|
||||
res.status(404).json({
|
||||
message: "Zone not found for the UUID",
|
||||
});
|
||||
res.status(200).json(result.data);
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json(result.data);
|
||||
|
||||
@@ -208,7 +208,7 @@ export const ViewData = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, userId, role } = req.user || {};
|
||||
if (!req.user?.userId || !req.user?.organization) {
|
||||
if (!req.user?.userId || !req.user?.organization) {
|
||||
res.status(401).json({ message: "Unauthorized" });
|
||||
return;
|
||||
}
|
||||
@@ -263,7 +263,6 @@ export const ProjectDuplicateController = async (
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
const { projectUuid, thumbnail, projectName } = req.body;
|
||||
|
||||
if (!req.user?.userId || !req.user?.organization) {
|
||||
res.status(401).json({ message: "Unauthorized" });
|
||||
return;
|
||||
|
||||
@@ -45,7 +45,6 @@ export const GetTrashList = async (
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("error: ", error);
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
|
||||
@@ -6,7 +6,6 @@ export const versioncontroller = async (
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
console.log("req.body: ", req.body);
|
||||
const { projectId, userId, description, db } = req.body;
|
||||
|
||||
const result = await versionService.saveCurrentStateAsVersion(
|
||||
@@ -16,7 +15,6 @@ export const versioncontroller = async (
|
||||
description
|
||||
);
|
||||
|
||||
console.log(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "An unexpected error occurred",
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import express from "express";
|
||||
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||
import {
|
||||
GetEnvironmentController,
|
||||
SetEnvironmentController,
|
||||
} from "../../v1Controllers/builderController/v1EnvironmentController.ts";
|
||||
|
||||
const v1Environment = express.Router();
|
||||
|
||||
v1Environment.post("/SetEnvironments", tokenValidator, SetEnvironmentController);
|
||||
|
||||
v1Environment.get(
|
||||
"/Environments/:projectId",
|
||||
tokenValidator,
|
||||
GetEnvironmentController
|
||||
);
|
||||
|
||||
export default v1Environment;
|
||||
@@ -35,16 +35,22 @@ import v1PanelRoutes from "./V1/v1Routes/vizRoutes.ts/v1-panelRoutes.ts";
|
||||
import v1Template from "./V1/v1Routes/vizRoutes.ts/v1-TemplateRoutes.ts";
|
||||
import v1Widget from "./V1/v1Routes/vizRoutes.ts/v1-widgetRoutes.ts";
|
||||
import v1Widget3d from "./V1/v1Routes/vizRoutes.ts/v1-widget3dRoutes.ts";
|
||||
redis
|
||||
import v1Environment from "./V1/v1Routes/BuilderRoutes/v1-environmentRoutes.ts";
|
||||
redis;
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(
|
||||
cors({
|
||||
origin: "*",
|
||||
credentials: true,
|
||||
exposedHeaders: ["x-access-token"],
|
||||
})
|
||||
);
|
||||
|
||||
app.use(express.json({ limit: "50mb" }));
|
||||
app.use(
|
||||
express.urlencoded({ limit: "50mb", extended: true, parameterLimit: 50000 })
|
||||
);
|
||||
dotenv.config();
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
app.get("/", (req, res) => {
|
||||
res.send("Hello, I am Major-Dwinzo API!");
|
||||
@@ -77,6 +83,7 @@ app.use("/api/V1", v1TrashRoutes);
|
||||
app.use("/api/V1", v1homeRoutes);
|
||||
app.use("/api/V1", v1Asset);
|
||||
app.use("/api/V1", v1Camera);
|
||||
app.use("/api/V1", v1Environment);
|
||||
app.use("/api/V1", v1Line);
|
||||
app.use("/api/V1", v1Wall);
|
||||
app.use("/api/V1", v1Zone);
|
||||
|
||||
@@ -13,7 +13,6 @@ export class Environment {
|
||||
renderDistance,
|
||||
limitDistance,
|
||||
} = req.body;
|
||||
|
||||
const findvalue = await environmentModel(organization).findOne({
|
||||
userId: userId,
|
||||
});
|
||||
|
||||
@@ -15,7 +15,6 @@ const AuthSchema: Schema = new Schema({
|
||||
},
|
||||
Email: {
|
||||
type: String,
|
||||
unique: true,
|
||||
required: true,
|
||||
},
|
||||
Password: {
|
||||
|
||||
@@ -6,6 +6,7 @@ import { Version } from "../Version/versionModel.ts";
|
||||
export interface Camera extends Document {
|
||||
userId: User["_id"];
|
||||
projectId: Project["_id"];
|
||||
isArchive: boolean;
|
||||
versionId: Version["_id"];
|
||||
position: {
|
||||
x: number;
|
||||
@@ -28,6 +29,7 @@ const cameraSchema: Schema = new Schema({
|
||||
userId: { type: Schema.Types.ObjectId, ref: "User" },
|
||||
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
||||
isArchive: { type: Boolean, default: false },
|
||||
position: {
|
||||
x: { type: Number, required: true },
|
||||
y: { type: Number, required: true },
|
||||
|
||||
@@ -18,6 +18,7 @@ const LineSchema = new mongoose.Schema({
|
||||
layer: { type: Number, required: true },
|
||||
line: { type: [Vector3], required: true },
|
||||
type: { type: String, required: false },
|
||||
isArchive: { type: Boolean, default: false },
|
||||
});
|
||||
|
||||
const lineModel = (db: string) => {
|
||||
|
||||
@@ -1,25 +1,30 @@
|
||||
import { Document, Schema } from "mongoose";
|
||||
import MainModel from "../../connect/mongoose.ts";
|
||||
import { User } from "../Auth/userAuthModel.ts";
|
||||
import { Project } from "../Project/project-model.ts";
|
||||
export interface Environment extends Document {
|
||||
userId: User["_id"];
|
||||
projectId: Project["_id"];
|
||||
roofVisibility: boolean;
|
||||
wallVisibility: boolean;
|
||||
renderDistance: number;
|
||||
shadowVisibility: boolean;
|
||||
limitDistance: boolean;
|
||||
isArchive: boolean;
|
||||
}
|
||||
|
||||
const environmentSchema: Schema = new Schema({
|
||||
userId: { type: Schema.Types.ObjectId, ref: "User", unique: true },
|
||||
userId: { type: Schema.Types.ObjectId, ref: "User" },
|
||||
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||
roofVisibility: { type: Boolean, default: false },
|
||||
wallVisibility: { type: Boolean, default: false },
|
||||
shadowVisibility: { type: Boolean, default: false },
|
||||
renderDistance: { type: Number, default: 40 },
|
||||
limitDistance: { type: Boolean, default: true },
|
||||
isArchive: { type: Boolean, default: false },
|
||||
});
|
||||
|
||||
const environmentModel = (db: string) => {
|
||||
return MainModel(db, "Environment", environmentSchema, "Environment");
|
||||
return MainModel(db, "Environments", environmentSchema, "Environments");
|
||||
};
|
||||
export default environmentModel;
|
||||
|
||||
62
src/shared/services/User/userService.ts
Normal file
62
src/shared/services/User/userService.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import UsersDataModel from "../../V1Models/Auth/user.ts";
|
||||
import AuthModel from "../../V1Models/Auth/userAuthModel.ts";
|
||||
import {
|
||||
existingProjectById,
|
||||
existingUser,
|
||||
} from "../helpers/v1projecthelperFns.ts";
|
||||
interface ISearchUser {
|
||||
searchName: string;
|
||||
userId: string;
|
||||
organization: string;
|
||||
projectId: string;
|
||||
}
|
||||
interface ShareUserResult {
|
||||
userName: string;
|
||||
Email: string;
|
||||
profilePicture?: string;
|
||||
}
|
||||
export const ShareUserSearch = async (
|
||||
data: ISearchUser
|
||||
): Promise<{
|
||||
status: string;
|
||||
data?: object;
|
||||
}> => {
|
||||
const { userId, organization, searchName, projectId } = data;
|
||||
try {
|
||||
if (!(await existingUser(userId, organization)))
|
||||
return { status: "User not found" };
|
||||
|
||||
if (!(await existingProjectById(projectId, organization, userId)))
|
||||
return { status: "Project not found" };
|
||||
|
||||
const UsersData = await AuthModel(organization).find({
|
||||
Email: { $regex: `${searchName}`, $options: "i" },
|
||||
isArchive: false,
|
||||
});
|
||||
if (!UsersData || UsersData.length === 0)
|
||||
return { status: "Project not found" };
|
||||
const results = await Promise.all(
|
||||
UsersData.map(async (user) => {
|
||||
const profile = await UsersDataModel(organization)
|
||||
.findOne({ userId: user._id, isArchive: false })
|
||||
.select("profilePicture");
|
||||
return {
|
||||
userName: user.userName,
|
||||
Email: user.Email,
|
||||
profilePicture: profile?.profilePicture,
|
||||
};
|
||||
})
|
||||
);
|
||||
return { status: "Success", data: results };
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
return {
|
||||
status: error.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "An unexpected error occurred",
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -11,7 +11,7 @@ interface Iserviceuser {
|
||||
userName: string;
|
||||
Email: string;
|
||||
Password: string;
|
||||
profilePicture: string;
|
||||
profilePicture?: string;
|
||||
}
|
||||
interface IloginUser {
|
||||
Email: string;
|
||||
@@ -64,7 +64,7 @@ export const AuthSignup = async (
|
||||
Email: caseChange,
|
||||
Password: hashPassword,
|
||||
});
|
||||
await UsersDataModel(organization).create({
|
||||
await UsersDataModel(organization).create({
|
||||
userId: newuser._id,
|
||||
role: role,
|
||||
isShare: isShare,
|
||||
|
||||
@@ -5,11 +5,11 @@ import {
|
||||
} from "../helpers/v1projecthelperFns.ts";
|
||||
|
||||
interface EnvironmentInput {
|
||||
roofVisibility: boolean;
|
||||
wallVisibility: boolean;
|
||||
shadowVisibility: boolean;
|
||||
renderDistance: number;
|
||||
limitDistance: boolean;
|
||||
roofVisibility?: boolean;
|
||||
wallVisibility?: boolean;
|
||||
shadowVisibility?: boolean;
|
||||
renderDistance?: number;
|
||||
limitDistance?: boolean;
|
||||
organization: string;
|
||||
projectId: string;
|
||||
userId: string;
|
||||
@@ -43,6 +43,7 @@ export const setEnvironment = async (
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const findvalue = await environmentModel(organization).findOne({
|
||||
userId: userId,
|
||||
projectId: projectId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (findvalue) {
|
||||
@@ -95,13 +96,21 @@ export const getEnvironment = async (
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
|
||||
const findValue = await environmentModel(organization).findOne({
|
||||
userId: userId,
|
||||
projectId: projectId,
|
||||
isArchive: false,
|
||||
});
|
||||
const findValue = await environmentModel(organization)
|
||||
.findOne({
|
||||
userId: userId,
|
||||
projectId: projectId,
|
||||
isArchive: false,
|
||||
})
|
||||
.select(
|
||||
"limitDistance projectId renderDistance roofVisibility shadowVisibility wallVisibility _id"
|
||||
);
|
||||
if (!findValue) {
|
||||
return { status: "Environment Not found for the User" };
|
||||
const newValue = await environmentModel(organization).create({
|
||||
userId,
|
||||
projectId,
|
||||
});
|
||||
return { status: "Environment Not found for the User", data: newValue };
|
||||
} else {
|
||||
return { status: "Success", data: findValue };
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ export const setAssetModel = async (
|
||||
userId: userId,
|
||||
isArchive: false,
|
||||
});
|
||||
console.log("findvalue: ", findvalue);
|
||||
if (findvalue) {
|
||||
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
||||
{
|
||||
@@ -439,11 +440,11 @@ export const getFloorItems = async (
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const findValues = await assetModel(organization)
|
||||
.find({ isArchive: false })
|
||||
.find({ isArchive: false, projectId: projectId })
|
||||
.select("-_id -isArchive");
|
||||
|
||||
if (!findValues || findValues.length === 0) {
|
||||
return { status: "floorItems not found" };
|
||||
return { status: "floorItems not found", data: [] };
|
||||
}
|
||||
|
||||
const response = findValues.map((item) => {
|
||||
|
||||
@@ -25,14 +25,8 @@ export const SetCamera = async (
|
||||
data: IcameraData
|
||||
): Promise<{ status: string; data?: Object }> => {
|
||||
try {
|
||||
const {
|
||||
userId,
|
||||
position,
|
||||
target,
|
||||
rotation,
|
||||
organization,
|
||||
projectId
|
||||
} = data;
|
||||
const { userId, position, target, rotation, organization, projectId } =
|
||||
data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -43,6 +37,7 @@ export const SetCamera = async (
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const existingCamera = await cameraModel(organization).findOne({
|
||||
userId: userId,
|
||||
projectId: projectId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existingCamera) {
|
||||
@@ -98,7 +93,7 @@ export const GetCamers = async (
|
||||
isArchive: false,
|
||||
});
|
||||
if (!findCamera) {
|
||||
return { status: "Camera not found" };
|
||||
return { status: "Camera not found", data: [] };
|
||||
} else {
|
||||
return { status: "Success", data: findCamera };
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import lineModel from "../../V1Models/Builder/linesModel.ts";
|
||||
import { existingProjectById, existingUser } from "../helpers/v1projecthelperFns.ts";
|
||||
import {
|
||||
existingProjectById,
|
||||
existingUser,
|
||||
} from "../helpers/v1projecthelperFns.ts";
|
||||
interface ILineItems {
|
||||
organization: string;
|
||||
layer: number;
|
||||
@@ -83,7 +86,7 @@ export const UpdateLineItems = async (
|
||||
userId
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const updateResult= await lineModel(organization).updateMany(
|
||||
const updateResult = await lineModel(organization).updateMany(
|
||||
{ "line.uuid": uuid, projectId: projectId },
|
||||
{ $set: { "line.$.position": position } }
|
||||
);
|
||||
@@ -117,14 +120,15 @@ export const DeleteLineItems = async (
|
||||
userId
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const inputUuids = line.map((item: any) => item.uuid);
|
||||
const inputUuids = line.map((item: any) => {
|
||||
return item.uuid;
|
||||
});
|
||||
|
||||
const findValue = await lineModel(organization).findOneAndDelete(
|
||||
{ projectId: projectId, isArchive: false },
|
||||
{
|
||||
"line.uuid": { $all: inputUuids },
|
||||
}
|
||||
);
|
||||
const findValue = await lineModel(organization).findOneAndDelete({
|
||||
projectId,
|
||||
isArchive: false,
|
||||
"line.uuid": { $all: inputUuids },
|
||||
});
|
||||
|
||||
if (!findValue) {
|
||||
return {
|
||||
@@ -153,6 +157,7 @@ export const DeleteLayer = async (
|
||||
): Promise<{ status: string; data?: object }> => {
|
||||
try {
|
||||
const { organization, projectId, layer, userId } = data;
|
||||
console.log("data: ", data);
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) return { status: "User not found" };
|
||||
const LivingProject = await existingProjectById(
|
||||
@@ -171,7 +176,7 @@ export const DeleteLayer = async (
|
||||
return { status: "layer not found" };
|
||||
} else {
|
||||
await lineModel(organization).deleteMany(
|
||||
{ projectId: projectId },
|
||||
{ projectId: projectId, layer: layer, isArchive: false },
|
||||
{ layer: layer }
|
||||
);
|
||||
|
||||
@@ -209,7 +214,7 @@ export const GetLinesService = async (
|
||||
isArchive: false,
|
||||
});
|
||||
if (!findValue) {
|
||||
return { status: "user not found" };
|
||||
return { status: "Line not found", data: [] };
|
||||
} else {
|
||||
return { status: "Success", data: findValue };
|
||||
}
|
||||
@@ -227,7 +232,7 @@ export const GetLinesService = async (
|
||||
};
|
||||
export const DeleteLinePoints = async (
|
||||
data: ILinePointsDelete
|
||||
): Promise<{ status: string; data?: object }> => {
|
||||
): Promise<{ status: string; data?: object | string }> => {
|
||||
try {
|
||||
const { organization, projectId, uuid, userId } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
@@ -239,7 +244,7 @@ export const DeleteLinePoints = async (
|
||||
);
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
const findValue = await lineModel(organization).deleteMany(
|
||||
{ projectId: projectId, isArchive: false },
|
||||
{ projectId: projectId, isArchive: false, "line.uuid": uuid },
|
||||
{
|
||||
"line.uuid": uuid,
|
||||
}
|
||||
@@ -248,7 +253,7 @@ export const DeleteLinePoints = async (
|
||||
if (!findValue) {
|
||||
return { status: "Line not found" };
|
||||
} else {
|
||||
return { status: "Success" };
|
||||
return { status: "Success", data: uuid };
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import wallItemModel from "../../../shared/model/builder/assets/wallitems-Model.ts";
|
||||
import { existingProjectById, existingUser } from "../helpers/v1projecthelperFns.ts";
|
||||
import {
|
||||
existingProjectById,
|
||||
existingUser,
|
||||
} from "../helpers/v1projecthelperFns.ts";
|
||||
interface IWallSetupData {
|
||||
modelUuid: string;
|
||||
modelName: string;
|
||||
@@ -29,7 +32,9 @@ interface IWallItemResult {
|
||||
data?: Object;
|
||||
status: string;
|
||||
}
|
||||
export const setWallItems = async (data: IWallSetupData): Promise<IWallItemResult> => {
|
||||
export const setWallItems = async (
|
||||
data: IWallSetupData
|
||||
): Promise<IWallItemResult> => {
|
||||
try {
|
||||
const {
|
||||
userId,
|
||||
@@ -86,6 +91,7 @@ export const setWallItems = async (data: IWallSetupData): Promise<IWallItemResul
|
||||
quaternion,
|
||||
scale,
|
||||
});
|
||||
console.log("newValue: ", newValue);
|
||||
return {
|
||||
status: "wall Item created successfully",
|
||||
data: newValue,
|
||||
@@ -102,7 +108,7 @@ export const setWallItems = async (data: IWallSetupData): Promise<IWallItemResul
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
export const getWallItems = async (data: IWallGet) => {
|
||||
try {
|
||||
const { organization, userId, projectId } = data;
|
||||
@@ -120,6 +126,7 @@ export const getWallItems = async (data: IWallGet) => {
|
||||
if (!findValue) {
|
||||
return {
|
||||
status: "wallitems not found",
|
||||
data: [],
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
@@ -138,8 +145,10 @@ export const getWallItems = async (data: IWallGet) => {
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
export const deleteWallItems = async (data: IWallDelete): Promise<IWallItemResult> => {
|
||||
};
|
||||
export const deleteWallItems = async (
|
||||
data: IWallDelete
|
||||
): Promise<IWallItemResult> => {
|
||||
try {
|
||||
const { modelUuid, modelName, organization, userId, projectId } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
@@ -176,4 +185,4 @@ export const deleteWallItems = async (data: IWallDelete): Promise<IWallItemResul
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,7 +4,10 @@ import floatWidgetModel from "../../V1Models/Vizualization/floatWidget.ts";
|
||||
import panelModel from "../../V1Models/Vizualization/panelmodel.ts";
|
||||
import templateModel from "../../V1Models/Vizualization/templatemodel.ts";
|
||||
import widgetModel from "../../V1Models/Vizualization/widgemodel.ts";
|
||||
import { existingProjectById, existingUser } from "../helpers/v1projecthelperFns.ts";
|
||||
import {
|
||||
existingProjectById,
|
||||
existingUser,
|
||||
} from "../helpers/v1projecthelperFns.ts";
|
||||
interface ISetZone {
|
||||
organization: string;
|
||||
projectId: string;
|
||||
@@ -119,12 +122,16 @@ export const DelZone = async (data: IZone): Promise<IResult> => {
|
||||
if (!LivingProject) return { status: "Project not found" };
|
||||
if (findZoneId) {
|
||||
const deleteZone = await zoneModel(organization)
|
||||
.findOneAndUpdate({
|
||||
zoneUuid: zoneUuid,
|
||||
createdBy: userId,
|
||||
projectId: projectId,
|
||||
isArchive: false,
|
||||
},{isArchive:true},{new:true})
|
||||
.findOneAndUpdate(
|
||||
{
|
||||
zoneUuid: zoneUuid,
|
||||
createdBy: userId,
|
||||
projectId: projectId,
|
||||
isArchive: false,
|
||||
},
|
||||
{ isArchive: true },
|
||||
{ new: true }
|
||||
)
|
||||
.select("-_id -__v");
|
||||
if (deleteZone) {
|
||||
const panels = await panelModel(organization).find({
|
||||
|
||||
@@ -84,7 +84,6 @@ export const existingProjectById = async (
|
||||
) => {
|
||||
const projectData = await projectModel(organization).findOne({
|
||||
_id: projectId,
|
||||
createdBy: userId,
|
||||
isArchive: false,
|
||||
});
|
||||
return projectData;
|
||||
|
||||
@@ -114,7 +114,7 @@ export const GetAllProjects = async (data: GetProjectsInterface) => {
|
||||
const { userId, organization } = data;
|
||||
await existingUser(userId, organization);
|
||||
if (!existingUser) return { status: "User not found" };
|
||||
let filter = { isArchive: false } as RoleFilter;
|
||||
let filter = { isArchive: false, createdBy: userId } as RoleFilter;
|
||||
|
||||
const projectDatas = await projectModel(organization)
|
||||
.find(filter)
|
||||
|
||||
@@ -44,7 +44,6 @@ export const RecentlyAdded = async (data: IRecentData) => {
|
||||
);
|
||||
|
||||
const filteredProjects = RecentDatas.filter(Boolean);
|
||||
console.log("filteredProjects: ", filteredProjects);
|
||||
return { status: "Success", data: filteredProjects };
|
||||
} catch (error) {
|
||||
return { status: error };
|
||||
|
||||
@@ -171,13 +171,17 @@ export const DelFloat = async (data: IDelFloat): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, floatWidgetID, zoneUuid, projectId, userId } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) { return { status: "User not found" } }
|
||||
if (!UserExists) {
|
||||
return { status: "User not found" };
|
||||
}
|
||||
const LivingProject = await existingProjectById(
|
||||
projectId,
|
||||
organization,
|
||||
userId
|
||||
);
|
||||
if (!LivingProject) { return { status: "Project not found" } }
|
||||
if (!LivingProject) {
|
||||
return { status: "Project not found" };
|
||||
}
|
||||
const existingZone = await zoneModel(organization).findOne({
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
@@ -224,13 +228,17 @@ export const DuplicateFloat = async (
|
||||
try {
|
||||
const { organization, widget, zoneUuid, index, projectId, userId } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) {return { status: "User not found" }};
|
||||
if (!UserExists) {
|
||||
return { status: "User not found" };
|
||||
}
|
||||
const LivingProject = await existingProjectById(
|
||||
projectId,
|
||||
organization,
|
||||
userId
|
||||
);
|
||||
if (!LivingProject) {return { status: "Project not found" }};
|
||||
if (!LivingProject) {
|
||||
return { status: "Project not found" };
|
||||
}
|
||||
const existingZone = await zoneModel(organization).findOne({
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
@@ -332,13 +340,17 @@ export const GetFloatWidget = async (data: IGetZoneFloat): Promise<IResult> => {
|
||||
try {
|
||||
const { organization, zoneUuid, projectId, userId } = data;
|
||||
const UserExists = await existingUser(userId, organization);
|
||||
if (!UserExists) {return { status: "User not found" }}
|
||||
if (!UserExists) {
|
||||
return { status: "User not found" };
|
||||
}
|
||||
const LivingProject = await existingProjectById(
|
||||
projectId,
|
||||
organization,
|
||||
userId
|
||||
);
|
||||
if (!LivingProject) {return { status: "Project not found" }};
|
||||
if (!LivingProject) {
|
||||
return { status: "Project not found" };
|
||||
}
|
||||
const existingZone = await zoneModel(organization).findOne({
|
||||
zoneUuid: zoneUuid,
|
||||
isArchive: false,
|
||||
|
||||
@@ -40,7 +40,7 @@ const tokenRefreshGenerator = (
|
||||
{ Email: Email, role: role, userId: userId, organization: organization },
|
||||
refresh_jwt_secret,
|
||||
{
|
||||
expiresIn: "30d",
|
||||
expiresIn: "7d",
|
||||
}
|
||||
);
|
||||
return token;
|
||||
@@ -77,7 +77,6 @@ const tokenValidator = async (
|
||||
req.user = decoded;
|
||||
next();
|
||||
} catch (err) {
|
||||
|
||||
if (!refresh_token) {
|
||||
res.status(403).json({
|
||||
success: false,
|
||||
@@ -93,7 +92,6 @@ const tokenValidator = async (
|
||||
userId: string;
|
||||
organization: string;
|
||||
};
|
||||
console.log("refresh token");
|
||||
if (!decodedRefresh) {
|
||||
res.status(403).json({
|
||||
success: false,
|
||||
|
||||
@@ -1,155 +1,200 @@
|
||||
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";
|
||||
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,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: {
|
||||
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||
}
|
||||
) => {
|
||||
if (event !== EVENTS.setAssetModel_v1 || !data?.organization) return;
|
||||
const requiredFields = [
|
||||
"modelUuid",
|
||||
"modelName",
|
||||
"position",
|
||||
"rotation",
|
||||
"eventData",
|
||||
"modelfileID",
|
||||
"isLocked",
|
||||
"isVisible",
|
||||
"projectId",
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
if (event !== EVENTS.setAssetModel_v1 || !data?.organization) return;
|
||||
console.log('event: ', event);
|
||||
const requiredFields = [
|
||||
"modelUuid",
|
||||
"modelName",
|
||||
"position",
|
||||
"rotation",
|
||||
"modelfileID",
|
||||
"isLocked",
|
||||
"isVisible",
|
||||
"projectId",
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1UpdateResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await setAssetModel(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.asset_v1UpdateResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization),
|
||||
connectedUsersByOrg
|
||||
);
|
||||
return;
|
||||
}
|
||||
const result = await setAssetModel(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "Model created successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Project not found": { message: "Project not found" },
|
||||
"Updated successfully": { message: "Updated successfully" },
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "Model created successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Project not found": { message: "Project not found" },
|
||||
"Updated successfully": { message: "Updated successfully" },
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const Asset_Datas = status === "Success" && result?.data ? {} : undefined;
|
||||
|
||||
};
|
||||
const response = FinalResponse(
|
||||
status,
|
||||
socket,
|
||||
data.organization,
|
||||
messages,
|
||||
Asset_Datas
|
||||
);
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const Asset_Datas =
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
|
||||
const response = FinalResponse(status, socket, data.organization, messages, Asset_Datas);
|
||||
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1UpdateResponse, response, connectedUsersByOrg)
|
||||
}
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.asset_v1UpdateResponse,
|
||||
response,
|
||||
connectedUsersByOrg
|
||||
);
|
||||
};
|
||||
export const deleteAssetHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: {
|
||||
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||
}
|
||||
) => {
|
||||
if (event !== EVENTS.delete_v1AssetModel || !data?.organization) return;
|
||||
const requiredFields = [
|
||||
"modelUuid",
|
||||
"modelName",
|
||||
"projectId",
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
if (event !== EVENTS.delete_v1AssetModel || !data?.organization) return;
|
||||
console.log('event: ', event);
|
||||
const requiredFields = [
|
||||
"modelUuid",
|
||||
"modelName",
|
||||
"projectId",
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1DeleteResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await deleteAssetModel(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.asset_v1DeleteResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization),
|
||||
connectedUsersByOrg
|
||||
);
|
||||
return;
|
||||
}
|
||||
const result = await deleteAssetModel(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "Model deleted successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Project not found": { message: "Project not found" },
|
||||
"model not found": { message: "model not found" },
|
||||
"Failed to archive asset": { message: "Failed to archive asset" },
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "Model deleted successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Project not found": { message: "Project not found" },
|
||||
"model not found": { message: "model not found" },
|
||||
"Failed to archive asset": { message: "Failed to archive asset" },
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const Asset_Datas = status === "Success" && result?.data ? {} : undefined;
|
||||
const response = FinalResponse(
|
||||
status,
|
||||
socket,
|
||||
data.organization,
|
||||
messages,
|
||||
Asset_Datas
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const Asset_Datas =
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
|
||||
}
|
||||
: undefined;
|
||||
const response = FinalResponse(status, socket, data.organization, messages, Asset_Datas);
|
||||
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1DeleteResponse, response, connectedUsersByOrg)
|
||||
}
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.asset_v1DeleteResponse,
|
||||
response,
|
||||
connectedUsersByOrg
|
||||
);
|
||||
};
|
||||
export const replaceEventDatasHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: {
|
||||
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||
}
|
||||
) => {
|
||||
if (event !== EVENTS.asset_v1EventData || !data?.organization) return;
|
||||
const requiredFields = [
|
||||
"modelUuid",
|
||||
"eventData",
|
||||
"projectId",
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1EventDataResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await replaceEventDatas(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
if (event !== EVENTS.asset_v1EventData || !data?.organization) return;
|
||||
const requiredFields = [
|
||||
"modelUuid",
|
||||
"eventData",
|
||||
"projectId",
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.asset_v1EventDataResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization),
|
||||
connectedUsersByOrg
|
||||
);
|
||||
return;
|
||||
}
|
||||
const result = await replaceEventDatas(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "Data updated successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Project not found": { message: "Project not found" },
|
||||
"Model not for this UUID": { message: "Model not for this UUID" },
|
||||
"Failed to archive asset": { message: "Failed to archive asset" },
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "Data updated successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Project not found": { message: "Project not found" },
|
||||
"Model not for this UUID": { message: "Model not for this UUID" },
|
||||
"Failed to archive asset": { message: "Failed to archive asset" },
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const Asset_Datas = status === "Success" && result?.data ? {} : undefined;
|
||||
|
||||
};
|
||||
const response = FinalResponse(
|
||||
status,
|
||||
socket,
|
||||
data.organization,
|
||||
messages,
|
||||
Asset_Datas
|
||||
);
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const Asset_Datas =
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = FinalResponse(status, socket, data.organization, messages, Asset_Datas);
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1EventDataResponse, response, connectedUsersByOrg)
|
||||
}
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.asset_v1EventDataResponse,
|
||||
response,
|
||||
connectedUsersByOrg
|
||||
);
|
||||
};
|
||||
|
||||
@@ -11,6 +11,7 @@ export const SetCameraHandleEvent = async (
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
) => {
|
||||
if (event !== EVENTS.setCamera_v1 || !data?.organization) return;
|
||||
console.log('event: ', event);
|
||||
const requiredFields = [
|
||||
"position",
|
||||
"target",
|
||||
@@ -26,6 +27,7 @@ export const SetCameraHandleEvent = async (
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
console.log('data: ', data);
|
||||
const result = await SetCamera(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
|
||||
@@ -1,241 +1,303 @@
|
||||
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";
|
||||
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,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: {
|
||||
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||
}
|
||||
) => {
|
||||
if (event !== EVENTS.createLine_v1 || !data?.organization) return;
|
||||
const requiredFields = [
|
||||
"line",
|
||||
"type",
|
||||
"layer",
|
||||
"projectId",
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.createLine_v1Response,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await CreateLineItems(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
if (event !== EVENTS.createLine_v1 || !data?.organization) return;
|
||||
const requiredFields = [
|
||||
"line",
|
||||
"type",
|
||||
"layer",
|
||||
"projectId",
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.createLine_v1Response,
|
||||
ErrorResponse(missingFields, socket, data.organization),
|
||||
connectedUsersByOrg
|
||||
);
|
||||
return;
|
||||
}
|
||||
const result = await CreateLineItems(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "line created successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Project not found": { message: "Project not found" },
|
||||
"Update Success": { message: "Update Success" },
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "line created successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Project not found": { message: "Project not found" },
|
||||
"Update Success": { message: "Update Success" },
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const Line_Datas = status === "Success" && result?.data ? {} : undefined;
|
||||
|
||||
};
|
||||
const response = FinalResponse(
|
||||
status,
|
||||
socket,
|
||||
data.organization,
|
||||
messages,
|
||||
Line_Datas
|
||||
);
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const Line_Datas =
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = FinalResponse(status, socket, data.organization, messages, Line_Datas);
|
||||
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.createLine_v1Response, response, connectedUsersByOrg)
|
||||
}
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.createLine_v1Response,
|
||||
response,
|
||||
connectedUsersByOrg
|
||||
);
|
||||
};
|
||||
export const UpdateLineHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: {
|
||||
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||
}
|
||||
) => {
|
||||
if (event !== EVENTS.updateLine_v1 || !data?.organization) return;
|
||||
const requiredFields = [
|
||||
"uuid",
|
||||
"position",
|
||||
"projectId",
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
if (event !== EVENTS.updateLine_v1 || !data?.organization) return;
|
||||
const requiredFields = [
|
||||
"uuid",
|
||||
"position",
|
||||
"projectId",
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.updateLine_v1Response,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await UpdateLineItems(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.updateLine_v1Response,
|
||||
ErrorResponse(missingFields, socket, data.organization),
|
||||
connectedUsersByOrg
|
||||
);
|
||||
return;
|
||||
}
|
||||
const result = await UpdateLineItems(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "line updated successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Project not found": { message: "Project not found" },
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "line updated successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Project not found": { message: "Project not found" },
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const Line_Datas = status === "Success" && result?.data ? {} : undefined;
|
||||
|
||||
};
|
||||
const response = FinalResponse(
|
||||
status,
|
||||
socket,
|
||||
data.organization,
|
||||
messages,
|
||||
Line_Datas
|
||||
);
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const Line_Datas =
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = FinalResponse(status, socket, data.organization, messages, Line_Datas);
|
||||
|
||||
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.updateLine_v1Response, response, connectedUsersByOrg)
|
||||
}
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.updateLine_v1Response,
|
||||
response,
|
||||
connectedUsersByOrg
|
||||
);
|
||||
};
|
||||
export const DeleteLineHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: {
|
||||
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||
}
|
||||
) => {
|
||||
if (event !== EVENTS.deleteLine_v1 || !data?.organization) return;
|
||||
const requiredFields = [
|
||||
"uuid",
|
||||
"projectId",
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
if (event !== EVENTS.deleteLine_v1 || !data?.organization) return;
|
||||
console.log("data: ", data);
|
||||
console.log("event: ", event);
|
||||
const requiredFields = ["line", "projectId", "userId", "organization"];
|
||||
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deleteLine_v1Response,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await DeleteLineItems(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.deleteLine_v1Response,
|
||||
ErrorResponse(missingFields, socket, data.organization),
|
||||
connectedUsersByOrg
|
||||
);
|
||||
return;
|
||||
}
|
||||
const result = await DeleteLineItems(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "line deleted successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Project not found": { message: "Project not found" },
|
||||
"line not found": { message: "line not found" },
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "line deleted successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Project not found": { message: "Project not found" },
|
||||
"line not found": { message: "line not found" },
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const Line_Datas = status === "Success" && result?.data ? {} : undefined;
|
||||
|
||||
};
|
||||
const response = FinalResponse(
|
||||
status,
|
||||
socket,
|
||||
data.organization,
|
||||
messages,
|
||||
Line_Datas
|
||||
);
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const Line_Datas =
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = FinalResponse(status, socket, data.organization, messages, Line_Datas);
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deleteLine_v1Response, response, connectedUsersByOrg)
|
||||
}
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.deleteLine_v1Response,
|
||||
response,
|
||||
connectedUsersByOrg
|
||||
);
|
||||
};
|
||||
export const DeleteLayerHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: {
|
||||
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||
}
|
||||
) => {
|
||||
if (event !== EVENTS.deleteLineLayer_v1 || !data?.organization) return;
|
||||
const requiredFields = [
|
||||
"layer",
|
||||
"projectId",
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
if (event !== EVENTS.deleteLineLayer_v1 || !data?.organization) return;
|
||||
console.log("event:-layer ", event);
|
||||
const requiredFields = ["layer", "projectId", "userId", "organization"];
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deleteLineLayer_v1Response,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await DeleteLayer(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.deleteLineLayer_v1Response,
|
||||
ErrorResponse(missingFields, socket, data.organization),
|
||||
connectedUsersByOrg
|
||||
);
|
||||
return;
|
||||
}
|
||||
const result = await DeleteLayer(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "layer deleted successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Project not found": { message: "Project not found" },
|
||||
"layer not found": { message: "layer not found" },
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "layer deleted successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Project not found": { message: "Project not found" },
|
||||
"layer not found": { message: "layer not found" },
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const Line_Datas = status === "Success" && result?.data ? {} : undefined;
|
||||
|
||||
};
|
||||
const response = FinalResponse(
|
||||
status,
|
||||
socket,
|
||||
data.organization,
|
||||
messages,
|
||||
Line_Datas
|
||||
);
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const Line_Datas =
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = FinalResponse(status, socket, data.organization, messages, Line_Datas);
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deleteLineLayer_v1Response, response, connectedUsersByOrg)
|
||||
}
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.deleteLineLayer_v1Response,
|
||||
response,
|
||||
connectedUsersByOrg
|
||||
);
|
||||
};
|
||||
export const DeleteLinePointsHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: {
|
||||
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||
}
|
||||
) => {
|
||||
if (event !== EVENTS.deletePoint_v1 || !data?.organization) return;
|
||||
const requiredFields = [
|
||||
"uuid",
|
||||
"projectId",
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
if (event !== EVENTS.deletePoint_v1 || !data?.organization) return;
|
||||
console.log("event:point ", event);
|
||||
const requiredFields = ["uuid", "projectId", "userId", "organization"];
|
||||
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deletePoint_v1Response,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
return;
|
||||
}
|
||||
const result = await DeleteLinePoints(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.deletePoint_v1Response,
|
||||
ErrorResponse(missingFields, socket, data.organization),
|
||||
connectedUsersByOrg
|
||||
);
|
||||
return;
|
||||
}
|
||||
const result = await DeleteLinePoints(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "layer deleted successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Project not found": { message: "Project not found" },
|
||||
"Line not found": { message: "Line not found" },
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "point deleted successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"Project not found": { message: "Project not found" },
|
||||
"Line not found": { message: "Line not found" },
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const Line_Datas =
|
||||
status === "Success" && result?.data ? result?.data : undefined;
|
||||
|
||||
};
|
||||
const response = FinalResponse(
|
||||
status,
|
||||
socket,
|
||||
data.organization,
|
||||
messages,
|
||||
Line_Datas
|
||||
);
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const Line_Datas =
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = FinalResponse(status, socket, data.organization, messages, Line_Datas);
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deletePoint_v1Response, response, connectedUsersByOrg)
|
||||
}
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.deletePoint_v1Response,
|
||||
response,
|
||||
connectedUsersByOrg
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,34 +1,51 @@
|
||||
import { Socket, Server } from "socket.io";
|
||||
import { EVENTS } from "../../socket/events.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";
|
||||
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,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] }, callback?: Function
|
||||
connectedUsersByOrg: {
|
||||
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||
},
|
||||
callback?: Function
|
||||
) => {
|
||||
console.log('event: ', event);
|
||||
console.log("event: ", event);
|
||||
if (event !== EVENTS.addProject || !data?.organization) return;
|
||||
const requiredFields = ["projectUuid", "userId", "thumbnail", "organization"];
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.projectResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.projectResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization),
|
||||
connectedUsersByOrg
|
||||
);
|
||||
return;
|
||||
}
|
||||
console.log('data:controller ', data);
|
||||
const result = await createProject(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
const messages: Record<string, { message: string; }> = {
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "Project created successfully" },
|
||||
"user_not_found": { message: "User not found" },
|
||||
"project_exists": { message: "Project already exists" },
|
||||
user_not_found: { message: "User not found" },
|
||||
project_exists: { message: "Project already exists" },
|
||||
};
|
||||
let responseData = undefined;
|
||||
if (status === "Success" && result?.project) {
|
||||
@@ -40,25 +57,46 @@ export const projectHandleEvent = async (
|
||||
projectId: result.project._id,
|
||||
};
|
||||
}
|
||||
const response = FinalResponse(status, socket, data.organization, messages, responseData);
|
||||
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,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
connectedUsersByOrg: {
|
||||
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||
}
|
||||
) => {
|
||||
console.log('event: ', event);
|
||||
console.log("event: ", event);
|
||||
|
||||
if (event !== EVENTS.deleteProject || !data?.organization) return;
|
||||
const requiredFields = ["projectId", "userId", "organization"];
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deleteProjectResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.deleteProjectResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization),
|
||||
connectedUsersByOrg
|
||||
);
|
||||
return;
|
||||
}
|
||||
const result = await DeleteProject(data);
|
||||
@@ -74,32 +112,53 @@ export const projectDeleteHandleEvent = async (
|
||||
const projectDeleteDatas =
|
||||
status === "Success" && result?.project
|
||||
? {
|
||||
projectUuid: result.project.projectUuid,
|
||||
projectName: result.project.projectName,
|
||||
thumbnail: result.project.thumbnail,
|
||||
createdBy: result.project.createdBy,
|
||||
}
|
||||
projectUuid: result.project.projectUuid,
|
||||
projectName: result.project.projectName,
|
||||
thumbnail: result.project.thumbnail,
|
||||
createdBy: result.project.createdBy,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const response = FinalResponse(status, socket, data.organization, messages, projectDeleteDatas);
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.projectResponse, response, connectedUsersByOrg);
|
||||
}
|
||||
const response = FinalResponse(
|
||||
status,
|
||||
socket,
|
||||
data.organization,
|
||||
messages,
|
||||
projectDeleteDatas
|
||||
);
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.projectResponse,
|
||||
response,
|
||||
connectedUsersByOrg
|
||||
);
|
||||
};
|
||||
|
||||
export const projecUpdateHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
connectedUsersByOrg: {
|
||||
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||
}
|
||||
) => {
|
||||
console.log('event: ', event);
|
||||
console.log("event: ", event);
|
||||
if (event !== EVENTS.ProjectUpdate || !data?.organization) return;
|
||||
const requiredFields = ["projectId", "userId", "organization"];
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.projectUpdateResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.projectUpdateResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization),
|
||||
connectedUsersByOrg
|
||||
);
|
||||
return;
|
||||
}
|
||||
const result = await updateProject(data);
|
||||
@@ -115,46 +174,71 @@ export const projecUpdateHandleEvent = async (
|
||||
const projectDeleteDatas =
|
||||
status === "Success" && result?.data
|
||||
? {
|
||||
projectUuid: result.data.projectUuid,
|
||||
projectName: result.data.projectName,
|
||||
thumbnail: result.data.thumbnail,
|
||||
projectId: result.data._id,
|
||||
}
|
||||
projectUuid: result.data.projectUuid,
|
||||
projectName: result.data.projectName,
|
||||
thumbnail: result.data.thumbnail,
|
||||
projectId: result.data._id,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
|
||||
const response = FinalResponse(status, socket, data.organization, messages, projectDeleteDatas);
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.projectUpdateResponse, response, connectedUsersByOrg)
|
||||
|
||||
}
|
||||
const response = FinalResponse(
|
||||
status,
|
||||
socket,
|
||||
data.organization,
|
||||
messages,
|
||||
projectDeleteDatas
|
||||
);
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.projectUpdateResponse,
|
||||
response,
|
||||
connectedUsersByOrg
|
||||
);
|
||||
};
|
||||
export const DuplicateProjectHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] }, callback?: Function
|
||||
connectedUsersByOrg: {
|
||||
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||
},
|
||||
callback?: Function
|
||||
) => {
|
||||
console.log('event: ', event);
|
||||
console.log("event: ", event);
|
||||
if (event !== EVENTS.DuplicateProject || !data?.organization) return;
|
||||
const requiredFields = ["projectUuid", "projectName", "userId", "thumbnail", "organization"];
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
const requiredFields = [
|
||||
"projectUuid",
|
||||
"projectName",
|
||||
"userId",
|
||||
"thumbnail",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = validateFields(data, requiredFields);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.DuplicateprojectResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.DuplicateprojectResponse,
|
||||
ErrorResponse(missingFields, socket, data.organization),
|
||||
connectedUsersByOrg
|
||||
);
|
||||
return;
|
||||
}
|
||||
console.log('data:controller ', data);
|
||||
const result = await DuplicateProject(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
const messages: Record<string, { message: string; }> = {
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "Project Duplicated successfully" },
|
||||
"user_not_found": { message: "User not found" },
|
||||
"project_exists": { message: "Project already exists" },
|
||||
user_not_found: { message: "User not found" },
|
||||
project_exists: { message: "Project already exists" },
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error", };
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
|
||||
let projectDatas = undefined;
|
||||
if (status === "Success" && result?.project) {
|
||||
@@ -165,9 +249,20 @@ export const DuplicateProjectHandleEvent = async (
|
||||
createdBy: result.project.createdBy,
|
||||
};
|
||||
}
|
||||
const response = FinalResponse(status, socket, data.organization, messages, projectDatas);
|
||||
const response = FinalResponse(
|
||||
status,
|
||||
socket,
|
||||
data.organization,
|
||||
messages,
|
||||
projectDatas
|
||||
);
|
||||
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.DuplicateprojectResponse, response, connectedUsersByOrg)
|
||||
|
||||
}
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.DuplicateprojectResponse,
|
||||
response,
|
||||
connectedUsersByOrg
|
||||
);
|
||||
};
|
||||
|
||||
@@ -28,7 +28,6 @@ export const TrashDeleteHandleEvent = async (
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.Trash_v1DeleteResponse, response, connectedUsersByOrg)
|
||||
return;
|
||||
}
|
||||
console.log('data:controller ', data);
|
||||
const result = await TrashDelete(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
|
||||
@@ -1,169 +1,229 @@
|
||||
import { Socket, Server } from "socket.io";
|
||||
import { EVENTS } from "../../socket/events.ts";
|
||||
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||
import { AddFloat, DelFloat, DuplicateFloat } from "../../../shared/services/visualization/floatWidgetService.ts";
|
||||
import {
|
||||
AddFloat,
|
||||
DelFloat,
|
||||
DuplicateFloat,
|
||||
} from "../../../shared/services/visualization/floatWidgetService.ts";
|
||||
export const AddFloatHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: {
|
||||
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||
}
|
||||
) => {
|
||||
if (event !== EVENTS.addFloat_v1 || !data?.organization) return;
|
||||
const requiredFields = ["zoneUuid", "index", "widget", "projectId", "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.float_v1UpdateResponse, response, connectedUsersByOrg)
|
||||
return;
|
||||
}
|
||||
const result = await AddFloat(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "FloatWidget created successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"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" },
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const fload_Datas =
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
|
||||
}
|
||||
: undefined;
|
||||
if (event !== EVENTS.addFloat_v1 || !data?.organization) return;
|
||||
const requiredFields = [
|
||||
"zoneUuid",
|
||||
"widget",
|
||||
"projectId",
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = requiredFields.filter((field) => !data?.[field]);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(fload_Datas ? { data: fload_Datas } : {}),
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: data?.organization ?? "unknown",
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.float_v1UpdateResponse,
|
||||
response,
|
||||
connectedUsersByOrg
|
||||
);
|
||||
return;
|
||||
}
|
||||
const result = await AddFloat(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.float_v1UpdateResponse, response, connectedUsersByOrg)
|
||||
}
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "FloatWidget created successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"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" },
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const fload_Datas = status === "Success" && result?.data ? {} : undefined;
|
||||
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(fload_Datas ? { data: fload_Datas } : {}),
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.float_v1UpdateResponse,
|
||||
response,
|
||||
connectedUsersByOrg
|
||||
);
|
||||
};
|
||||
export const DeleteFloatHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: {
|
||||
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||
}
|
||||
) => {
|
||||
if (event !== EVENTS.deleteFloat_v1 || !data?.organization) return;
|
||||
const requiredFields = ["zoneUuid", "floatWidgetID", "projectId", "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.float_v1DeleteResponse, response, connectedUsersByOrg)
|
||||
return;
|
||||
}
|
||||
const result = await DelFloat(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "FloatingWidget deleted successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"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" },
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const fload_Datas =
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
|
||||
}
|
||||
: undefined;
|
||||
if (event !== EVENTS.deleteFloat_v1 || !data?.organization) return;
|
||||
const requiredFields = [
|
||||
"zoneUuid",
|
||||
"floatWidgetID",
|
||||
"projectId",
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = requiredFields.filter((field) => !data?.[field]);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(fload_Datas ? { data: fload_Datas } : {}),
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: data?.organization ?? "unknown",
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.float_v1DeleteResponse,
|
||||
response,
|
||||
connectedUsersByOrg
|
||||
);
|
||||
return;
|
||||
}
|
||||
const result = await DelFloat(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.float_v1DeleteResponse, response, connectedUsersByOrg)
|
||||
}
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "FloatingWidget deleted successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"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" },
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const fload_Datas = status === "Success" && result?.data ? {} : undefined;
|
||||
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(fload_Datas ? { data: fload_Datas } : {}),
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.float_v1DeleteResponse,
|
||||
response,
|
||||
connectedUsersByOrg
|
||||
);
|
||||
};
|
||||
export const DuplicateFloatHandleEvent = async (
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
||||
event: string,
|
||||
socket: Socket,
|
||||
io: Server,
|
||||
data: any,
|
||||
connectedUsersByOrg: {
|
||||
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||
}
|
||||
) => {
|
||||
if (event !== EVENTS.duplicatefloat_v1 || !data?.organization) return;
|
||||
const requiredFields = ["zoneUuid", "index", "widget", "projectId", "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.duplicatefloat_v1UpdateResponse, response, connectedUsersByOrg)
|
||||
return;
|
||||
}
|
||||
const result = await DuplicateFloat(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "duplicate FloatWidget created successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"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" },
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const fload_Datas =
|
||||
status === "Success" && result?.data
|
||||
|
||||
? {
|
||||
|
||||
}
|
||||
: undefined;
|
||||
if (event !== EVENTS.duplicatefloat_v1 || !data?.organization) return;
|
||||
const requiredFields = [
|
||||
"zoneUuid",
|
||||
"index",
|
||||
"widget",
|
||||
"projectId",
|
||||
"userId",
|
||||
"organization",
|
||||
];
|
||||
const missingFields = requiredFields.filter((field) => !data?.[field]);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(fload_Datas ? { data: fload_Datas } : {}),
|
||||
success: false,
|
||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||
status: "MissingFields",
|
||||
socketId: socket.id,
|
||||
organization: data?.organization ?? "unknown",
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.duplicatefloat_v1UpdateResponse,
|
||||
response,
|
||||
connectedUsersByOrg
|
||||
);
|
||||
return;
|
||||
}
|
||||
const result = await DuplicateFloat(data);
|
||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||
|
||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.duplicatefloat_v1UpdateResponse, response, connectedUsersByOrg)
|
||||
}
|
||||
const messages: Record<string, { message: string }> = {
|
||||
Success: { message: "duplicate FloatWidget created successfully" },
|
||||
"User not found": { message: "User not found" },
|
||||
"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" },
|
||||
};
|
||||
|
||||
const msg = messages[status] || { message: "Internal server error" };
|
||||
const fload_Datas = status === "Success" && result?.data ? {} : undefined;
|
||||
|
||||
const response = {
|
||||
success: status === "Success",
|
||||
message: msg.message,
|
||||
status,
|
||||
socketId: socket.id,
|
||||
organization: data.organization,
|
||||
...(fload_Datas ? { data: fload_Datas } : {}),
|
||||
};
|
||||
|
||||
emitToSenderAndAdmins(
|
||||
io,
|
||||
socket,
|
||||
data.organization,
|
||||
EVENTS.duplicatefloat_v1UpdateResponse,
|
||||
response,
|
||||
connectedUsersByOrg
|
||||
);
|
||||
};
|
||||
|
||||
@@ -420,7 +420,6 @@ const zoneHandleEvent = async (
|
||||
let result;
|
||||
switch (event) {
|
||||
case EVENTS.setZone: {
|
||||
// console.log("create zonedata: ", data);
|
||||
result = await setZone(data);
|
||||
|
||||
if (result) {
|
||||
|
||||
@@ -22,7 +22,6 @@ export const emitEventResponse = (
|
||||
console.log(`Organization missing in response for event: ${event}`);
|
||||
return;
|
||||
}
|
||||
console.log('result: ', result);
|
||||
|
||||
socket.to(organization).emit(event, {
|
||||
// success: result.success,
|
||||
|
||||
@@ -1,32 +1,40 @@
|
||||
import { Socket, Server } from "socket.io";
|
||||
|
||||
export const validateFields = (data: any, requiredFields: string[]): string[] => {
|
||||
return requiredFields.filter(field => !data?.[field]);
|
||||
export const validateFields = (
|
||||
data: any,
|
||||
requiredFields: string[]
|
||||
): string[] => {
|
||||
return requiredFields.filter(
|
||||
(field) => data[field] === undefined || data[field] === null
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
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 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
|
||||
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 } : {}),
|
||||
};
|
||||
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