merged with main branch to clear the testing commits

This commit is contained in:
2025-06-02 11:22:06 +05:30
107 changed files with 1344 additions and 2364 deletions

View File

@@ -39,7 +39,6 @@ const UserDataSchema: Schema = new Schema({
},
profilePicture: {
type: String,
// default: "default-profile-picture.jpg"
},
});

View File

@@ -21,7 +21,6 @@ const AuthSchema: Schema = new Schema({
Password: {
type: String,
min: 8,
// required: true,
},
isArchive: { type: Boolean, default: false },
lastPasswordReset: { type: Number },

View File

@@ -31,7 +31,7 @@ export interface AssetData extends Document {
type: string;
isVisible: boolean;
isArchive: false;
// points: [] | {};
position: [];
rotation: {
x: number;

View File

@@ -1,26 +1,24 @@
import mongoose, { Schema } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
import { User } from "../Auth/userAuthModel.ts";
import { Project } from "../Project/project-model.ts";
import { Version } from "../Version/versionModel.ts";
import { User } rom "../Version/versionModel.ts";
const positionSchema = new mongoose.Schema({
x: { type: Number }, // Optional position fields
x: { type: Number },
y: { type: Number },
z: { type: Number },
});
const Vector3 = new mongoose.Schema({
position: { type: positionSchema, required: false }, // Optional position
uuid: { type: String, required: false }, // Optional uuid
position: { type: positionSchema, required: false },
uuid: { type: String, required: false },
});
const LineSchema = new mongoose.Schema({
userId: { type: Schema.Types.ObjectId, ref: "User" },
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
layer: { type: Number, required: true }, // Layer is mandatory
line: { type: [Vector3], required: true }, // Array of line objects
type: { type: String, required: false }, // Optional type
layer: { type: Number, required: true },
line: { type: [Vector3], required: true },
type: { type: String, required: false },
});
const lineModel = (db: string) => {

View File

@@ -38,8 +38,6 @@ const zoneSchema: Schema = new Schema(
default: [],
enum: ["left", "right", "top", "bottom"],
},
// createdBy: { type: mongoose.Schema.Types.ObjectId, ref: "User" },
// sceneID: { type: mongoose.Schema.Types.ObjectId, ref: "Scene" },
},
{ timestamps: true }
);

View File

@@ -1,4 +1,3 @@
// models/Product.ts
import { Schema, Document } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
@@ -118,13 +117,11 @@ interface RoboticArmEventSchema extends AssetEventSchema {
interface MachineEventSchema extends AssetEventSchema {
type: "machine";
// speed: number;
point: MachinePointSchema;
}
interface StorageEventSchema extends AssetEventSchema {
type: "storageUnit";
// speed: number;
point: StoragePointSchema;
}
interface IPointModel extends Document {
@@ -144,7 +141,6 @@ interface IPointModel extends Document {
| StorageEventSchema;
points: ConveyorEventSchema[];
}
// type EventsSchema = ConveyorEventSchema | VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema;
const BaseEventSchema = new Schema<IPointModel>(
{

View File

@@ -5,9 +5,7 @@ import { Version } from "../Version/versionModel.ts";
import MainModel from "../../connect/mongoose.ts";
interface IComment {
userId: User["_id"];
// createdAt: string;
comment: string;
// lastUpdatedAt: string;
timestamp:Number
}
export interface IThread extends Document {
@@ -26,14 +24,11 @@ export interface IThread extends Document {
const CommentSchema = new Schema<IComment>(
{
userId: { type: Schema.Types.ObjectId, ref: 'User', required: true },
// createdAt: { type: String, },
comment: { type: String,},
// lastUpdatedAt: { type: String, },
timestamp:{
type: Number,
default:Date.now()}
},
// { _id: false } // Prevent automatic _id for each reply object
);
const threadSchema = new Schema<IThread>({
projectId: { type: Schema.Types.ObjectId, ref: 'Project', required: true },

View File

@@ -14,13 +14,12 @@ const MainModel = <T>(
): Model<T> => {
const db1_url = `${process.env.MONGO_URI}${db}`;
const authOptions = {
user: process.env.MONGO_USER, // Correct username environment variable
pass: process.env.MONGO_PASSWORD, // Correct password environment variable
authSource: process.env.MONGO_AUTH_DB || "admin", // Default to 'admin' if not provided
user: process.env.MONGO_USER,
pass: process.env.MONGO_PASSWORD,
authSource: process.env.MONGO_AUTH_DB || "admin",
maxPoolSize: 50,
};
// Check if the connection already exists
if (connections[db]) {
return connections[db].model<T>(modelName, schema, collectionName);
}
@@ -28,10 +27,8 @@ const MainModel = <T>(
try {
const db1 = mongoose.createConnection(db1_url, authOptions);
// Cache the connection
connections[db] = db1;
// Log connection success or handle errors
db1.on("connected", () => {
console.log(`Connected to MongoDB database: ${db}`);
});

View File

@@ -1,7 +1,7 @@
import { Document, Schema } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
export interface FloorItems extends Document {
export interface FloorItenms extends Document {
modelUuid: string;
modelfileID: string;
modelName: string;

View File

@@ -26,7 +26,6 @@ export interface AssetData extends Document {
type: string;
isVisible: boolean;
isArchive: false;
// points: [] | {};
position: [];
rotation: {
x: number;

View File

@@ -1,4 +1,4 @@
import { Document, Schema } from "mongoose";
import { Document, Schema } from "mongoose";
import MainModel from "../../../connect/mongoose.ts";
export interface Camera extends Document {

View File

@@ -1,20 +1,20 @@
import mongoose from "mongoose";
import MainModel from "../../../connect/mongoose.ts";
const positionSchema = new mongoose.Schema({
x: { type: Number }, // Optional position fields
x: { type: Number },
y: { type: Number },
z: { type: Number },
});
const Vector3 = new mongoose.Schema({
position: { type: positionSchema, required: false }, // Optional position
uuid: { type: String, required: false }, // Optional uuid
position: { type: positionSchema, required: false },
uuid: { type: String, required: false },
});
const LineSchema = new mongoose.Schema({
layer: { type: Number, required: true }, // Layer is mandatory
line: { type: [Vector3], required: true }, // Array of line objects
type: { type: String, required: false }, // Optional type
layer: { type: Number, required: true },
line: { type: [Vector3], required: true },
type: { type: String, required: false },
});
const lineModel = (db: string) => {

View File

@@ -1,5 +1,4 @@
import { Schema, Document } from "mongoose";
import { Schema, Document } from "mongoose";
import MainModel from "../../../connect/mongoose.ts";
export interface Zone extends Document {
@@ -13,8 +12,6 @@ export interface Zone extends Document {
sceneID: string;
panelOrder: string[];
lockedPanel: string[];
// createdBy: mongoose.Types.ObjectId;
// sceneID: mongoose.Types.ObjectId;
layer: number;
}
const zoneSchema: Schema = new Schema(
@@ -37,8 +34,6 @@ const zoneSchema: Schema = new Schema(
default: [],
enum: ["left", "right", "top", "bottom"],
},
// createdBy: { type: mongoose.Schema.Types.ObjectId, ref: "User" },
// sceneID: { type: mongoose.Schema.Types.ObjectId, ref: "Scene" },
},
{ timestamps: true }
);

View File

@@ -9,14 +9,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 };
};
}

View File

@@ -1,43 +1,23 @@
import mongoose, { Document, Schema } from "mongoose";
import mongoose from "mongoose";
import MainModel from "../../connect/mongoose.ts";
const positionSchema = new mongoose.Schema({
x: { type: Number, }, // Optional position fields
y: { type: Number, },
z: { type: Number},
});
// Define a schema for the individual line
const Vector3 = new mongoose.Schema({
position: { type: positionSchema, required: false }, // Optional position
uuid: { type: String, required: false }, // Optional uuid
});
// Define the main schema
const LineSchema = new mongoose.Schema({
layer: { type: Number, required: true }, // Layer is mandatory
line: { type: [Vector3], required: true }, // Array of line objects
type: { type: String, required: false }, // Optional type
});
x: { type: Number },
y: { type: Number },
z: { type: Number },
});
// Database connection and model creation
// const lineModel = (db: string) => {
// const mongoUrl = process.env.MONGO_URI || "";
// if (!mongoUrl) {
// throw new Error("MONGO_URI environment variable is not set");
// }
const Vector3 = new mongoose.Schema({
position: { type: positionSchema, required: false },
uuid: { type: String, required: false },
});
// // Connect to the database
// const dbConnection = mongoose.createConnection(mongoUrl, {
// dbName: db, // Specify the database name here
// serverSelectionTimeoutMS: 30000,
// });
const LineSchema = new mongoose.Schema({
layer: { type: Number, required: true },
line: { type: [Vector3], required: true },
type: { type: String, required: false },
});
// // Return the model
// return dbConnection.model("lines", LineSchema, "lines");
// };
// export default lineModel;
const lineModel = (db:string) => {
return MainModel(db, "lines", LineSchema, "lines")
const lineModel = (db: string) => {
return MainModel(db, "lines", LineSchema, "lines");
};
export default lineModel;
export default lineModel;

View File

@@ -1,32 +1,28 @@
import mongoose, { Document, ObjectId, Schema } from "mongoose";
import mongoose, { Document, Schema } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
export interface zoneSchema extends Document {
zoneId: string;//UUID
zoneName: string
createBy: mongoose.Types.ObjectId
points: []
layer: Number
viewPortCenter: []
viewPortposition: []
isArchive:boolean
export interface ZoneSchema extends Document {
zoneId: string;
zoneName: string;
createBy: mongoose.Types.ObjectId;
points: [];
layer: number;
viewPortCenter: [];
viewPortposition: [];
isArchive: boolean;
}
// Define the Mongoose Schema
const zoneSchema: Schema = new Schema({
zoneId: { type: String },//UUID
zoneName: { type: String },
createBy: { type: Schema.Types.ObjectId, ref: "Users", },
points: { type: Array },
layer: { type: Number, required: true },
viewPortCenter: { type: Array, required: true },
viewPortposition: { type: Array, required: true },
isArchive:{type:Boolean,default:false}
zoneId: { type: String },
zoneName: { type: String },
createBy: { type: Schema.Types.ObjectId, ref: "Users" },
points: { type: Array },
layer: { type: Number, required: true },
viewPortCenter: { type: Array, required: true },
viewPortposition: { type: Array, required: true },
isArchive: { type: Boolean, default: false },
});
// export default zoneModel;
const zoneModel = (db: string) => {
return MainModel(db, "zones", zoneSchema, "zones")
return MainModel(db, "zones", zoneSchema, "zones");
};
export default zoneModel;
export default zoneModel;

View File

@@ -7,27 +7,17 @@ export interface Project extends Document {
projectName: string;
createdBy: User["_id"];
isArchive: boolean;
isDeleted: boolean;
thumbnail: string;
sharedUsers: [];
DeletedAt: Date;
isViewed: number;
total_versions: string;
Present_version: string;
}
const projectSchema: Schema = new Schema(
{
projectUuid: { type: String },
projectName: { type: String },
projectUuid: { type: String, required: true },
projectName: { type: String },
thumbnail: { type: String },
isArchive: { type: Boolean, default: false },
createdBy: { type: Schema.Types.ObjectId, ref: "user" },
sharedUsers: [{ type: Schema.Types.ObjectId, ref: "user" }],
DeletedAt: { type: Date, default: null },
isDeleted: { type: Boolean, default: false },
isViewed: { type: Number },
total_versions: { type: String },
Present_version: { type: String },
},
{ timestamps: true }
);

View File

@@ -1,4 +1,3 @@
// models/Product.ts
import { Schema, Document } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
@@ -118,22 +117,20 @@ interface RoboticArmEventSchema extends AssetEventSchema {
interface MachineEventSchema extends AssetEventSchema {
type: "machine";
// speed: number;
point: MachinePointSchema;
}
interface StorageEventSchema extends AssetEventSchema {
type: "storageUnit";
// speed: number;
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;
@@ -144,7 +141,6 @@ interface IPointModel extends Document {
| StorageEventSchema;
points: ConveyorEventSchema[];
}
// type EventsSchema = ConveyorEventSchema | VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema;
const BaseEventSchema = new Schema<IPointModel>(
{

View File

@@ -3,9 +3,7 @@ import MainModel from "../../connect/mongoose.ts";
export interface Trigger extends Document {
pointsUUID: string;
// triggerUUID: string;
isArchive: string;
// sceneID: string;
uuid: string;
name: string;
type: string;
@@ -16,7 +14,6 @@ const triggerSchema: Schema = new Schema(
{
pointsUUID: { type: String },
isArchive: { type: Boolean, default: false },
// triggerUUID: { type: String },
uuid: { type: String, default: "" },
name: { type: String },
type: { type: String },

View File

@@ -32,7 +32,6 @@ const signupschema: Schema = new Schema({
},
profilePicture: {
type: String,
// default: "default-profile-picture.jpg"
},
isShare: {
type: Boolean,
@@ -43,14 +42,9 @@ const signupschema: Schema = new Schema({
enum: ["online", "offline"],
default: "offline",
},
recentlyViewed: {
type: [String],
default: [],
},
});
const userModel = (db: string) => {
return MainModel(db, "Users", signupschema, "Users")
// return MainModel(db, "UserAuth", signupschema, "UserAuth");
return MainModel(db, "Users", signupschema, "Users");
};
export default userModel;

View File

@@ -1,4 +1,4 @@
import { Schema, Document, model } from "mongoose";
import { Schema, Document } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
export interface Widget3d extends Document {

View File

@@ -1,4 +1,4 @@
import { Schema, Document, model } from "mongoose";
import { Schema, Document } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
export interface FloatingWidget extends Document {

View File

@@ -9,7 +9,7 @@ export interface Panel extends Document {
}
const panelSchema: Schema = new Schema(
{
zoneId: { type: String },
zoneId: { type: String },
panelName: { type: String },
widgets: [{ type: mongoose.Schema.Types.ObjectId, ref: "Widget" }],
isArchive: { type: Boolean, default: false },

View File

@@ -1,4 +1,4 @@
import { Schema, Document } from "mongoose";
import { Schema, Document } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
export interface Template extends Document {

View File

@@ -1,7 +1,7 @@
import mongoose, { Schema, Document } from "mongoose";
import MainModel from "../../connect/mongoose.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: string;
}
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: String },
},
{ timestamps: true }
);

View File

@@ -194,7 +194,6 @@ export const AuthLogin = async (
name: existingMail.userName,
userId: existingMail._id,
isShare: UserData.isShare,
// updatedUser: updatedUser as IUser,
token: tokenValidation,
refreshToken: refreshTokenvalidation,
};

View File

@@ -11,7 +11,6 @@ type MulterFile = {
const bucketName = "assets-public-bucket";
// Define public read policy
const publicReadPolicy = {
Version: "2012-10-17",
Statement: [
@@ -35,7 +34,7 @@ async function ensureBucketExists() {
async function ensureFolderExists(folderName: string) {
const folderPrefix = folderName.endsWith("/") ? folderName : `${folderName}/`;
const objects = minioClient.listObjects(bucketName, folderPrefix, true);
for await (const _ of objects) return; // Folder exists
for await (const _ of objects) return;
await minioClient.putObject(bucketName, folderPrefix, Buffer.from(""));
}

View File

@@ -9,7 +9,7 @@ import {
interface setAssetInput {
modelUuid: string;
modelName: string;
position: []; // user ID
position: [];
rotation: object;
eventData: Mixed;
modelfileID: string;
@@ -22,7 +22,7 @@ interface setAssetInput {
interface AssetUpdate {
modelUuid: string;
modelName: string;
position: []; // user ID
position: [];
rotation: object;
isLocked: boolean;
isVisible: boolean;
@@ -98,12 +98,7 @@ export const setAssetModel = async (
},
{ new: true }
);
// return {
// success: true,
// message: "Model updated successfully",
// data: updatevalue,
// organization: organization,
// };
return {
status: "Updated successfully",
data: updatevalue,
@@ -121,21 +116,6 @@ export const setAssetModel = async (
isVisible,
};
// if (eventData) {
// if (eventData?.type === "Conveyor") {
// assetData.eventData = {
// type: eventData.type,
// // point:undefined,
// points: eventData.points,
// };
// } else {
// assetData.eventData = {
// type: eventData.type,
// point: eventData.point,
// // points: undefined
// };
// }
// }
if (eventData) {
const typedEventData = eventData as unknown as {
type: string;
@@ -254,12 +234,7 @@ export const setAssetModel = async (
isVisible: assetDoc.isVisible,
};
}
// return {
// success: true,
// message: "Model created successfully",
// data: assetDatas,
// organization: organization,
// };
return {
status: "Success",
data: assetDatas,
@@ -307,11 +282,6 @@ export const deleteAssetModel = async (
{ new: true }
);
if (!archivedAsset) {
// return {
// success: false,
// status: "Failed to archive asset",
// organization: organization,
// };
return {
status: "Failed to archive asset",
};
@@ -321,13 +291,6 @@ export const deleteAssetModel = async (
{ $set: { isArchive: true } }
);
// return {
// success: true,
// message: "Model deleted successfully",
// data: archivedAsset,
// organization: organization,
// };
return {
status: "Success",
data: archivedAsset,
@@ -364,11 +327,6 @@ export const replaceEventDatas = async (
});
if (!existingModel) {
return { status: "Model not for this UUID" };
// return {
// success: false,
// message: "Model not for this UUID",
// organization: organization,
// };
} else {
const typedEventData = eventData as unknown as {
speed: number;
@@ -384,23 +342,11 @@ export const replaceEventDatas = async (
{ modelUuid, projectId, isArchive: false },
{
points: typedEventData?.points,
// speed: speed,
type: typedEventData?.type || existingModel?.type,
},
{ new: true }
);
// if (updatedModel)
// // return {
// // success: true,
// // message: "Data updated successfully",
// // data: updatedModel,
// // organization: organization,
// // };
// return {
// status: "Success",
// data: updatedModel,
// };
return {
status: "Success",
data: updatedModel,
@@ -448,7 +394,6 @@ export const updateAssetPositionRotation = async (
});
if (!existingAsset) {
return { status: "Asset not found" };
// return res.send("Asset not found");
}
const updateAsset = await assetModel(organization).updateMany(
{
@@ -464,12 +409,10 @@ export const updateAssetPositionRotation = async (
isLocked: isLocked,
}
);
// if (updateAsset)
return {
status: "Success",
data: updateAsset,
};
// return res.status(200).json({ message: "Asset updated successfully" });
} catch (error: unknown) {
if (error instanceof Error) {
return {
@@ -501,7 +444,6 @@ export const getFloorItems = async (
if (!findValues || findValues.length === 0) {
return { status: "floorItems not found" };
// return res.status(200).json({ message: "floorItems not found" });
}
const response = findValues.map((item) => {
@@ -519,8 +461,6 @@ export const getFloorItems = async (
return responseItem;
});
// return res.status(200).json(response);
return {
status: "Success",
data: response,

View File

@@ -68,13 +68,12 @@ export const setWallItems = async (data: IWallSetupData): Promise<IWallItemResul
quaternion,
scale,
},
{ new: true } // Return the updated document
{ new: true }
);
return {
status: "Updated successfully",
data: updatevalue,
};
// res.status(201).json(updatevalue);
} else {
const newValue = await wallItemModel(organization).create({
modelUuid,
@@ -91,7 +90,6 @@ export const setWallItems = async (data: IWallSetupData): Promise<IWallItemResul
status: "wall Item created successfully",
data: newValue,
};
// res.status(201).json(newValue);
}
} catch (error: unknown) {
if (error instanceof Error) {

View File

@@ -42,7 +42,7 @@ export const previousVersion = async (
projectId: projectId,
isArchive: false,
});
// .sort({ version: -1 });
return result;
};
export const generateUntitledProjectName = async (

View File

@@ -45,7 +45,7 @@ export const previousVersion = async (
projectId: projectId,
isArchive: false,
});
// .sort({ version: -1 });
return result;
};
export const generateUntitledProjectName = async (

View File

@@ -56,7 +56,7 @@ export const searchProject = async (data: searchProjectInterface) => {
const userExisting = await existingUser(userId, organization);
if (!userExisting) return { status: "User not found" };
const findprojectName = await projectModel(organization).find({
projectName: { $regex: `${searchName}`, $options: "i" }, // 'i' makes it case-insensitive
projectName: { $regex: `${searchName}`, $options: "i" },
isArchive: false,
});
if (!findprojectName || findprojectName.length === 0)

View File

@@ -11,7 +11,7 @@ import {
interface CreateProjectInput {
projectName: string;
projectUuid: string;
userId: string; // user ID
userId: string;
thumbnail?: string;
sharedUsers?: string[];
organization: string;
@@ -19,7 +19,7 @@ interface CreateProjectInput {
interface updateProjectInput {
projectName: string;
projectId: string;
userId: string; // user ID
userId: string;
thumbnail?: string;
sharedUsers?: string[];
organization: string;

View File

@@ -1,375 +1,364 @@
import { Mixed } from "mongoose";
import EventsDataModel from "../../V1Models/Simulation/eventsDataModel.ts";
import ProductModel from "../../V1Models/Simulation/productModel.ts";
import { existingProjectById, existingUser } from "../helpers/v1projecthelperFns.ts";
import {
existingProjectById,
existingUser,
} from "../helpers/v1projecthelperFns.ts";
interface Iproduct {
productName: string;
productId: string;
eventDatas: {
modelUuid: string
modelName: string
position: [Number]
rotation: [Number]
type: string
speed: string
point: Mixed
points: Mixed
};
userId: string;
organization: string;
projectId: string;
productName: string;
productId: string;
eventDatas: {
modelUuid: string;
modelName: string;
position: [Number];
rotation: [Number];
type: string;
speed: string;
point: Mixed;
points: Mixed;
};
userId: string;
organization: string;
projectId: string;
}
interface IResult {
status: string;
data?: object;
status: string;
data?: object;
}
interface IEventDataDelete {
productId: string;
modelUuid: string
userId: string;
organization: string;
projectId: string;
productId: string;
modelUuid: string;
userId: string;
organization: string;
projectId: string;
}
export const productAdd = async (data: Iproduct): Promise<IResult> => {
try {
const { productName, productId, eventDatas, projectId, userId, organization } = data
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingProduct = await ProductModel(organization).findOne({
productId: productId, projectId: projectId,
isArchive: false,
});
if (existingProduct) {
const existingEventData = await EventsDataModel(organization).findOne({
productId: productId,
projectId: projectId,
modelUuid: eventDatas.modelUuid,
isArchive: false,
});
if (existingEventData) {
await EventsDataModel(organization).findOneAndUpdate(
{
modelUuid: eventDatas.modelUuid,
productId: productId,
isArchive: false,
},
{
modelUuid: eventDatas?.modelUuid,
modelName: eventDatas?.modelName,
position: eventDatas?.position,
rotation: eventDatas?.rotation,
type: eventDatas?.type,
speed: eventDatas?.speed,
point: eventDatas?.point,
points: eventDatas?.points,
}
);
return {
status: "EventData updated successfully"
}
// return res
// .status(200)
// .json({ message: "EventData updated successfully" });
} else {
await EventsDataModel(organization).create({
productId: productId,
modelUuid: eventDatas?.modelUuid,
modelName: eventDatas?.modelName,
position: eventDatas?.position,
rotation: eventDatas?.rotation,
type: eventDatas?.type,
speed: eventDatas?.speed,
point: eventDatas?.point,
points: eventDatas?.points,
});
return {
status: "EventData add successfully"
}
// return res
// .status(201)
// .json({ message: "EventData add successfully" });
}
} else {
const newProduct = await ProductModel(organization).create({
productId: productId,
productName: productName,
});
if (newProduct) {
if (eventDatas) {
await EventsDataModel(organization).create({
productId: productId,
modelUuid: eventDatas?.modelUuid,
modelName: eventDatas?.modelName,
position: eventDatas?.position,
rotation: eventDatas?.rotation,
type: eventDatas?.type,
speed: eventDatas?.speed,
point: eventDatas?.point,
points: eventDatas?.points,
});
}
}
return {
status: "Success"
}
// return res
// .status(201)
// .json({ message: "Product created successfully" });
}
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
}
export const getProductDatas = async (data: Iproduct): Promise<IResult> => {
try {
const { productId, projectId, userId, organization } = data
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingProduct = await ProductModel(organization).findOne({
productId: productId, projectId: projectId,
isArchive: false,
});
if (!existingProduct)
return { status: "Product not found" };
// return res.status(404).json({ message: "Product not found" });
const existingEventDatas = await EventsDataModel(organization)
.find({ productId: productId, projectId: projectId })
.select("-productId");
return { status: "Success", data: existingEventDatas };
// return res.status(200).json(existingEventDatas);
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
}
export const productDataDelete = async (data: Iproduct): Promise<IResult> => {
try {
const { productId, projectId, userId, organization } = data
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingProduct = await ProductModel(organization).findOne({
productId: productId,
isArchive: false,
});
if (!existingProduct)
return { status: "Product not found" };
// return res.status(404).json({ message: "Product not found" });
await ProductModel(organization).findOneAndUpdate(
{ productId: productId, projectId: projectId },
{
isArchive: true,
},
{ new: true }
);
const existingEventDatas = await EventsDataModel(organization).find({
productId: productId,
});
if (existingEventDatas) {
await EventsDataModel(organization).updateMany(
{ productId, projectId },
{ $set: { isArchive: true } }
);
}
return {
status: "Success",
// data: assetDatas,
};
// return res.status(201).json({ message: "product deleted successfully" });
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
}
export const EventDataDelete = async (data: IEventDataDelete): Promise<IResult> => {
try {
const { modelUuid, productId, projectId, userId, organization } = data
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingProduct = await ProductModel(organization).findOne({
productId: productId, projectId: projectId,
isArchive: false,
});
if (!existingProduct)
return { status: "Product not found" };
// return res.status(404).json({ message: "Product not found" });
try {
const {
productName,
productId,
eventDatas,
projectId,
userId,
organization,
} = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingProduct = await ProductModel(organization).findOne({
productId: productId,
projectId: projectId,
isArchive: false,
});
if (existingProduct) {
const existingEventData = await EventsDataModel(organization).findOne({
productId: productId,
projectId: projectId,
modelUuid: eventDatas.modelUuid,
isArchive: false,
});
if (existingEventData) {
await EventsDataModel(organization).findOneAndUpdate(
{ productId: productId, projectId: projectId, modelUuid: modelUuid },
{
isArchive: true,
},
{ new: true }
);
// return res
// .status(201)
// .json({ message: "EventData deleted successfully" });
return {
status: "Success",
// data: assetDatas,
};
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
}
export const AllProductDatas = async (data: IEventDataDelete): Promise<IResult> => {
try {
const { projectId, userId, organization } = data
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingProduct = await ProductModel(organization).find({
{
modelUuid: eventDatas.modelUuid,
productId: productId,
isArchive: false,
});
if (!existingProduct) {
// return res.status(404).json({ message: "No products found" });
return {
status: "No products found",
// data: result,
};
}
const result = [];
for (const product of existingProduct) {
const eventDatas = await EventsDataModel(organization)
.find({ projectId: product.projectId, productId: product.productId, isArchive: false })
.select("-productId -isArchive -createdAt -updatedAt -__v -_id");
result.push({
// product: {
projectId: product.projectId,
productName: product.productName,
productId: product.productId,
eventDatas,
// },
});
}
// return res.status(200).json(result);
},
{
modelUuid: eventDatas?.modelUuid,
modelName: eventDatas?.modelName,
position: eventDatas?.position,
rotation: eventDatas?.rotation,
type: eventDatas?.type,
speed: eventDatas?.speed,
point: eventDatas?.point,
points: eventDatas?.points,
}
);
return {
status: "Success",
data: result,
status: "EventData updated successfully",
};
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
} else {
await EventsDataModel(organization).create({
productId: productId,
modelUuid: eventDatas?.modelUuid,
modelName: eventDatas?.modelName,
position: eventDatas?.position,
rotation: eventDatas?.rotation,
type: eventDatas?.type,
speed: eventDatas?.speed,
point: eventDatas?.point,
points: eventDatas?.points,
});
return {
status: "EventData add successfully",
};
}
} else {
const newProduct = await ProductModel(organization).create({
productId: productId,
productName: productName,
});
if (newProduct) {
if (eventDatas) {
await EventsDataModel(organization).create({
productId: productId,
modelUuid: eventDatas?.modelUuid,
modelName: eventDatas?.modelName,
position: eventDatas?.position,
rotation: eventDatas?.rotation,
type: eventDatas?.type,
speed: eventDatas?.speed,
point: eventDatas?.point,
points: eventDatas?.points,
});
}
}
return {
status: "Success",
};
}
}
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const getProductDatas = async (data: Iproduct): Promise<IResult> => {
try {
const { productId, projectId, userId, organization } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingProduct = await ProductModel(organization).findOne({
productId: productId,
projectId: projectId,
isArchive: false,
});
if (!existingProduct) return { status: "Product not found" };
const existingEventDatas = await EventsDataModel(organization)
.find({ productId: productId, projectId: projectId })
.select("-productId");
return { status: "Success", data: existingEventDatas };
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const productDataDelete = async (data: Iproduct): Promise<IResult> => {
try {
const { productId, projectId, userId, organization } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingProduct = await ProductModel(organization).findOne({
productId: productId,
isArchive: false,
});
if (!existingProduct) return { status: "Product not found" };
await ProductModel(organization).findOneAndUpdate(
{ productId: productId, projectId: projectId },
{
isArchive: true,
},
{ new: true }
);
const existingEventDatas = await EventsDataModel(organization).find({
productId: productId,
});
if (existingEventDatas) {
await EventsDataModel(organization).updateMany(
{ productId, projectId },
{ $set: { isArchive: true } }
);
}
return {
status: "Success",
};
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const EventDataDelete = async (
data: IEventDataDelete
): Promise<IResult> => {
try {
const { modelUuid, productId, projectId, userId, organization } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingProduct = await ProductModel(organization).findOne({
productId: productId,
projectId: projectId,
isArchive: false,
});
if (!existingProduct) return { status: "Product not found" };
await EventsDataModel(organization).findOneAndUpdate(
{ productId: productId, projectId: projectId, modelUuid: modelUuid },
{
isArchive: true,
},
{ new: true }
);
return {
status: "Success",
};
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const AllProductDatas = async (
data: IEventDataDelete
): Promise<IResult> => {
try {
const { projectId, userId, organization } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingProduct = await ProductModel(organization).find({
isArchive: false,
});
if (!existingProduct) {
return {
status: "No products found",
};
}
const result = [];
for (const product of existingProduct) {
const eventDatas = await EventsDataModel(organization)
.find({
projectId: product.projectId,
productId: product.productId,
isArchive: false,
})
.select("-productId -isArchive -createdAt -updatedAt -__v -_id");
result.push({
projectId: product.projectId,
productName: product.productName,
productId: product.productId,
eventDatas,
});
}
return {
status: "Success",
data: result,
};
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};
export const productRename = async (data: Iproduct): Promise<IResult> => {
try {
const { productName, productId, projectId, userId, organization } = data
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingProduct = await ProductModel(organization).findOne({
productId: productId, projectId: projectId,
isArchive: false,
});
try {
const { productName, productId, projectId, userId, organization } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingProduct = await ProductModel(organization).findOne({
productId: productId,
projectId: projectId,
isArchive: false,
});
if (!existingProduct)
return { status: "Product not found" };
if (!existingProduct) return { status: "Product not found" };
await ProductModel(organization).findOneAndUpdate(
{ productId: productId },
{
productName: productName,
},
{ new: true }
);
await ProductModel(organization).findOneAndUpdate(
{ productId: productId },
{
productName: productName,
},
{ new: true }
);
// return res.status(201).json({ message: "product Rename successfully" });
return {
status: "Success",
// data: assetDatas,
};
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
return {
status: "Success",
};
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
}
};

View File

@@ -11,7 +11,7 @@ import UsersDataModel from "../../V1Models/Auth/user.ts";
interface CreateProjectInput {
projectName: string;
projectUuid: string;
userId: string; // user ID
userId: string;
thumbnail?: string;
sharedUsers?: string[];
organization: string;
@@ -19,7 +19,7 @@ interface CreateProjectInput {
interface IProjectDuplicate {
projectName: string;
projectUuid: string;
userId: string; // user ID
userId: string;
thumbnail?: string;
sharedUsers?: string[];
organization: string;
@@ -27,7 +27,7 @@ interface IProjectDuplicate {
interface updateProjectInput {
projectName: string;
projectId: string;
userId: string; // user ID
userId: string;
thumbnail?: string;
sharedUsers?: string[];
organization: string;
@@ -116,9 +116,7 @@ export const GetAllProjects = async (data: GetProjectsInterface) => {
await existingUser(userId, organization);
if (!existingUser) return { status: "User not found" };
let filter = { isArchive: false } as RoleFilter;
// if (role === "User") {
// filter.createdBy = userId;
// }
const projectDatas = await projectModel(organization)
.find(filter)
.select("_id projectName createdBy thumbnail createdAt projectUuid");
@@ -135,9 +133,7 @@ export const DeleteProject = async (data: ProjectDelInterface) => {
if (!ExistingUser) return { status: "User not found" };
let filter = { _id: projectId, isArchive: false } as RoleFilter;
// if (role === "User") {
// filter.createdBy = userId;
// }
const existingProject = await projectModel(organization).findOne(filter);
console.log("existingProject: ", existingProject);
if (!existingProject) return { status: "Project not found" };
@@ -158,9 +154,7 @@ export const updateProject = async (data: updateProjectInput) => {
const ExistingUser = await existingUser(userId, organization);
if (!ExistingUser) return { status: "User not found" };
let filter = { _id: projectId, isArchive: false } as RoleFilter;
// if (role === "User") {
// filter.createdBy = userId;
// }
const existingProject = await projectModel(organization).findOne(filter);
if (!existingProject) return { status: "Project not found" };
if (projectName !== undefined) projectName;
@@ -245,9 +239,7 @@ export const viewProject = async (data: ProjectInterface) => {
isArchive: false,
});
let filter = { _id: projectId, isArchive: false } as RoleFilter;
// if (role === "User") {
// filter.createdBy = userId;
// }
const existingProject = await projectModel(organization).findOne(filter);
if (!existingProject) return { status: "Project not found" };
const newArr = RecentUserDoc?.recentlyViewed || [];

View File

@@ -36,12 +36,8 @@ export const RecentlyAdded = async (data: IRecentData) => {
model: projectModel(organization),
select: "_id",
});
let filter = { isArchive: false } as RoleFilter;
// if (role === "User") {
// filter.createdBy = userId;
// }
const populatedProjects = userRecentData.recentlyViewed as IProject[];
console.log("populatedProjects: ", populatedProjects);
const RecentDatas = await Promise.all(
populatedProjects.map(async (project) => {
const projectExisting = await projectModel(organization)
@@ -50,7 +46,6 @@ export const RecentlyAdded = async (data: IRecentData) => {
return projectExisting;
})
);
console.log("RecentDatas: ", RecentDatas);
const filteredProjects = RecentDatas.filter(Boolean);
console.log("filteredProjects: ", filteredProjects);
@@ -65,7 +60,7 @@ export const searchProject = async (data: searchProjectInterface) => {
const userExisting = await existingUser(userId, organization);
if (!userExisting) return { status: "User not found" };
const findprojectName = await projectModel(organization).find({
projectName: { $regex: `${searchName}`, $options: "i" }, // 'i' makes it case-insensitive
projectName: { $regex: `${searchName}`, $options: "i" },
isArchive: false,
});
if (!findprojectName || findprojectName.length === 0)

View File

@@ -19,9 +19,7 @@ export const TrashDatas = async (data: IOrg) => {
try {
const { organization, role, userId } = data;
let filter = { isArchive: true, isDeleted: false } as RoleFilter;
// if (role === "User") {
// filter.createdBy = userId;
// }
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const TrashLists = await projectModel(organization).find(filter);
@@ -62,9 +60,7 @@ export const RestoreTrashData = async (data: IRestore) => {
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
let filter = { isArchive: true, _id: projectId } as RoleFilter;
// if (role === "User") {
// filter.createdBy = userId;
// }
const findProject = await projectModel(organization).findOne(filter);
if (!findProject) return { status: "Project not found" };
const restoreData = await projectModel(organization).findOneAndUpdate(

View File

@@ -48,7 +48,6 @@ class VersionService {
userId: string,
description?: string
) {
// Create new version
const newVersion = await this.createNewVersion(
db,
projectId,
@@ -56,7 +55,6 @@ class VersionService {
description
);
// Get all assets from previous version
const previousVersion = parseFloat((newVersion.version - 0.1).toFixed(1));
const previousVersionDoc = await versionModel(db).findOne({
projectId,
@@ -73,7 +71,6 @@ class VersionService {
});
}
// Copy assets to new version
const newAssets = await Promise.all(
previousAssets.map(async (asset) => {
console.log("previousAssets: ", previousAssets);

View File

@@ -45,13 +45,12 @@ export class WallItems {
quaternion,
scale,
},
{ new: true } // Return the updated document
{ new: true }
);
return {
state: "Updated successfully",
data: updatevalue,
};
// res.status(201).json(updatevalue);
} else {
const newValue = await wallItemModel(organization).create({
modelUuid,
@@ -67,16 +66,12 @@ export class WallItems {
state: "wall Item created successfully",
data: newValue,
};
// res.status(201).json(newValue);
}
// Send response with the created document
} catch (error:unknown) {
const err = error as Error;
console.error("Error creating wallitems:", error);
return { state: "Failed to create wallitems", data: { message: err.message } };
// return { state: "Failed to create wallitems", data: error } };
// res.status(500).json({ message: "Failed to create wallitems" });
}
}
static async getWallItems(req: Request, res: Response) {

View File

@@ -15,8 +15,6 @@ const doc = {
description: "Description",
},
host: "185.100.212.76:5000",
// host: "192.168.0.102:5000",
// basePath: "/api/v1",
schemes: ["http"],
};

View File

@@ -1,34 +1,34 @@
import { MongoClient } from 'mongodb'
import { MongoClient } from "mongodb";
export default async function mongoAdminCreation() {
const uri = process.env.MONGO_URI!; // Replace with your MongoDB URI
const client = new MongoClient(uri);
const user = {
user:"admin",
pwd: process.env.MONGO_PASSWORD!,
roles: [{ role: "root", db: process.env.MONGO_AUTH_DB || "admin" }],
};
try {
await client.connect();
const db = client.db('admin'); // Specify the actual database where the user should be created
// Check if the user already exists
const userExists = await db.collection('system.users').findOne({ user: user.user});
if (userExists) {
console.log(`User ${user} already exists`);
return; // Exit if the user already exists
}
// Create the user
await db.command({ createUser: user.user, pwd: user.pwd, roles: user.roles });
console.log("User created successfully!")
} catch (error) {
console.error("Error creating user:",error);
} finally {
await client.close();
const uri = process.env.MONGO_URI!;
const client = new MongoClient(uri);
const user = {
user: "admin",
pwd: process.env.MONGO_PASSWORD!,
roles: [{ role: "root", db: process.env.MONGO_AUTH_DB || "admin" }],
};
try {
await client.connect();
const db = client.db("admin");
const userExists = await db
.collection("system.users")
.findOne({ user: user.user });
if (userExists) {
console.log(`User ${user} already exists`);
return;
}
await db.command({
createUser: user.user,
pwd: user.pwd,
roles: user.roles,
});
console.log("User created successfully!");
} catch (error) {
console.error("Error creating user:", error);
} finally {
await client.close();
}
// mongoAdminCreation
}

View File

@@ -77,9 +77,7 @@ const tokenValidator = async (
req.user = decoded;
next();
} catch (err) {
// res.status(401).json({
// msg: "Invalid Token",
// });
if (!refresh_token) {
res.status(403).json({
success: false,