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