Testing failer uncomment issue sorted API-Docker updated based on the Failed testcase

This commit is contained in:
2025-05-28 09:42:00 +05:30
parent f2cad42d30
commit 41e2075c55
90 changed files with 2485 additions and 4308 deletions

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,57 +1,35 @@
import mongoose, { Document, Schema } from 'mongoose';
import MainModel from '../../connect/mongoose.ts';
import { Document, Schema } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
// Interface for TypeScript with PascalCase
export interface floorItenms extends Document {
export interface FloorItenms extends Document {
modelUuid: string;
modelfileID: string;
modelName: string
isLocked:boolean
isVisible:boolean
position: []
modelName: string;
isLocked: boolean;
isVisible: boolean;
position: [];
rotation: {
x: number;
y: number;
z: number;
};
}
// Define the Mongoose Schema
const floorItemsSchema: Schema = new Schema({
modelUuid: { type: String },
modelfileID: { type: String },
modelName: { type: String },
position: { type: Array},
isLocked:{type:Boolean},
isVisible:{type:Boolean},
position: { type: Array },
isLocked: { type: Boolean },
isVisible: { type: Boolean },
rotation: {
x: { type: Number, required: true },
y: { type: Number, required: true },
z: { type: Number, required: true }
}
z: { type: Number, required: true },
},
});
// Model for MongoDB collection
// const cameraModel = model<Camera>("Camera", cameraSchema);
// export default cameraModel;
// const floorItemsModel = (db: string) => {
// const mongoUrl = process.env.MONGO_URI || '';
// if (!mongoUrl) {
// throw new Error('MONGO_URI environment variable is not set');
// }
// // Connect to the database
// const dbConnection = mongoose.createConnection(mongoUrl, {
// dbName: db, // Specify the database name here
// serverSelectionTimeoutMS: 30000,
// });
// return dbConnection.model<floorItenms>('floorItenms', floorItenmsSchema,`floorItenms`);
// }
// export default floorItemsModel;
const floorItemsModel = (db:string) => {
return MainModel(db, "floorItems", floorItemsSchema, "floorItems")
const floorItemsModel = (db: string) => {
return MainModel(db, "floorItems", floorItemsSchema, "floorItems");
};
export default floorItemsModel;
export default floorItemsModel;

View File

@@ -1,48 +1,30 @@
import mongoose, { Document, Schema } from 'mongoose';
import MainModel from '../../connect/mongoose.ts';
// Interface for TypeScript with PascalCase
export interface wallitems extends Document {
modelUuid: string;
modelName: string
modelfileID: string;
type: string
csgposition: []
csgscale: []
position: []
quaternion: []
scale: []
import { Document, Schema } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
export interface WallItems extends Document {
modelUuid: string;
modelName: string;
modelfileID: string;
type: string;
csgposition: [];
csgscale: [];
position: [];
quaternion: [];
scale: [];
}
// Define the Mongoose Schema
const wallItemsSchema: Schema = new Schema({
modelUuid: { type: String},
modelfileID: { type: String},
modelName: { type: String},
type: { type: String },
csgposition: { type: Array},
csgscale: { type: Array,},
position: { type: Array },
quaternion: { type: Array},
scale: { type: Array}
modelUuid: { type: String },
modelfileID: { type: String },
modelName: { type: String },
type: { type: String },
csgposition: { type: Array },
csgscale: { type: Array },
position: { type: Array },
quaternion: { type: Array },
scale: { type: Array },
});
// const wallItenmModel = (db: string) => {
// const mongoUrl = process.env.MONGO_URI || '';
// if (!mongoUrl) {
// throw new Error('MONGO_URI environment variable is not set');
// }
// // Connect to the database
// const dbConnection = mongoose.createConnection(mongoUrl, {
// dbName: db, // Specify the database name here
// serverSelectionTimeoutMS: 30000,
// });
// return dbConnection.model<wallitenms>('wallitenms', wallItenmsSchema, `wallitenms`);
// }
// export default wallItenmModel;
const wallItenmModel = (db:string) => {
return MainModel(db, "wallitems", wallItemsSchema, "wallitems")
};
export default wallItenmModel;
const wallItenmModel = (db: string) => {
return MainModel(db, "wallitems", wallItemsSchema, "wallitems");
};
export default wallItenmModel;

View File

@@ -1,4 +1,4 @@
import mongoose, { Document, Schema } from "mongoose";
import { Document, Schema } from "mongoose";
import MainModel from "../../../connect/mongoose.ts";
interface ICommonBase {
@@ -26,7 +26,6 @@ export interface assetData extends Document {
type: string;
isVisible: boolean;
isArchive: false;
// points: [] | {};
position: [];
rotation: {
x: number;
@@ -43,7 +42,6 @@ const assetDataSchema: Schema = new Schema({
modelfileID: { type: String },
modelName: { type: String },
type: { type: String },
// points: { type: Schema.Types.Mixed },
position: { type: Array },
rotation: {
x: { type: Number },
@@ -58,101 +56,7 @@ const assetDataSchema: Schema = new Schema({
},
});
// export default floorItemsModel;
const assetModel = (db: string) => {
return MainModel(db, "Assets", assetDataSchema, "Assets");
};
export default assetModel;
// import mongoose, { Document, Schema } from "mongoose";
// import MainModel from "../../../connect/mongoose.ts";
// export interface assetData extends Document {
// modelUuid: string;
// modelfileID: string;
// modelName: string;
// isLocked: boolean;
// type: string;
// isVisible: boolean;
// isArchive: false;
// // position: [];
// // rotation: {
// // x: number;
// // y: number;
// // z: number;
// // };
// points: {
// uuid: string;
// position: [];
// rotation: [];
// actions: [mongoose.Types.ObjectId];
// triggers: [mongoose.Types.ObjectId];
// connections: {
// source: {
// modelUUID: string;
// pointUUID: string;
// };
// targets: [
// {
// modelUUID: string;
// pointUUID: string;
// }
// ];
// }[];
// }[];
// position: [];
// // rotation: [];
// rotation: {
// x: number;
// y: number;
// z: number;
// };
// speed: number | string;
// }
// // Define the Mongoose Schema
// const assetDataSchema: Schema = new Schema({
// isArchive: { type: Boolean, default: false },
// modelUuid: { type: String },
// modelfileID: { type: String },
// modelName: { type: String },
// type: { type: String },
// // assetPosition: { type: Array },
// points: [
// {
// uuid: { type: String },
// position: { type: Array },
// rotation: { type: Array },
// actions: [{ type: mongoose.Schema.Types.ObjectId, ref: "Actions" }],
// triggers: [{ type: mongoose.Schema.Types.ObjectId, ref: "Triggers" }],
// connections: {
// source: {
// modelUUID: { type: String },
// pointUUID: { type: String },
// },
// targets: [
// {
// modelUUID: { type: String },
// pointUUID: { type: String },
// },
// ],
// },
// },
// ],
// position: { type: Array },
// // rotation: { type: Array},
// rotation: {
// x: { type: Number },
// y: { type: Number },
// z: { type: Number },
// },
// speed: { type: Schema.Types.Mixed },
// isLocked: { type: Boolean },
// isVisible: { type: Boolean },
// });
// // export default floorItemsModel;
// const assetModel = (db: string) => {
// return MainModel(db, "Assets", assetDataSchema, "Assets");
// };
// export default assetModel;

View File

@@ -1,31 +1,6 @@
import mongoose, { Schema, Document } from "mongoose";
import { Schema, Document } from "mongoose";
import MainModel from "../../../connect/mongoose.ts";
// Common Interfaces
// interface ITriggerConveyor {
// uuid: string;
// name: string;
// type: string;
// isUsed: boolean;
// bufferTime: number;
// }
// interface ITriggerVehicle {
// uuid: string;
// name: string;
// type: string;
// isUsed: boolean;
// }
// interface IConnectionConveyor {
// source: { modelUUID: string; pointUUID: string };
// targets: { modelUUID: string; pointUUID: string }[];
// }
// interface IConnectionVehicle {
// source: { modelUUID: string; pointUUID: string };
// targets: { modelUUID: string; pointUUID: string }[];
// }
// Point Types
interface IPointBase {
uuid: string;
position: number[];
@@ -127,322 +102,10 @@ const PointSchema = new Schema<IPointModel>(
{ timestamps: true }
);
// Model Creation
const pointModel = (db: string) => {
return MainModel(db, "Points", PointSchema, "Points");
};
export default pointModel;
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// import mongoose, { Schema, Document } from "mongoose";
// import MainModel from "../../../connect/mongoose.ts";
// interface IActionConveyor {
// uuid: string;
// name: string;
// type: string;
// material: string;
// delay: number | string;
// spawnInterval: number | string;
// spawnMaterial: string;
// isUsed: boolean;
// hitCount: number;
// start: string;
// end: string;
// buffer: number;
// }
// interface ITriggers {
// uuid: string;
// name: string;
// type: string;
// isUsed: boolean;
// bufferTime: number;
// }
// interface IConnection {
// source: { modelUUID: string; pointUUID: string };
// targets: { modelUUID: string; pointUUID: string }[];
// }
// interface IActionVehicle {
// uuid: string;
// name: string;
// type: string;
// isUsed: boolean;
// hitCount: number;
// start: string;
// end: string;
// buffer: number;
// }
// interface IPointConveyor {
// uuid: string;
// position: number[];
// rotation: number[];
// actions: IActionConveyor[];
// triggers: ITriggers[];
// connections: IConnection;
// }
// interface IPointVehicle {
// uuid: string;
// position: number[];
// actions: IActionVehicle[];
// triggers: ITriggers[];
// connections: IConnection;
// }
// interface IBaseModel extends Document {
// modelfileID: string;
// type: "Conveyor" | "Vehicle";
// points: IPointConveyor[] | IPointVehicle;
// }
// const PointconveyorSchema = new Schema<IPointConveyor>({
// uuid: { type: String, required: true },
// position: { type: [Number] },
// rotation: { type: [Number] },
// actions: [
// {
// uuid: { type: String, default: "" },
// name: { type: String },
// type: { type: String },
// material: { type: String },
// delay: { type: Schema.Types.Mixed },
// spawnInterval: { type: Schema.Types.Mixed },
// spawnMaterial: { type: String },
// isUsed: { type: Boolean },
// },
// ],
// triggers: [
// {
// uuid: { type: String, default: "" },
// name: { type: String },
// type: { type: String },
// bufferTime: { type: Number },
// isUsed: { type: Boolean },
// },
// ],
// connections: {
// source: {
// modelUUID: { type: String },
// pointUUID: { type: String },
// },
// targets: [
// {
// modelUUID: { type: String },
// pointUUID: { type: String },
// },
// ],
// },
// });
// const PointvehicleSchema = new Schema<IPointVehicle>({
// uuid: { type: String, required: true },
// position: { type: [Number] },
// actions: [
// {
// uuid: { type: String, default: "" },
// name: { type: String },
// type: { type: String },
// isUsed: { type: Boolean },
// hitCount: { type: String },
// start: { type: String },
// end: { type: String },
// buffer: { type: String },
// },
// ],
// triggers: [
// {
// uuid: { type: String, default: "" },
// name: { type: String },
// type: { type: String },
// bufferTime: { type: Number },
// isUsed: { type: Boolean },
// },
// ],
// connections: {
// source: {
// modelUUID: { type: String },
// pointUUID: { type: String },
// },
// targets: [
// {
// modelUUID: { type: String },
// pointUUID: { type: String },
// },
// ],
// },
// });
// const BaseSchema = new Schema<IBaseModel>(
// {
// modelfileID: { type: String },
// type: { type: String, enum: ["Conveyor", "Vehicle"] },
// points: {
// type: Schema.Types.Mixed,
// required: true,
// },
// },
// { discriminatorKey: "type", timestamps: true }
// );
// const pointModel = (db: string) => {
// const BasePointModel = MainModel(db, "Points", BaseSchema, "Points");
// const ConveyorModel = BasePointModel.discriminator(
// "Conveyor",
// new Schema({
// points: [PointconveyorSchema],
// })
// );
// const VehicleModel = BasePointModel.discriminator(
// "Vehicle",
// new Schema({
// points: PointvehicleSchema,
// })
// );
// return { ConveyorModel, VehicleModel };
// };
// export default pointModel;
// ===
// const pointModel = (db: string) => {
// const BasePointModel =
// mongoose.models.Points || MainModel(db, "Points", BaseSchema, "Points");
// if (!BasePointModel.discriminators?.Conveyor) {
// BasePointModel.discriminator(
// "Conveyor",
// new Schema({
// points: [PointconveyorSchema],
// })
// );
// }
// if (!BasePointModel.discriminators?.Vehicle) {
// BasePointModel.discriminator(
// "Vehicle",
// new Schema({
// points: PointvehicleSchema,
// })
// );
// }
// const ConveyorModel =
// mongoose.models.Conveyor || BasePointModel.discriminators?.Conveyor;
// const VehicleModel =
// mongoose.models.Vehicle || BasePointModel.discriminators?.Vehicle;
// return { ConveyorModel, VehicleModel, BasePointModel };
// };
// export default pointModel;
// ===========================================
// ===
// import mongoose, { Schema, Document } from "mongoose";
// import MainModel from "../../../connect/mongoose.ts";
// interface IAction {
// uuid: string;
// name: string;
// type: string;
// material: string;
// delay: number | string;
// spawnInterval: number | string;
// spawnMaterial: string;
// isUsed: boolean;
// hitCount: number;
// start: string;
// end: string;
// buffer: number;
// }
// interface ITriggers {
// uuid: string;
// name: string;
// type: string;
// isUsed: boolean;
// bufferTime: number;
// }
// interface IConnection {
// source: { modelUUID: string; pointUUID: string };
// targets: { modelUUID: string; pointUUID: string }[];
// }
// interface IPoint {
// uuid: string;
// position: number[];
// rotation: number[];
// actions: IAction[];
// triggers: ITriggers[];
// connections: IConnection;
// }
// interface IBaseModel extends Document {
// modelfileID: string;
// type: "Conveyor" | "Vehicle";
// points: IPoint[] | IPoint;
// }
// const PointSchema = new Schema<IPoint>({
// uuid: { type: String, required: true },
// position: { type: [Number] },
// rotation: { type: [Number] },
// actions: [
// {
// uuid: { type: String, default: "" },
// name: { type: String },
// type: { type: String },
// material: { type: String },
// delay: { type: String },
// spawnInterval: { type: String },
// spawnMaterial: { type: String },
// isUsed: { type: Boolean },
// hitCount: { type: String },
// start: { type: String },
// end: { type: String },
// buffer: { type: String },
// },
// ],
// triggers: [
// {
// uuid: { type: String, default: "" },
// name: { type: String },
// type: { type: String },
// bufferTime: { type: Number },
// isUsed: { type: Boolean },
// },
// ],
// connections: {
// source: {
// modelUUID: { type: String },
// pointUUID: { type: String },
// },
// targets: [
// {
// modelUUID: { type: String },
// pointUUID: { type: String },
// },
// ],
// },
// });
// // Base Schema
// const BaseSchema = new Schema<IBaseModel>(
// {
// modelfileID: { type: String },
// type: { type: String, enum: ["Conveyor", "Vehicle"] },
// points: {
// type: Schema.Types.Mixed,
// required: true,
// },
// },
// { discriminatorKey: "type", timestamps: true }
// );
// const pointModel = (db: string) => {
// return MainModel(db, "Points", BaseSchema, "Points");
// };
// export default pointModel;

View File

@@ -1,7 +1,6 @@
import mongoose, { Document, Schema } from "mongoose";
import { Document, Schema } from "mongoose";
import MainModel from "../../../connect/mongoose.ts";
// Interface for TypeScript with PascalCase
export interface wallitems extends Document {
export interface WallItems extends Document {
modelUuid: string;
modelName: string;
type: string;
@@ -12,7 +11,6 @@ export interface wallitems extends Document {
scale: [];
}
// Define the Mongoose Schema
const wallItemsSchema: Schema = new Schema({
modelUuid: { type: String, unique: true },
modelName: { type: String },
@@ -24,7 +22,6 @@ const wallItemsSchema: Schema = new Schema({
scale: { type: Array },
});
// export default wallItenmModel;
const wallItenmModel = (db: string) => {
return MainModel(db, "wallitems", wallItemsSchema, "wallitems");
};

View File

@@ -1,7 +1,6 @@
import mongoose, { Document, Schema } from "mongoose";
import { Document, Schema } from "mongoose";
import MainModel from "../../../connect/mongoose.ts";
// Interface for TypeScript with PascalCase
export interface Camera extends Document {
userId: string;
position: {
@@ -21,7 +20,6 @@ export interface Camera extends Document {
};
}
// Define the Mongoose Schema
const cameraSchema: Schema = new Schema({
userId: { type: String },
position: {
@@ -41,7 +39,6 @@ const cameraSchema: Schema = new Schema({
},
});
// export default cameraModel
const cameraModel = (db: string) => {
return MainModel(db, "Camera", cameraSchema, "Camera");
};

View File

@@ -1,13 +1,11 @@
import mongoose, { Document, Schema } from 'mongoose';
import MainModel from '../../../connect/mongoose.ts';
// Interface for TypeScript with PascalCase
export interface environment extends Document {
import { Document, Schema } from "mongoose";
import MainModel from "../../../connect/mongoose.ts";
export interface Environment extends Document {
userId: string;
roofVisibility: boolean
wallVisibility: boolean
roofVisibility: boolean;
wallVisibility: boolean;
}
// Define the Mongoose Schema
const environmentSchema: Schema = new Schema({
userId: { type: String, unique: true },
roofVisibility: { type: Boolean, default: false },
@@ -15,10 +13,7 @@ const environmentSchema: Schema = new Schema({
shadowVisibility: { type: Boolean, default: false },
});
// export default environmentModel;
const environmentModel = (db: string) => {
return MainModel(db, "environments", environmentSchema, "environments")
return MainModel(db, "environments", environmentSchema, "environments");
};
export default environmentModel;
export default environmentModel;

View File

@@ -1,25 +1,22 @@
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
x: { type: Number },
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
position: { type: positionSchema, required: false },
uuid: { type: String, required: false },
});
// 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
layer: { type: Number, required: true },
line: { type: [Vector3], required: true },
type: { type: String, required: false },
});
// export default lineModel;
const lineModel = (db: string) => {
return MainModel(db, "lines", LineSchema, "lines");
};

View File

@@ -1,40 +1,4 @@
// import mongoose, { Schema, Document, model } from "mongoose";
// import MainModel from "../../../connect/mongoose.ts";
// export interface Zone extends Document {
// zoneName: string;
// // zoneUUID: string;
// zonePoints: [];
// centerPoints: [];
// isArchive: boolean;
// createdBy: string;
// sceneID: string;
// // createdBy: mongoose.Types.ObjectId;
// // sceneID: mongoose.Types.ObjectId;
// layer: number;
// }
// const zoneSchema: Schema = new Schema(
// {
// zoneName: { type: String },
// // zoneUUID: { type: String },
// createdBy: { type: String },
// sceneID: { type: String },
// layer: { type: Number },
// centerPoints: { type: Array },
// zonePoints: { type: Array },
// isArchive: { type: Boolean, default: false },
// // createdBy: { type: mongoose.Schema.Types.ObjectId, ref: "User" },
// // sceneID: { type: mongoose.Schema.Types.ObjectId, ref: "Scene" },
// },
// { timestamps: true }
// );
// const dataModel = (db: any) => {
// return MainModel(db, "Zones", zoneSchema, "Zones");
// };
// export default dataModel;
import mongoose, { Schema, Document, model } from "mongoose";
import { Schema, Document } from "mongoose";
import MainModel from "../../../connect/mongoose.ts";
export interface Zone extends Document {
@@ -48,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(
@@ -72,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

@@ -1,87 +1,45 @@
import mongoose, { Document, Schema } from 'mongoose';
import MainModel from '../../connect/mongoose.ts';
import { Document, Schema } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
// Interface for TypeScript with PascalCase
export interface Camera extends Document {
userId: string;
position: {
x: number;
y: number;
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 };
};
}
// Define the Mongoose Schema
const cameraSchema: Schema = new Schema({
userId: { type: String },
position: {
x: { type: Number, required: true },
y: { type: Number, required: true },
z: { type: Number, required: true }
z: { type: Number, required: true },
},
target: {
x: { type: Number, required: true },
y: { type: Number, required: true },
z: { 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 }
}
z: { type: Number, required: true },
},
});
// Model for MongoDB collection
// const cameraModel = model<Camera>("Camera", cameraSchema);
// export default cameraModel;
// const cameraModel = (db: string) => {
// const mongoUrl = process.env.MONGO_URI || '';
// if (!mongoUrl) {
// throw new Error('MONGO_URI environment variable is not set');
// }
// // Connect to the database
// const dbConnection = mongoose.createConnection(mongoUrl, {
// dbName: db, // Specify the database name here
// serverSelectionTimeoutMS: 30000,
// });
// return dbConnection.model<Camera>('Camera', cameraSchema,`Camera`);
// }
// export default cameraModel;
// const cameraModel = (db: string) => {
// const mongoUrl = process.env.MONGO_URI || '';
// if (!mongoUrl) {
// throw new Error('MONGO_URI environment variable is not set');
// }
// const dbConnection = mongoose.createConnection(mongoUrl, {
// dbName: db,
// serverSelectionTimeoutMS: 60000, // Increased timeout
// });
// dbConnection.on('error', (err) => {
// console.error(`MongoDB connection error for database ${db}:`, err);
// });
// dbConnection.once('open', () => {
// console.log(`Connected to MongoDB database: ${db}`);
// });
// return dbConnection.model<Camera>('Camera', cameraSchema, 'Camera');
// };
// export default cameraModel
const cameraModel = (db:string) => {
return MainModel(db, "Camera", cameraSchema, "Camera")
const cameraModel = (db: string) => {
return MainModel(db, "Camera", cameraSchema, "Camera");
};
export default cameraModel;
export default cameraModel;

View File

@@ -1,7 +1,7 @@
import mongoose, { Document, Schema } from "mongoose";
import { Document, Schema } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
// Interface for TypeScript with PascalCase
export interface environment extends Document {
export interface Environment extends Document {
userId: string;
roofVisibility: boolean;
wallVisibility: boolean;
@@ -10,7 +10,6 @@ export interface environment extends Document {
limitDistance: boolean;
}
// Define the Mongoose Schema
const environmentSchema: Schema = new Schema({
userId: { type: String, unique: true },
roofVisibility: { type: Boolean, default: false },
@@ -20,24 +19,6 @@ const environmentSchema: Schema = new Schema({
limitDistance: { type: Boolean, default: true },
});
// Model for MongoDB collection
// const cameraModel = model<Camera>("Camera", cameraSchema);
// export default cameraModel;
// const environmentModel = (db: string) => {
// const mongoUrl = process.env.MONGO_URI || '';
// if (!mongoUrl) {
// throw new Error('MONGO_URI environment variable is not set');
// }
// // Connect to the database
// const dbConnection = mongoose.createConnection(mongoUrl, {
// dbName: db, // Specify the database name here
// serverSelectionTimeoutMS: 30000,
// });
// return dbConnection.model<environment>('environments', environmentSchema,`environments`);
// }
// export default environmentModel;
const environmentModel = (db: string) => {
return MainModel(db, "environments", environmentSchema, "environments");
};

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

@@ -1,29 +1,29 @@
import { Schema, Document, Types } from "mongoose";
import { Schema, Document } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
import {User} from "../user-Model.ts";
import { User } from "../user-Model.ts";
export interface Project extends Document {
projectUuid: string;
projectName: string;
createdBy: User["_id"];
isArchive: boolean
thumbnail: string
sharedUsers: []
projectUuid: string;
projectName: string;
createdBy: User["_id"];
isArchive: boolean;
thumbnail: string;
sharedUsers: [];
}
const projectSchema:Schema = new Schema({
const projectSchema: Schema = new Schema(
{
projectUuid: { type: String, required: true },
projectName: { type: String },
thumbnail: { type: String },
isArchive: { type: Boolean,default:false },
isArchive: { type: Boolean, default: false },
createdBy: { type: Schema.Types.ObjectId, ref: "user" },
sharedUsers: [{ type: Schema.Types.ObjectId, ref: "user" }],
}, { timestamps: true })
sharedUsers: [{ type: Schema.Types.ObjectId, ref: "user" }],
},
{ timestamps: true }
);
const projectModel = (db: string) => {
return MainModel(db, "Projects", projectSchema, "Projects");
return MainModel(db, "Projects", projectSchema, "Projects");
};
export default projectModel;
export default projectModel;

View File

@@ -1,12 +1,9 @@
import mongoose, { Schema, Document, model } from "mongoose";
import { Schema, Document } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
export interface Action extends Document {
pointsUUID: string;
// actionUUID: string;
isArchive: string;
// sceneID: string;
// eventData: {
uuid: string;
name: string;
type: string;
@@ -19,13 +16,11 @@ export interface Action extends Document {
start: string;
end: string;
buffer: number;
// };
}
const actionSchema: Schema = new Schema(
{
pointsUUID: { type: String },
isArchive: { type: Boolean, default: false },
// actionUUID: { type: String },
uuid: { type: String, default: "" },
name: { type: String },
type: { type: String },

View File

@@ -1,179 +1,178 @@
// models/Product.ts
import mongoose, { Schema, Document, Types } from "mongoose";
import { Schema, Document } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
interface AssetEventSchema {
modelUuid: string;
modelName: string;
position: [number, number, number];
rotation: [number, number, number];
state: "idle" | "running" | "stopped" | "disabled" | "error";
};
modelUuid: string;
modelName: string;
position: [number, number, number];
rotation: [number, number, number];
state: "idle" | "running" | "stopped" | "disabled" | "error";
}
interface TriggerSchema {
triggerUuid: string;
triggerName: string;
triggerType: "onComplete" | "onStart" | "onStop" | "delay" | "onError";
delay: number;
triggeredAsset: {
triggeredModel: { modelName: string, modelUuid: string };
triggeredPoint: { pointName: string, pointUuid: string };
triggeredAction: { actionName: string, actionUuid: string };
} | null;
triggerUuid: string;
triggerName: string;
triggerType: "onComplete" | "onStart" | "onStop" | "delay" | "onError";
delay: number;
triggeredAsset: {
triggeredModel: { modelName: string; modelUuid: string };
triggeredPoint: { pointName: string; pointUuid: string };
triggeredAction: { actionName: string; actionUuid: string };
} | null;
}
interface ConveyorPointSchema {
uuid: string;
position: [number, number, number];
rotation: [number, number, number];
action: {
actionUuid: string;
actionName: string;
actionType: "default" | "spawn" | "swap" | "despawn";
material: string;
delay: number | "inherit";
spawnInterval: number | "inherit";
spawnCount: number | "inherit";
triggers: TriggerSchema[];
};
uuid: string;
position: [number, number, number];
rotation: [number, number, number];
action: {
actionUuid: string;
actionName: string;
actionType: "default" | "spawn" | "swap" | "despawn";
material: string;
delay: number | "inherit";
spawnInterval: number | "inherit";
spawnCount: number | "inherit";
triggers: TriggerSchema[];
};
}
interface VehiclePointSchema {
uuid: string;
position: [number, number, number];
rotation: [number, number, number];
action: {
actionUuid: string;
actionName: string;
actionType: "travel";
material: string | null;
unLoadDuration: number;
loadCapacity: number;
pickUpPoint: { x: number; y: number, z: number } | null;
unLoadPoint: { x: number; y: number, z: number } | null;
triggers: TriggerSchema[];
};
uuid: string;
position: [number, number, number];
rotation: [number, number, number];
action: {
actionUuid: string;
actionName: string;
actionType: "travel";
material: string | null;
unLoadDuration: number;
loadCapacity: number;
pickUpPoint: { x: number; y: number; z: number } | null;
unLoadPoint: { x: number; y: number; z: number } | null;
triggers: TriggerSchema[];
};
}
interface RoboticArmPointSchema {
uuid: string;
position: [number, number, number];
rotation: [number, number, number];
actions: {
actionUuid: string;
actionName: string;
actionType: "pickAndPlace";
process: { startPoint: [number, number, number]; endPoint: [number, number, number] };
triggers: TriggerSchema[];
}[];
uuid: string;
position: [number, number, number];
rotation: [number, number, number];
actions: {
actionUuid: string;
actionName: string;
actionType: "pickAndPlace";
process: {
startPoint: [number, number, number];
endPoint: [number, number, number];
};
triggers: TriggerSchema[];
}[];
}
interface MachinePointSchema {
uuid: string;
position: [number, number, number];
rotation: [number, number, number];
action: {
actionUuid: string;
actionName: string;
actionType: "process";
processTime: number;
swapMaterial: string;
triggers: TriggerSchema[];
};
uuid: string;
position: [number, number, number];
rotation: [number, number, number];
action: {
actionUuid: string;
actionName: string;
actionType: "process";
processTime: number;
swapMaterial: string;
triggers: TriggerSchema[];
};
}
interface StoragePointSchema {
uuid: string;
position: [number, number, number];
rotation: [number, number, number];
action: {
actionUuid: string;
actionName: string;
actionType: "storage";
materials: { materialName: string; materialId: string; }[];
storageCapacity: number;
};
uuid: string;
position: [number, number, number];
rotation: [number, number, number];
action: {
actionUuid: string;
actionName: string;
actionType: "storage";
materials: { materialName: string; materialId: string }[];
storageCapacity: number;
};
}
interface ConveyorEventSchema extends AssetEventSchema {
type: "transfer";
speed: number;
points: ConveyorPointSchema[];
type: "transfer";
speed: number;
points: ConveyorPointSchema[];
}
interface VehicleEventSchema extends AssetEventSchema {
type: "vehicle";
speed: number;
point: VehiclePointSchema;
type: "vehicle";
speed: number;
point: VehiclePointSchema;
}
interface RoboticArmEventSchema extends AssetEventSchema {
type: "roboticArm";
speed: number;
point: RoboticArmPointSchema;
type: "roboticArm";
speed: number;
point: RoboticArmPointSchema;
}
interface MachineEventSchema extends AssetEventSchema {
type: "machine";
// speed: number;
point: MachinePointSchema;
type: "machine";
point: MachinePointSchema;
}
interface StorageEventSchema extends AssetEventSchema {
type: "storageUnit";
// speed: number;
point: StoragePointSchema;
type: "storageUnit";
point: StoragePointSchema;
}
interface IPointModel extends Document {
modelUuid:String,
modelName:String,
position:String,
rotation:String,
state:String,
productId:String,
isArchive:boolean,
type: "transfer" | "vehicle" | "roboticArm" | "machine" |"storageUnit";
modelUuid: String;
modelName: String;
position: String;
rotation: String;
state: String;
productId: String;
isArchive: boolean;
type: "transfer" | "vehicle" | "roboticArm" | "machine" | "storageUnit";
speed: number;
point: VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema
points: ConveyorEventSchema[]
point:
| VehicleEventSchema
| RoboticArmEventSchema
| MachineEventSchema
| StorageEventSchema;
points: ConveyorEventSchema[];
}
// type EventsSchema = ConveyorEventSchema | VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema;
const BaseEventSchema = new Schema<IPointModel>(
{
modelUuid: { type: String, required: true },
modelName: { type: String, required: true },
position: { type: [Number], required: true },
rotation: { type: [Number], required: true },
speed: { type: Number,},
state: {
type: String,
enum: ["idle", "running", "stopped", "disabled", "error"],
default: "idle"
},
type: {
type: String,
required: true,
enum: ["transfer", "vehicle", "roboticArm", "machine", "storageUnit"]
},
point:{
type:Schema.Types.Mixed,
},
points:{
type:Schema.Types.Mixed,
},
productId: { type:String,required: true },
isArchive: { type: Boolean, default: false }
{
modelUuid: { type: String, required: true },
modelName: { type: String, required: true },
position: { type: [Number], required: true },
rotation: { type: [Number], required: true },
speed: { type: Number },
state: {
type: String,
enum: ["idle", "running", "stopped", "disabled", "error"],
default: "idle",
},
{ discriminatorKey: "type", timestamps: true }
);
const EventsDataModel = (db: string) => {
return MainModel(db, "EventDatas", BaseEventSchema, "EventDatas");
};
export default EventsDataModel;
type: {
type: String,
required: true,
enum: ["transfer", "vehicle", "roboticArm", "machine", "storageUnit"],
},
point: {
type: Schema.Types.Mixed,
},
points: {
type: Schema.Types.Mixed,
},
productId: { type: String, required: true },
isArchive: { type: Boolean, default: false },
},
{ discriminatorKey: "type", timestamps: true }
);
const EventsDataModel = (db: string) => {
return MainModel(db, "EventDatas", BaseEventSchema, "EventDatas");
};
export default EventsDataModel;

View File

@@ -1,97 +0,0 @@
// import mongoose, { Schema, Document, model } from "mongoose";
// import MainModel from "../../connect/mongoose.ts";
// export interface ProductFlow extends Document {
// productName: string;
// ProductData: [
// {
// AssetName: string;
// Assetuuid: string;
// paths: {
// Points: [
// {
// pointuuid: string;
// actions: [mongoose.Types.ObjectId];
// triggers: [mongoose.Types.ObjectId];
// position: [];
// rotation: [number];
// connections: {
// source: {
// // modelUUID: { type: String };
// pointUUID: string;
// };
// targets: [
// {
// // modelUUID: { type: String };
// pointUUID: string;
// }
// ];
// };
// }
// ];
// // endPoint: {
// // pointuuid: string;
// // actions: [mongoose.Types.ObjectId];
// // triggers: [mongoose.Types.ObjectId];
// // position: [];
// // rotation: [];
// // };
// };
// isArchive: false;
// }
// ];
// isArchive: false;
// }
// const productFlowSchema: Schema = new Schema(
// {
// productName: { type: String },
// ProductData: [
// {
// AssetName: { type: String },
// Assetuuid: { type: String },
// paths: {
// Points: [
// {
// pointuuid: { type: String },
// actions: [
// { type: mongoose.Schema.Types.ObjectId, ref: "Actions" },
// ],
// triggers: [
// { type: mongoose.Schema.Types.ObjectId, ref: "Triggers" },
// ],
// connections: {
// source: {
// // modelUUID: { type: String };
// pointUUID: { type: String },
// },
// targets: [
// {
// // modelUUID: { type: String };
// pointUUID: { type: String },
// },
// ],
// },
// position: { type: Array },
// rotation: {
// type: [Number],
// validate: {
// validator: function (value: number[]) {
// return value && value.length > 0; // Ensures it's only stored if it has values
// },
// message: "Rotation array should not be empty",
// },
// },
// },
// ],
// },
// isArchive: { type: Boolean, default: false },
// },
// ],
// },
// { timestamps: true }
// );
// const productFlowModel = (db: any) => {
// return MainModel(db, "ProductFlow", productFlowSchema, "ProductFlow");
// };
// export default productFlowModel;

View File

@@ -1,24 +1,20 @@
import mongoose, { Schema, Document, model } from "mongoose";
import { Schema, Document } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
export interface product extends Document {
export interface Product extends Document {
productName: string;
productId: string;
eventsData: [];
isArchive: boolean;
}
// Product Schema
const ProductSchema = new Schema({
productName: { type: String, required: true },
productId: { type: String, required: true },
isArchive: { type: Boolean, default: false },
});
const ProductModel = (db: string) => {
return MainModel(db, "Product", ProductSchema, "Product");
};
export default ProductModel;
export default ProductModel;

View File

@@ -1,11 +1,9 @@
import mongoose, { Schema, Document, model } from "mongoose";
import { Schema, Document } from "mongoose";
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

@@ -1,4 +1,4 @@
import mongoose, { Document, Schema } from "mongoose";
import { Document, Schema } from "mongoose";
import MainModel from "../connect/mongoose.ts";
export interface User extends Document {
userName: String;
@@ -7,9 +7,8 @@ export interface User extends Document {
role: String;
profilePicture: String;
isShare:Boolean,
activeStatus:string
isShare: Boolean;
activeStatus: string;
}
const signupschema: Schema = new Schema({
userName: {
@@ -33,37 +32,19 @@ const signupschema: Schema = new Schema({
},
profilePicture: {
type: String,
// default: "default-profile-picture.jpg"
},
isShare:{
type:Boolean,
default:false
},
activeStatus:{
type:String,
isShare: {
type: Boolean,
default: false,
},
activeStatus: {
type: String,
enum: ["online", "offline"],
default: "offline"
}
default: "offline",
},
});
// const userModel = (db: string) => {
// const mongoUrl = process.env.MONGO_URI || "";
// if (!mongoUrl) {
// throw new Error("MONGO_URI environment variable is not set");
// }
// // Connect to the database
// const dbConnection = mongoose.createConnection(mongoUrl, {
// dbName: db, // Specify the database name here
// serverSelectionTimeoutMS: 30000,
// });
// // Return the model
// return dbConnection.model("Users", signupschema, "Users");
// };
// export default userModel;
const userModel = (db:string) => {
return MainModel(db, "Users", signupschema, "Users")
const userModel = (db: string) => {
return MainModel(db, "Users", signupschema, "Users");
};
export default userModel;
export default userModel;

View File

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

View File

@@ -1,7 +1,7 @@
import mongoose, { Schema, Document, model } from "mongoose";
import { Schema, Document } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
export interface floatingWidget extends Document {
export interface FloatingWidget extends Document {
className: string;
iconName: string;
header: string;

View File

@@ -1,8 +1,7 @@
import mongoose, { Schema, Document, model } from "mongoose";
import mongoose, { Schema, Document } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
export interface Panel extends Document {
// zoneId: mongoose.Types.ObjectId;
zoneId: string;
panelName: string;
widgets: [mongoose.Types.ObjectId];
@@ -10,8 +9,7 @@ export interface Panel extends Document {
}
const panelSchema: Schema = new Schema(
{
// zoneId: { type: mongoose.Schema.Types.ObjectId, ref: "Zone" },
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 mongoose, { Schema, Document, model } 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, model } from "mongoose";
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

@@ -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

@@ -1,31 +1,33 @@
import { Request, Response, NextFunction } from 'express';
import * as Jwt from 'jsonwebtoken'; // Correct way to import jsonwebtoken
import { Request, Response, NextFunction } from "express";
import * as Jwt from "jsonwebtoken";
// Define a new interface extending Request
interface AuthenticatedRequest extends Request {
user?: {
email: string;
// Add more fields as needed based on your JWT payload
};
}
const tokenGenerator = (email: string) => {
const token = Jwt.sign({ email: email }, "Milestone", {
expiresIn: "3hours",
});
return token;
};
const token = Jwt.sign({ email: email }, "Milestone", {
expiresIn: "3hours",
});
return token;
};
const tokenValidator = (req: AuthenticatedRequest, res: Response, next: NextFunction): void => {
const tokenValidator = (
req: AuthenticatedRequest,
res: Response,
next: NextFunction
): void => {
const token: string | undefined = req.headers.token as string | undefined;
if (!token) {
res.status(403).json({
msg: "No token present",
});
return; // Make sure to return after sending a response
return;
}
try {
const decoded = Jwt.verify(token,"Milestone") as { email: string }; // adjust if your JWT payload has more fields
const decoded = Jwt.verify(token, "Milestone") as { email: string };
req.user = decoded;
next();
} catch (err) {
@@ -35,4 +37,4 @@ const tokenValidator = (req: AuthenticatedRequest, res: Response, next: NextFunc
}
};
export { tokenValidator,tokenGenerator };
export { tokenValidator, tokenGenerator };

View File

@@ -1,80 +1,87 @@
import projectModel from "../../model/project/project-model.ts";
import userModel from "../../model/user-Model.ts";
import { Types } from 'mongoose';
import { Types } from "mongoose";
interface CreateProjectInput {
projectName: string;
projectUuid: string;
createdBy: string; // user ID
createdBy: string;
thumbnail?: string;
sharedUsers?: string[];
organization:string
organization: string;
}
export const createProject = async (data: CreateProjectInput) => {
console.log('data: ', data);
try {
const{projectName,projectUuid,createdBy,thumbnail,sharedUsers,organization}=data
console.log('createdBy: ', typeof createdBy);
const userExisting =await existingUser(createdBy,organization)
if (!userExisting)
{
return {
status: "user_not_found",
};
export const createProject = async (data: CreateProjectInput) => {
try {
const {
projectName,
projectUuid,
createdBy,
thumbnail,
sharedUsers,
organization,
} = data;
const userExisting = await existingUser(createdBy, organization);
if (!userExisting) {
return {
status: "user_not_found",
};
}
const projectExisting = await existingProject(projectUuid, organization);
}
const projectExisting = await existingProject(projectUuid, organization);
console.log('projectExisting: ', projectExisting);
if (projectExisting) {
return {
status: "project_exists",
project: projectExisting,
};
}
const project = await projectModel(organization).create({
projectName: projectName,
projectUuid: projectUuid,
createdBy: createdBy,
thumbnail: thumbnail || "",
sharedUsers: sharedUsers || [],
isArchive: false,
});
return {
status: "success",
project: project,
};
} catch (error) {
console.log('error: ', error);
return {
exists: false,
};
if (projectExisting) {
return {
status: "project_exists",
project: projectExisting,
};
}
const project = await projectModel(organization).create({
projectName: projectName,
projectUuid: projectUuid,
createdBy: createdBy,
thumbnail: thumbnail || "",
sharedUsers: sharedUsers || [],
isArchive: false,
});
return {
status: "success",
project: project,
};
} catch (error) {
return {
exists: false,
};
}
};
export const existingProject = async (projectUuid: string,organization:string) => {
console.log("projectUuid",typeof projectUuid);
const projectData= await projectModel(organization).findOne({projectUuid:projectUuid,isArchive:false})
console.log('projectData: ', projectData);
return projectData
export const existingProject = async (
projectUuid: string,
organization: string
) => {
const projectData = await projectModel(organization).findOne({
projectUuid: projectUuid,
isArchive: false,
});
return projectData;
};
export const existingUser = async (createdBy: string, organization: string) => {
console.log('createdBy: ', typeof createdBy);
if (!Types.ObjectId.isValid(createdBy)) {
console.log('Invalid ObjectId format');
return null;
}
const userData = await userModel(organization).findOne({
_id: createdBy,
});
console.log('userData:', userData);
return userData; // ✅ Make sure you return it
};
export const archiveProject = async (projectId: string,organization:string) => {
return await projectModel(organization).findByIdAndUpdate(projectId, { isArchive: true }, { new: true });
if (!Types.ObjectId.isValid(createdBy)) {
return null;
}
const userData = await userModel(organization).findOne({
_id: createdBy,
});
return userData;
};
export const archiveProject = async (
projectId: string,
organization: string
) => {
return await projectModel(organization).findByIdAndUpdate(
projectId,
{ isArchive: true },
{ new: true }
);
};

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"],
};