diff --git a/.env b/.env index de50cf6..3bd7209 100644 --- a/.env +++ b/.env @@ -1,10 +1,14 @@ -MONGO_URI=mongodb://mongo/ -MONGO_USER=admin -MONGO_PASSWORD=admin321 +# MONGO_URI=mongodb://mongo/ +# MONGO_USER=admin +# MONGO_PASSWORD=admin321 +# MONGO_AUTH_DB=admin + +MONGO_URI=mongodb://192.168.0.110/ +MONGO_USER=mydata +MONGO_PASSWORD=mongodb@hexr2002 MONGO_AUTH_DB=admin - API_PORT=5000 SOCKET_PORT=8000 NODE_ENV=development diff --git a/src/api-server/Dockerfile b/src/api-server/Dockerfile index ca61db6..1c35ba4 100644 --- a/src/api-server/Dockerfile +++ b/src/api-server/Dockerfile @@ -3,7 +3,7 @@ ARG NODE_VERSION=lts FROM node:${NODE_VERSION}-alpine AS development # Use production node environment by default. -ENV NODE_ENV = development +ENV NODE_ENV=development WORKDIR /usr/src/app diff --git a/src/api-server/V1/v1Controllers/authController/authControllers.ts b/src/api-server/V1/v1Controllers/authController/authControllers.ts index 2a6bdb7..298dc43 100644 --- a/src/api-server/V1/v1Controllers/authController/authControllers.ts +++ b/src/api-server/V1/v1Controllers/authController/authControllers.ts @@ -12,7 +12,7 @@ export const SignupController = async ( ): Promise => { try { console.log("req.body: ", req.body); - const { userName, Email, Password, profilePicture } = req.body; + const { userName, Email, Password } = req.body; if (!userName || !Email || !Password) { res.status(400).json({ message: "All fields are required", diff --git a/src/api-server/V1/v1Controllers/builderController/v1cameraController.ts b/src/api-server/V1/v1Controllers/builderController/v1cameraController.ts index efeaf61..2d9b2db 100644 --- a/src/api-server/V1/v1Controllers/builderController/v1cameraController.ts +++ b/src/api-server/V1/v1Controllers/builderController/v1cameraController.ts @@ -13,15 +13,14 @@ export const SetNewCamera = async ( ): Promise => { try { const { organization, userId } = req.user || {}; - const { position, target, rotation, projectId, versionId } = req.body; + const { position, target, rotation, projectId} = req.body; if ( !organization || !userId || !position || !target || !rotation || - !projectId || - !versionId + !projectId ) { res.status(400).json({ message: "All fields are required", @@ -33,7 +32,6 @@ export const SetNewCamera = async ( target, rotation, projectId, - versionId, organization, userId, }; diff --git a/src/api-server/V1/v1Controllers/projectController/v1projectController.ts b/src/api-server/V1/v1Controllers/projectController/v1projectController.ts index c017ec4..79f99c1 100644 --- a/src/api-server/V1/v1Controllers/projectController/v1projectController.ts +++ b/src/api-server/V1/v1Controllers/projectController/v1projectController.ts @@ -17,7 +17,7 @@ export const createProjectController = async ( const { userId, organization } = req.user || {}; const { projectUuid, thumbnail } = req.body; - if (!req.user || !req.user.userId || !req.user.organization) { + if (!req.user?.userId || !req.user?.organization) { res.status(401).json({ message: "Unauthorized" }); return; } @@ -106,7 +106,7 @@ export const RemoveProject = async ( try { const { projectId } = req.params; const { organization, userId } = req.user || {}; - if (!req.user || !req.user.userId || !req.user.organization) { + if (!req.user?.userId || !req.user?.organization) { res.status(401).json({ message: "Unauthorized" }); return; } @@ -208,12 +208,7 @@ export const ViewData = async ( ): Promise => { try { const { organization, userId, role } = req.user || {}; - if ( - !req.user || - !req.user.userId || - !req.user.organization || - !req.user.role - ) { + if (!req.user?.userId || !req.user?.organization) { res.status(401).json({ message: "Unauthorized" }); return; } @@ -269,7 +264,7 @@ export const ProjectDuplicateController = async ( const { userId, organization } = req.user || {}; const { projectUuid, thumbnail, projectName } = req.body; - if (!req.user || !req.user.userId || !req.user.organization) { + if (!req.user?.userId || !req.user?.organization) { res.status(401).json({ message: "Unauthorized" }); return; } diff --git a/src/api-server/V1/v1Controllers/vizualizationController/v1widgetController.ts b/src/api-server/V1/v1Controllers/vizualizationController/v1widgetController.ts index a9d0b98..4be5b2c 100644 --- a/src/api-server/V1/v1Controllers/vizualizationController/v1widgetController.ts +++ b/src/api-server/V1/v1Controllers/vizualizationController/v1widgetController.ts @@ -43,6 +43,7 @@ export const AddWidgetController = async ( res.status(404).json({ message: "Zone not found", }); + break; case "panelName not found": res.status(404).json({ message: "panelName not found", @@ -179,11 +180,6 @@ export const WidgetUpdateController = async ( message: "Project not found", }); break; - case "Project not found": - res.status(404).json({ - message: "Project not found", - }); - break; case "Zone not found for the zoneId": res.status(404).json({ message: "Zone not found for the zoneId", @@ -247,11 +243,6 @@ export const GetWidgetController = async ( message: "Project not found", }); break; - case "Project not found": - res.status(404).json({ - message: "Project not found", - }); - break; case "Zone not found for the zoneId": res.status(404).json({ message: "Zone not found for the zoneId", diff --git a/src/api-server/V1/v1Routes/v1-homeRoutes.ts b/src/api-server/V1/v1Routes/v1-homeRoutes.ts index 3ae8de9..9067e2c 100644 --- a/src/api-server/V1/v1Routes/v1-homeRoutes.ts +++ b/src/api-server/V1/v1Routes/v1-homeRoutes.ts @@ -1,6 +1,5 @@ import express from "express"; import { tokenValidator } from "../../../shared/utils/token.ts"; -import authorizedRoles from "../../../shared/middleware/rbacMiddleware.ts"; import { recentDataController, searchProjectController, diff --git a/src/api-server/V1/v1Routes/v1-trashRoutes.ts b/src/api-server/V1/v1Routes/v1-trashRoutes.ts index cc9d646..9353b7e 100644 --- a/src/api-server/V1/v1Routes/v1-trashRoutes.ts +++ b/src/api-server/V1/v1Routes/v1-trashRoutes.ts @@ -1,6 +1,5 @@ import express from "express"; import { tokenValidator } from "../../../shared/utils/token.ts"; -import authorizedRoles from "../../../shared/middleware/rbacMiddleware.ts"; import { DeleteTrashData, GetTrashList, diff --git a/src/api-server/app.ts b/src/api-server/app.ts index 4f0f83c..3b93ecd 100644 --- a/src/api-server/app.ts +++ b/src/api-server/app.ts @@ -35,7 +35,7 @@ import v1PanelRoutes from "./V1/v1Routes/vizRoutes.ts/v1-panelRoutes.ts"; import v1Template from "./V1/v1Routes/vizRoutes.ts/v1-TemplateRoutes.ts"; import v1Widget from "./V1/v1Routes/vizRoutes.ts/v1-widgetRoutes.ts"; import v1Widget3d from "./V1/v1Routes/vizRoutes.ts/v1-widget3dRoutes.ts"; -redis; +redis const app = express(); app.use(cors()); diff --git a/src/shared/V1Models/Auth/tokenModel.ts b/src/shared/V1Models/Auth/tokenModel.ts index 30ed6fa..ff70443 100644 --- a/src/shared/V1Models/Auth/tokenModel.ts +++ b/src/shared/V1Models/Auth/tokenModel.ts @@ -3,7 +3,7 @@ import MainModel from "../../connect/mongoose.ts"; import { User } from "./userAuthModel.ts"; export interface Token extends Document { userId: User["_id"]; - isArchive: Boolean; + isArchive: boolean; refreshToken: string; resetTokenExpiry?: Date; resetToken: string; diff --git a/src/shared/V1Models/Builder/cameraModel.ts b/src/shared/V1Models/Builder/cameraModel.ts index 183430a..232400f 100644 --- a/src/shared/V1Models/Builder/cameraModel.ts +++ b/src/shared/V1Models/Builder/cameraModel.ts @@ -13,14 +13,14 @@ export interface Camera extends Document { z: number; }; target: { - x: { type: Number; required: true }; - y: { type: Number; required: true }; - z: { type: Number; required: true }; + x: { type: number; required: true }; + y: { type: number; required: true }; + z: { type: number; required: true }; }; rotation: { - x: { type: Number; required: true }; - y: { type: Number; required: true }; - z: { type: Number; required: true }; + x: { type: number; required: true }; + y: { type: number; required: true }; + z: { type: number; required: true }; }; } diff --git a/src/shared/V1Models/Simulation/eventsDataModel.ts b/src/shared/V1Models/Simulation/eventsDataModel.ts index 7fea568..24d5739 100644 --- a/src/shared/V1Models/Simulation/eventsDataModel.ts +++ b/src/shared/V1Models/Simulation/eventsDataModel.ts @@ -125,12 +125,12 @@ interface StorageEventSchema extends AssetEventSchema { point: StoragePointSchema; } interface IPointModel extends Document { - modelUuid: String; - modelName: String; - position: String; - rotation: String; - state: String; - productId: String; + modelUuid: string; + modelName: string; + position: [number]; + rotation: [number]; + state: string; + productId: string; isArchive: boolean; type: "transfer" | "vehicle" | "roboticArm" | "machine" | "storageUnit"; speed: number; diff --git a/src/shared/V1Models/Thread/thread-Model.ts b/src/shared/V1Models/Thread/thread-Model.ts index dc6be7c..b654b30 100644 --- a/src/shared/V1Models/Thread/thread-Model.ts +++ b/src/shared/V1Models/Thread/thread-Model.ts @@ -6,7 +6,7 @@ import MainModel from "../../connect/mongoose.ts"; interface IComment { userId: User["_id"]; comment: string; - timestamp:Number + timestamp:number } export interface IThread extends Document { projectId: Project["_id"]; diff --git a/src/shared/V1Models/Vizualization/3dwidget.ts b/src/shared/V1Models/Vizualization/3dwidget.ts index 6e84c6d..a916fd8 100644 --- a/src/shared/V1Models/Vizualization/3dwidget.ts +++ b/src/shared/V1Models/Vizualization/3dwidget.ts @@ -1,4 +1,4 @@ -import { Schema, Document, model } from "mongoose"; +import { Schema, Document } from "mongoose"; import MainModel from "../../connect/mongoose.ts"; import { Zone } from "../Builder/zoneModel.ts"; export interface Widget3d extends Document { @@ -8,7 +8,7 @@ export interface Widget3d extends Document { position: []; rotation: []; isArchive: boolean; - zoneId: string; + zoneId: Zone["_id"]; Data: { measurements: {}; duration: string; @@ -21,7 +21,7 @@ const Widget3dSchema: Schema = new Schema( widgetName: { type: String, default: "Widget3D" }, position: { type: Array }, rotation: { type: Array }, - zoneId: { type: String }, + zoneId:{ type: Schema.Types.ObjectId, ref: "Zone" }, Data: { measurements: { type: Object, default: {} }, duration: { type: String, default: "1h" }, diff --git a/src/shared/V1Models/Vizualization/floatWidget.ts b/src/shared/V1Models/Vizualization/floatWidget.ts index cb2712a..54044ce 100644 --- a/src/shared/V1Models/Vizualization/floatWidget.ts +++ b/src/shared/V1Models/Vizualization/floatWidget.ts @@ -1,5 +1,5 @@ -import { Schema, Document, model } from "mongoose"; -import MainModel from "../../connect/mongoose.ts"; +import { Schema, Document } from "mongoose"; +import MainModel from "../../connect/mongoose.ts"; import { Zone } from "../Builder/zoneModel.ts"; export interface FloatingWidget extends Document { className: string; @@ -10,7 +10,7 @@ export interface FloatingWidget extends Document { per: string; value: string; isArchive: boolean; - zoneId: string; + zoneId: Zone["_id"]; Data: { measurements: {}; duration: string; @@ -25,7 +25,7 @@ const floatingWidgetSchema: Schema = new Schema( position: { type: Object }, per: { type: String }, value: { type: String }, - zoneId: { type: String }, + zoneId: { type: Schema.Types.ObjectId, ref: "Zone" }, Data: { measurements: { type: Object, default: {} }, duration: { type: String, default: "1h" }, diff --git a/src/shared/V1Models/Vizualization/panelmodel.ts b/src/shared/V1Models/Vizualization/panelmodel.ts index 78ab7ea..259cd94 100644 --- a/src/shared/V1Models/Vizualization/panelmodel.ts +++ b/src/shared/V1Models/Vizualization/panelmodel.ts @@ -2,14 +2,14 @@ import mongoose, { Schema, Document } from "mongoose"; import MainModel from "../../connect/mongoose.ts"; import { Zone } from "../Builder/zoneModel.ts"; export interface Panel extends Document { - zoneId: string; + zoneId: Zone["_id"]; panelName: string; widgets: [mongoose.Types.ObjectId]; isArchive: boolean; } const panelSchema: Schema = new Schema( { - zoneId: { type: String }, + zoneId: { type: Schema.Types.ObjectId, ref: "Zone" }, panelName: { type: String }, widgets: [{ type: mongoose.Schema.Types.ObjectId, ref: "Widget" }], isArchive: { type: Boolean, default: false }, diff --git a/src/shared/V1Models/Vizualization/widgemodel.ts b/src/shared/V1Models/Vizualization/widgemodel.ts index cfe5e11..5bc8906 100644 --- a/src/shared/V1Models/Vizualization/widgemodel.ts +++ b/src/shared/V1Models/Vizualization/widgemodel.ts @@ -1,7 +1,7 @@ import mongoose, { Schema, Document } from "mongoose"; import MainModel from "../../connect/mongoose.ts"; import { Zone } from "../Builder/zoneModel.ts"; -export interface widget extends Document { +export interface Widget extends Document { widgetName: string; widgetside: string; widgetID: string; @@ -17,7 +17,7 @@ export interface widget extends Document { measurements: {}; duration: string; }; - zoneId: string; + zoneId: Zone["_id"]; } const widgetSchema: Schema = new Schema( { @@ -36,7 +36,7 @@ const widgetSchema: Schema = new Schema( fontWeight: { type: String }, isArchive: { type: Boolean, default: false }, panelID: { type: mongoose.Schema.Types.ObjectId, ref: "Panel" }, - zoneId: { type: String }, + zoneId: { type: Schema.Types.ObjectId, ref: "Zone" }, }, { timestamps: true } ); diff --git a/src/shared/connect/mongoose.ts b/src/shared/connect/mongoose.ts index 9e0b411..0200f84 100644 --- a/src/shared/connect/mongoose.ts +++ b/src/shared/connect/mongoose.ts @@ -1,5 +1,4 @@ import mongoose, { Schema, Connection, Model } from "mongoose"; -import { Client } from "minio"; interface ConnectionCache { [key: string]: Connection; } diff --git a/src/shared/middleware/rbacMiddleware.ts b/src/shared/middleware/rbacMiddleware.ts index 3a7497a..18ba11d 100644 --- a/src/shared/middleware/rbacMiddleware.ts +++ b/src/shared/middleware/rbacMiddleware.ts @@ -1,4 +1,4 @@ -import { Response, Request, NextFunction } from "express"; +import { Response, NextFunction } from "express"; import { AuthenticatedRequest } from "../../shared/utils/token.ts"; type Role = "Admin" | "User"; const authorizedRoles = (...allowedRoles: Role[]) => { diff --git a/src/shared/services/Thread/ThreadService.ts b/src/shared/services/Thread/ThreadService.ts index 1f4fff7..b4345b5 100644 --- a/src/shared/services/Thread/ThreadService.ts +++ b/src/shared/services/Thread/ThreadService.ts @@ -20,7 +20,7 @@ interface IThread { } export const createThread = async (data: IThread) => { try { - const { projectId, versionId, state, userId, position, rotation, comments, organization, threadId } = data + const { projectId, state, userId, position, rotation, comments, organization } = data const userExisting = await existingUser(userId, organization); if (!userExisting) { return { @@ -38,7 +38,6 @@ export const createThread = async (data: IThread) => { } const newThread = await ThreadModel(organization).create({ projectId, - versionId, state, createdBy: userId, position, @@ -58,7 +57,7 @@ export const createThread = async (data: IThread) => { } export const deleteThread = async (data: IThread) => { try { - const { projectId, versionId, state, userId, organization, threadId } = data + const { projectId, userId, organization, threadId } = data const userExisting = await existingUser(userId, organization); if (!userExisting) { return { @@ -92,7 +91,7 @@ export const deleteThread = async (data: IThread) => { } export const addComments = async (data: IThread) => { try { - const { projectId, versionId, userId, comments, organization, threadId } = data + const { projectId, userId, comments, organization, threadId } = data const userExisting = await existingUser(userId, organization); if (!userExisting) { return { @@ -125,7 +124,7 @@ export const addComments = async (data: IThread) => { } export const deleteComments = async (data: IThread) => { try { - const { projectId, versionId, userId, commentId, organization, threadId } = data + const { projectId, userId, commentId, organization, threadId } = data const userExisting = await existingUser(userId, organization); if (!userExisting) { return { diff --git a/src/shared/services/auth/authServices.ts b/src/shared/services/auth/authServices.ts index 50060dc..a97c748 100644 --- a/src/shared/services/auth/authServices.ts +++ b/src/shared/services/auth/authServices.ts @@ -64,7 +64,7 @@ export const AuthSignup = async ( Email: caseChange, Password: hashPassword, }); - const UserDatas = await UsersDataModel(organization).create({ + await UsersDataModel(organization).create({ userId: newuser._id, role: role, isShare: isShare, @@ -449,7 +449,7 @@ async function handleTokenCache( isArchive: false, }); if (!tokenDoc) { - tokenDoc = await tokenType(organization).create({ userId, refreshToken }); + await tokenType(organization).create({ userId, refreshToken }); } else { await tokenType(organization).findByIdAndUpdate( tokenDoc._id, diff --git a/src/shared/services/builder/assetService.ts b/src/shared/services/builder/assetService.ts index a49efee..ad7c0df 100644 --- a/src/shared/services/builder/assetService.ts +++ b/src/shared/services/builder/assetService.ts @@ -6,7 +6,7 @@ import { existingUser, } from "../helpers/v1projecthelperFns.ts"; -interface setAssetInput { +interface SetAssetInput { modelUuid: string; modelName: string; position: []; @@ -50,7 +50,7 @@ interface ReplaceEventInput { modelUuid: string; } export const setAssetModel = async ( - data: setAssetInput + data: SetAssetInput ): Promise<{ status: string; data?: Object }> => { try { const { @@ -286,7 +286,7 @@ export const deleteAssetModel = async ( status: "Failed to archive asset", }; } - const updatedEvents = await EventsDataModel(organization).updateMany( + await EventsDataModel(organization).updateMany( { modelUuid, productId: projectId }, { $set: { isArchive: true } } ); @@ -342,7 +342,7 @@ export const replaceEventDatas = async ( { modelUuid, projectId, isArchive: false }, { points: typedEventData?.points, - type: typedEventData?.type || existingModel?.type, + type: typedEventData?.type ?? existingModel?.type, }, { new: true } ); diff --git a/src/shared/services/builder/cameraService.ts b/src/shared/services/builder/cameraService.ts index abfa56c..3814b08 100644 --- a/src/shared/services/builder/cameraService.ts +++ b/src/shared/services/builder/cameraService.ts @@ -11,7 +11,6 @@ interface IcameraData { rotation: Object; organization: string; projectId: string; - versionId: string; } interface IgetCameras { organization: string; @@ -32,8 +31,7 @@ export const SetCamera = async ( target, rotation, organization, - projectId, - versionId, + projectId } = data; const UserExists = await existingUser(userId, organization); if (!UserExists) return { status: "User not found" }; @@ -52,7 +50,6 @@ export const SetCamera = async ( { userId: userId, projectId: projectId, - versionId: versionId, isArchive: false, }, { position: position, target: target, rotation: rotation }, @@ -66,7 +63,6 @@ export const SetCamera = async ( const newCamera = await cameraModel(organization).create({ userId, projectId, - versionId, position, target, rotation, diff --git a/src/shared/services/home/homeService.ts b/src/shared/services/home/homeService.ts index 1ce4442..d4bb2be 100644 --- a/src/shared/services/home/homeService.ts +++ b/src/shared/services/home/homeService.ts @@ -14,7 +14,7 @@ interface IProject { createdAt: Date; isViewed?: number; } -interface searchProjectInterface { +interface SearchProjectInterface { searchName: string; userId: string; organization: string; @@ -50,7 +50,7 @@ export const RecentlyAdded = async (data: IRecentData) => { return { status: error }; } }; -export const searchProject = async (data: searchProjectInterface) => { +export const searchProject = async (data: SearchProjectInterface) => { try { const { userId, organization, searchName } = data; const userExisting = await existingUser(userId, organization); @@ -66,7 +66,7 @@ export const searchProject = async (data: searchProjectInterface) => { return { status: error }; } }; -export const searchTrashProject = async (data: searchProjectInterface) => { +export const searchTrashProject = async (data: SearchProjectInterface) => { try { const { userId, organization, searchName } = data; const userExisting = await existingUser(userId, organization); diff --git a/src/shared/services/project/project-Services.ts b/src/shared/services/project/project-Services.ts index a0951bc..0d6d7b1 100644 --- a/src/shared/services/project/project-Services.ts +++ b/src/shared/services/project/project-Services.ts @@ -4,7 +4,6 @@ import versionModel from "../../model/version/versionModel.ts"; import { existingProject, existingUser, - archiveProject, previousVersion, generateUntitledProjectName, } from "../helpers/ProjecthelperFn.ts"; @@ -16,7 +15,7 @@ interface CreateProjectInput { sharedUsers?: string[]; organization: string; } -interface updateProjectInput { +interface UpdateProjectInput { projectName: string; projectId: string; userId: string; @@ -130,7 +129,7 @@ export const DeleteProject = async (data: ProjectInterface) => { return { status: error }; } }; -export const updateProject = async (data: updateProjectInput) => { +export const updateProject = async (data: UpdateProjectInput) => { try { const { projectId, organization, userId, projectName, thumbnail } = data; const ExistingUser = await existingUser(userId, organization); @@ -141,8 +140,8 @@ export const updateProject = async (data: updateProjectInput) => { isArchive: false, }); if (!existingProject) return { status: "Project not found" }; - if (projectName !== undefined) projectName; - if (thumbnail !== undefined) thumbnail; + if (projectName !== undefined) existingProject.projectName=projectName; + if (thumbnail !== undefined) existingProject.thumbnail=thumbnail; const updateProject = await projectModel(organization) .findOneAndUpdate( { _id: projectId, isArchive: false }, diff --git a/src/shared/services/simulation/productService.ts b/src/shared/services/simulation/productService.ts index 2e7463e..ed58f7c 100644 --- a/src/shared/services/simulation/productService.ts +++ b/src/shared/services/simulation/productService.ts @@ -12,8 +12,8 @@ interface Iproduct { eventDatas: { modelUuid: string; modelName: string; - position: [Number]; - rotation: [Number]; + position: [number]; + rotation: [number]; type: string; speed: string; point: Mixed; diff --git a/src/shared/services/trash/trashService.ts b/src/shared/services/trash/trashService.ts index 0a9b58d..f2d78dc 100644 --- a/src/shared/services/trash/trashService.ts +++ b/src/shared/services/trash/trashService.ts @@ -1,5 +1,4 @@ import projectModel from "../../model/project/project-model.ts"; -import { existingUser } from "../helpers/v1projecthelperFns.ts"; interface IOrg { organization: string; } diff --git a/src/shared/services/v1Project/v1projectservice.ts b/src/shared/services/v1Project/v1projectservice.ts index 79220be..55c07b7 100644 --- a/src/shared/services/v1Project/v1projectservice.ts +++ b/src/shared/services/v1Project/v1projectservice.ts @@ -3,7 +3,6 @@ import versionModel from "../../V1Models/Version/versionModel.ts"; import { existingProject, existingUser, - archiveProject, previousVersion, generateUntitledProjectName, } from "../helpers/v1projecthelperFns.ts"; @@ -11,7 +10,7 @@ import UsersDataModel from "../../V1Models/Auth/user.ts"; interface CreateProjectInput { projectName: string; projectUuid: string; - userId: string; + userId: string; thumbnail?: string; sharedUsers?: string[]; organization: string; @@ -19,15 +18,15 @@ interface CreateProjectInput { interface IProjectDuplicate { projectName: string; projectUuid: string; - userId: string; + userId: string; thumbnail?: string; sharedUsers?: string[]; organization: string; } -interface updateProjectInput { +interface UpdateProjectInput { projectName: string; projectId: string; - userId: string; + userId: string; thumbnail?: string; sharedUsers?: string[]; organization: string; @@ -112,7 +111,7 @@ export const createProject = async (data: CreateProjectInput) => { export const GetAllProjects = async (data: GetProjectsInterface) => { try { - const { userId, organization, role } = data; + const { userId, organization } = data; await existingUser(userId, organization); if (!existingUser) return { status: "User not found" }; let filter = { isArchive: false } as RoleFilter; @@ -147,9 +146,9 @@ export const DeleteProject = async (data: ProjectDelInterface) => { return { status: error }; } }; -export const updateProject = async (data: updateProjectInput) => { +export const updateProject = async (data: UpdateProjectInput) => { try { - const { projectId, organization, userId, projectName, thumbnail, role } = + const { projectId, organization, userId, projectName, thumbnail } = data; const ExistingUser = await existingUser(userId, organization); if (!ExistingUser) return { status: "User not found" }; @@ -157,8 +156,8 @@ export const updateProject = async (data: updateProjectInput) => { const existingProject = await projectModel(organization).findOne(filter); if (!existingProject) return { status: "Project not found" }; - if (projectName !== undefined) projectName; - if (thumbnail !== undefined) thumbnail; + if (projectName !== undefined) existingProject.projectName = projectName; + if (thumbnail !== undefined) existingProject.thumbnail = thumbnail; const updateProject = await projectModel(organization) .findOneAndUpdate( filter, @@ -231,7 +230,7 @@ export const DuplicateProject = async (data: IProjectDuplicate) => { const maxLength: number = 6; export const viewProject = async (data: ProjectInterface) => { try { - const { projectId, organization, userId, role } = data; + const { projectId, organization, userId } = data; const userExisting = await existingUser(userId, organization); if (!userExisting) return { status: "User not found" }; const RecentUserDoc = await UsersDataModel(organization).findOne({ @@ -257,7 +256,7 @@ export const viewProject = async (data: ProjectInterface) => { newArr.pop(); } } - const datas = await UsersDataModel(organization).findOneAndUpdate( + await UsersDataModel(organization).findOneAndUpdate( { userId: userId, isArchive: false }, { recentlyViewed: newArr }, { new: true } diff --git a/src/shared/services/v1home/v1homeservice.ts b/src/shared/services/v1home/v1homeservice.ts index a314cb9..5744a77 100644 --- a/src/shared/services/v1home/v1homeservice.ts +++ b/src/shared/services/v1home/v1homeservice.ts @@ -15,18 +15,14 @@ interface IProject { createdAt: Date; isViewed?: number; } -interface searchProjectInterface { +interface SearchProjectInterface { searchName: string; userId: string; organization: string; } -interface RoleFilter { - isArchive: boolean; - createdBy?: string; -} export const RecentlyAdded = async (data: IRecentData) => { try { - const { userId, organization, role } = data; + const { userId, organization } = data; const userExisting = await existingUser(userId, organization); if (!userExisting) return { status: "User not found" }; const userRecentData = await UsersDataModel(organization) @@ -54,7 +50,7 @@ export const RecentlyAdded = async (data: IRecentData) => { return { status: error }; } }; -export const searchProject = async (data: searchProjectInterface) => { +export const searchProject = async (data: SearchProjectInterface) => { try { const { userId, organization, searchName } = data; const userExisting = await existingUser(userId, organization); @@ -70,7 +66,7 @@ export const searchProject = async (data: searchProjectInterface) => { return { status: error }; } }; -export const searchTrashProject = async (data: searchProjectInterface) => { +export const searchTrashProject = async (data: SearchProjectInterface) => { try { const { userId, organization, searchName } = data; const userExisting = await existingUser(userId, organization); diff --git a/src/shared/services/v1trash/v1trashservice.ts b/src/shared/services/v1trash/v1trashservice.ts index ad8d788..ca225b5 100644 --- a/src/shared/services/v1trash/v1trashservice.ts +++ b/src/shared/services/v1trash/v1trashservice.ts @@ -17,7 +17,7 @@ interface RoleFilter { } export const TrashDatas = async (data: IOrg) => { try { - const { organization, role, userId } = data; + const { organization, userId } = data; let filter = { isArchive: true, isDeleted: false } as RoleFilter; const UserExists = await existingUser(userId, organization); @@ -56,7 +56,7 @@ export const TrashDatas = async (data: IOrg) => { }; export const RestoreTrashData = async (data: IRestore) => { try { - const { projectId, organization, role, userId } = data; + const { projectId, organization, userId } = data; const UserExists = await existingUser(userId, organization); if (!UserExists) return { status: "User not found" }; let filter = { isArchive: true, _id: projectId } as RoleFilter; diff --git a/src/shared/services/visualization/floatWidgetService.ts b/src/shared/services/visualization/floatWidgetService.ts index 43cf79e..e4db81e 100644 --- a/src/shared/services/visualization/floatWidgetService.ts +++ b/src/shared/services/visualization/floatWidgetService.ts @@ -171,13 +171,13 @@ export const DelFloat = async (data: IDelFloat): Promise => { try { const { organization, floatWidgetID, zoneId, projectId, userId } = data; const UserExists = await existingUser(userId, organization); - if (!UserExists) return { status: "User not found" }; - const LivingProject = await existingProjectById( + if (!UserExists) { return { status: "User not found" } } + const LivingProject = await existingProjectById( projectId, organization, userId ); - if (!LivingProject) return { status: "Project not found" }; + if (!LivingProject) { return { status: "Project not found" } } const existingZone = await zoneModel(organization).findOne({ zoneId: zoneId, isArchive: false, @@ -224,13 +224,13 @@ export const DuplicateFloat = async ( try { const { organization, widget, zoneId, index, projectId, userId } = data; const UserExists = await existingUser(userId, organization); - if (!UserExists) return { status: "User not found" }; - const LivingProject = await existingProjectById( + if (!UserExists) {return { status: "User not found" }}; + const LivingProject = await existingProjectById( projectId, organization, userId ); - if (!LivingProject) return { status: "Project not found" }; + if (!LivingProject) {return { status: "Project not found" }}; const existingZone = await zoneModel(organization).findOne({ zoneId: zoneId, isArchive: false, @@ -332,13 +332,13 @@ export const GetFloatWidget = async (data: IGetZoneFloat): Promise => { try { const { organization, zoneId, projectId, userId } = data; const UserExists = await existingUser(userId, organization); - if (!UserExists) return { status: "User not found" }; - const LivingProject = await existingProjectById( + if (!UserExists) {return { status: "User not found" }} + const LivingProject = await existingProjectById( projectId, organization, userId ); - if (!LivingProject) return { status: "Project not found" }; + if (!LivingProject) {return { status: "Project not found" }}; const existingZone = await zoneModel(organization).findOne({ zoneId: zoneId, isArchive: false, @@ -388,7 +388,7 @@ export const SingleFloatWidget = async ( const { organization, floatWidgetID, userId } = data; const UserExists = await existingUser(userId, organization); if (!UserExists) return { status: "User not found" }; - + const widgetData = await floatWidgetModel(organization) .findOne({ floatWidgetID: floatWidgetID, diff --git a/src/shared/services/visualization/panelService.ts b/src/shared/services/visualization/panelService.ts index 09bad2c..70e5968 100644 --- a/src/shared/services/visualization/panelService.ts +++ b/src/shared/services/visualization/panelService.ts @@ -88,7 +88,7 @@ export const AddPanel = async (data: IAddPanel): Promise => { if (!zoneAndPanelData) { return zoneAndPanelData; } - return { status: "Success", data: zoneAndPanelData }; + return { status: "Success", data: createdPanels }; } catch (error: unknown) { if (error instanceof Error) { return { diff --git a/src/shared/services/visualization/templateService.ts b/src/shared/services/visualization/templateService.ts index 650e6ec..b9e18de 100644 --- a/src/shared/services/visualization/templateService.ts +++ b/src/shared/services/visualization/templateService.ts @@ -47,13 +47,13 @@ export const AddTemplate = async (data: IAddTemplate): Promise => { try { const { organization, template, projectId, userId } = data; const UserExists = await existingUser(userId, organization); - if (!UserExists) return { status: "User not found" }; + if (!UserExists) {return { status: "User not found" }}; const LivingProject = await existingProjectById( projectId, organization, userId ); - if (!LivingProject) return { status: "Project not found" }; + if (!LivingProject) {return { status: "Project not found" }}; const existingTemplate = await templateModel(organization).findOne({ templateID: template.id, isArchive: false, diff --git a/src/shared/utils/mongosecurity.ts b/src/shared/utils/mongosecurity.ts index c641a00..7b639b4 100644 --- a/src/shared/utils/mongosecurity.ts +++ b/src/shared/utils/mongosecurity.ts @@ -16,7 +16,6 @@ export default async function mongoAdminCreation() { .findOne({ user: user.user }); if (userExists) { - console.log(`User ${user} already exists`); return; } diff --git a/src/socket-server/controllers/builderController/environment-Controller.ts b/src/socket-server/controllers/builderController/environment-Controller.ts index adf08e8..e3badc1 100644 --- a/src/socket-server/controllers/builderController/environment-Controller.ts +++ b/src/socket-server/controllers/builderController/environment-Controller.ts @@ -1,7 +1,6 @@ import { Socket, Server } from "socket.io"; import { EVENTS } from "../../socket/events.ts"; import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts"; -import { SetCamera } from "../../../shared/services/builder/cameraService.ts"; import { setEnvironment } from "../../../shared/services/builder/EnvironmentService.ts"; export const setEnvironmentHandleEvent = async ( event: string, diff --git a/src/socket-server/controllers/thread/threadController.ts b/src/socket-server/controllers/thread/threadController.ts index 98322b6..e445d20 100644 --- a/src/socket-server/controllers/thread/threadController.ts +++ b/src/socket-server/controllers/thread/threadController.ts @@ -1,4 +1,4 @@ -import { Socket, Server } from "socket.io"; +import { Socket } from "socket.io"; import { EVENTS } from "../../socket/events.ts"; import { emitEventResponse } from "../../utils/emitEventResponse.ts"; import { addComments, createThread, deleteComments, deleteThread } from "../../../shared/services/Thread/ThreadService.ts"; diff --git a/src/socket-server/controllers/trashController/trash-Controller.ts b/src/socket-server/controllers/trashController/trash-Controller.ts index e563a68..4d18232 100644 --- a/src/socket-server/controllers/trashController/trash-Controller.ts +++ b/src/socket-server/controllers/trashController/trash-Controller.ts @@ -2,8 +2,6 @@ import { Socket, Server } from "socket.io"; import { EVENTS } from "../../socket/events.ts"; import { emitEventResponse, emitToSenderAndAdmins, } from "../../utils/emitEventResponse.ts"; import { - TrashDatas, - RestoreTrashData, TrashDelete, } from "../../../shared/services/v1trash/v1trashservice.ts"; export const TrashDeleteHandleEvent = async ( diff --git a/src/socket-server/controllers/vizualizationController/3dWidget-Controller.ts b/src/socket-server/controllers/vizualizationController/3dWidget-Controller.ts index 2dd5326..b6c33a5 100644 --- a/src/socket-server/controllers/vizualizationController/3dWidget-Controller.ts +++ b/src/socket-server/controllers/vizualizationController/3dWidget-Controller.ts @@ -103,15 +103,7 @@ export const update3DHandleEvent = async ( status === "Success" && result?.data ? { - // const updateDatas = { - // widget: { - // id: update3dwidget.widgetID, - // type: update3dwidget.type, - // position: update3dwidget.position, - // rotation: update3dwidget.rotation, - // }, - // zoneId: zoneId, - // }; + } : undefined; @@ -165,10 +157,7 @@ export const Delete3DwidgetHandleEvent = async ( status === "Success" && result?.data ? { - // const delete_Datas = { - // zoneId: zoneId, - // id: existing3Dwidget.widgetID, - // }; + } : undefined; diff --git a/src/socket-server/index.ts b/src/socket-server/index.ts index 83df8ce..07a76c2 100644 --- a/src/socket-server/index.ts +++ b/src/socket-server/index.ts @@ -1,7 +1,7 @@ import express, { Response, Request } from "express"; import http from "http"; import dotenv from "dotenv"; - +import { Server } from "socket.io"; dotenv.config(); import { SocketServer } from "./manager/manager.ts"; @@ -13,10 +13,15 @@ const server = http.createServer(app); app.get("/", (req: Request, res: Response) => { res.send("Hello, I am Major-Dwinzo RealTime!"); }); -initSocketServer(server); +const io = new Server(server, { + cors: { + origin: "*", + methods: ["GET", "POST"] + } +}); - -SocketServer(server); +initSocketServer(io); +SocketServer(io); server.listen(PORT, () => { console.log(`socket-Server is running on http://localhost:${PORT}`); diff --git a/src/socket-server/manager/manager.ts b/src/socket-server/manager/manager.ts index 0c6506e..5a96ff0 100644 --- a/src/socket-server/manager/manager.ts +++ b/src/socket-server/manager/manager.ts @@ -27,22 +27,16 @@ interface UserSocketInfo { } const connectedUsersByOrg: { [organization: string]: UserSocketInfo[] } = {}; -export const SocketServer = (httpServer: any) => { - const io = new Server(httpServer, { - cors: { - origin: '*', - methods: ['GET', 'POST'], - }, - }); - +export const SocketServer = (io: Server) => { + const namespaces = { dashboard: io.of('/dashboard'), project: io.of('/project'), thread: io.of('/thread'), - Builder: io.of("/Builder"), - visualization: io.of("/Visualization"), + Builder: io.of("/BuilderToken"), + visualization: io.of("/VisualizationToken"), }; @@ -126,6 +120,7 @@ export const SocketServer = (httpServer: any) => { } socket.onAny((event: string, data: any, callback: any) => { + console.log('data: dahbord', data); eventHandlers.forEach(handler => handler(event, socket, io, data, connectedUsersByOrg, callback) ); diff --git a/src/socket-server/socket/socketManager.ts b/src/socket-server/socket/socketManager.ts index 204542f..7340d94 100644 --- a/src/socket-server/socket/socketManager.ts +++ b/src/socket-server/socket/socketManager.ts @@ -971,18 +971,13 @@ interface UserSocketInfo { const connectedUsersByOrg: { [organization: string]: UserSocketInfo[] } = {}; -export const initSocketServer = (httpServer: any) => { - const io = new Server(httpServer, { - cors: { - origin: "*", - methods: ["GET", "POST"], - }, - }); +export const initSocketServer = (io: Server) => { + const namespaces = { Builder: io.of("/Builder"), visualization: io.of("/Visualization"), - project: io.of("/project"), + project: io.of("/projectPublic"), }; const onlineUsers: { [organization: string]: Set } = {}; @@ -999,7 +994,7 @@ namespace.use((socket: Socket, next: (err?: Error) => void) => { console.log("No token provided"); } - next(); + next(); }); namespace.on("connection", async (socket: Socket) => { @@ -1019,6 +1014,7 @@ namespace.use((socket: Socket, next: (err?: Error) => void) => { userStatus(EVENTS.connection, socket, socket.handshake.auth, socket); socket.onAny((event: string, data: any, callback: any) => { + console.log('data: socketmanager', data); eventHandlers.forEach((handler) => handler(event, socket, data, namespace, io, callback) );