schema modal add
This commit is contained in:
commit
7a67405d2a
|
@ -0,0 +1,50 @@
|
|||
import mongoose, { Schema, Connection, Model } from "mongoose";
|
||||
|
||||
interface ConnectionCache {
|
||||
[key: string]: Connection;
|
||||
}
|
||||
|
||||
const connections: ConnectionCache = {};
|
||||
|
||||
const MainModel = <T>(
|
||||
db: string,
|
||||
modelName: string,
|
||||
schema: Schema<T>,
|
||||
collectionName: string
|
||||
): 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
|
||||
maxPoolSize: 50,
|
||||
};
|
||||
// Check if the connection already exists
|
||||
if (connections[db]) {
|
||||
return connections[db].model<T>(modelName, schema, collectionName);
|
||||
}
|
||||
|
||||
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}`);
|
||||
});
|
||||
|
||||
db1.on("error", (err) => {
|
||||
console.error(`MongoDB connection error for database ${db}:`, err.message);
|
||||
});
|
||||
|
||||
return db1.model<T>(modelName, schema, collectionName);
|
||||
} catch (error) {
|
||||
console.error("Database connection error:", (error as Error).message);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export default MainModel;
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
import mongoose, { Document, Schema } from 'mongoose';
|
||||
import MainModel from '../../connect/mongoose';
|
||||
|
||||
// Interface for TypeScript with PascalCase
|
||||
export interface floorItenms extends Document {
|
||||
modeluuid: string;
|
||||
modelfileID: string;
|
||||
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 },
|
||||
rotation: {
|
||||
x: { type: Number, required: true },
|
||||
y: { type: Number, required: true },
|
||||
z: { type: Number, required: true }
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// export default floorItemsModel;
|
||||
const floorItemsModel = (db: string) => {
|
||||
return MainModel(db, "floorItems", floorItemsSchema, "floorItems")
|
||||
};
|
||||
export default floorItemsModel;
|
|
@ -0,0 +1,34 @@
|
|||
import mongoose, { Document, Schema } from 'mongoose';
|
||||
import MainModel from '../../connect/mongoose';
|
||||
// Interface for TypeScript with PascalCase
|
||||
export interface wallitems extends Document {
|
||||
modeluuid: string;
|
||||
modelname: string
|
||||
type: string
|
||||
csgposition: []
|
||||
csgscale: []
|
||||
position: []
|
||||
quaternion: []
|
||||
scale: []
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Define the Mongoose Schema
|
||||
const wallItemsSchema: Schema = new Schema({
|
||||
modeluuid: { type: String, unique: true },
|
||||
modelname: { type: String },
|
||||
type: { type: String },
|
||||
csgposition: { type: Array },
|
||||
csgscale: { type: Array, },
|
||||
position: { type: Array },
|
||||
quaternion: { type: Array },
|
||||
scale: { type: Array }
|
||||
});
|
||||
|
||||
|
||||
// export default wallItenmModel;
|
||||
const wallItenmModel = (db: string) => {
|
||||
return MainModel(db, "wallitems", wallItemsSchema, "wallitems")
|
||||
};
|
||||
export default wallItenmModel;
|
|
@ -0,0 +1,49 @@
|
|||
import mongoose, { Document, Schema } from 'mongoose';
|
||||
import MainModel from '../../connect/mongoose';
|
||||
|
||||
// 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 }
|
||||
}
|
||||
rotation: {
|
||||
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 }
|
||||
},
|
||||
target: {
|
||||
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 }
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// export default cameraModel
|
||||
const cameraModel = (db: string) => {
|
||||
return MainModel(db, "Camera", cameraSchema, "Camera")
|
||||
};
|
||||
export default cameraModel;
|
|
@ -0,0 +1,24 @@
|
|||
import mongoose, { Document, Schema } from 'mongoose';
|
||||
import MainModel from '../../connect/mongoose';
|
||||
// Interface for TypeScript with PascalCase
|
||||
export interface environment extends Document {
|
||||
userId: string;
|
||||
roofVisibility: boolean
|
||||
wallVisibility: boolean
|
||||
}
|
||||
|
||||
// Define the Mongoose Schema
|
||||
const environmentSchema: Schema = new Schema({
|
||||
userId: { type: String, unique: true },
|
||||
roofVisibility: { type: Boolean, default: false },
|
||||
wallVisibility: { type: Boolean, default: false },
|
||||
shadowVisibility: { type: Boolean, default: false },
|
||||
});
|
||||
|
||||
|
||||
|
||||
// export default environmentModel;
|
||||
const environmentModel = (db: string) => {
|
||||
return MainModel(db, "environments", environmentSchema, "environments")
|
||||
};
|
||||
export default environmentModel;
|
|
@ -0,0 +1,28 @@
|
|||
import mongoose, { Document, Schema } from "mongoose";
|
||||
import MainModel from "../../connect/mongoose";
|
||||
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
|
||||
});
|
||||
|
||||
|
||||
|
||||
// export default lineModel;
|
||||
const lineModel = (db: string) => {
|
||||
return MainModel(db, "lines", LineSchema, "lines")
|
||||
};
|
||||
export default lineModel;
|
|
@ -0,0 +1,26 @@
|
|||
import mongoose, { Document, ObjectId, Schema } from "mongoose";
|
||||
import MainModel from "../../connect/mongoose";
|
||||
export interface zoneSchema extends Document {
|
||||
zoneId: string;
|
||||
zoneName: string
|
||||
createBy: mongoose.Types.ObjectId
|
||||
points: []
|
||||
layer: Number
|
||||
|
||||
}
|
||||
|
||||
// Define the Mongoose Schema
|
||||
const zoneSchema: Schema = new Schema({
|
||||
zoneId: { type: String },
|
||||
zoneName: { type: String },
|
||||
createBy: { type: Schema.Types.ObjectId, ref: "Users", },
|
||||
points: { type: Array },
|
||||
layer: { type: Number, required: true },
|
||||
});
|
||||
|
||||
|
||||
// export default zoneModel;
|
||||
const zoneModel = (db: string) => {
|
||||
return MainModel(db, "zones", zoneSchema, "zones")
|
||||
};
|
||||
export default zoneModel;
|
|
@ -0,0 +1,55 @@
|
|||
import mongoose, { Document, Schema } from "mongoose";
|
||||
import MainModel from "../connect/mongoose";
|
||||
export interface User extends Document {
|
||||
userName: String;
|
||||
email: String;
|
||||
password: String;
|
||||
|
||||
role: String;
|
||||
profilePicture: String;
|
||||
isShare: Boolean,
|
||||
activeStatus: string
|
||||
|
||||
}
|
||||
const signupschema: Schema = new Schema({
|
||||
userName: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
unique: true,
|
||||
required: true,
|
||||
},
|
||||
password: {
|
||||
type: String,
|
||||
min: 8,
|
||||
required: true,
|
||||
},
|
||||
role: {
|
||||
type: String,
|
||||
default: "User",
|
||||
enum: ["User", "Admin", "Project Manager", "Manager", "Owner"],
|
||||
},
|
||||
profilePicture: {
|
||||
type: String,
|
||||
// default: "default-profile-picture.jpg"
|
||||
},
|
||||
isShare: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
activeStatus: {
|
||||
type: String,
|
||||
enum: ["online", "offline"],
|
||||
default: "offline"
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
// export default userModel;
|
||||
const userModel = (db: string) => {
|
||||
return MainModel(db, "Users", signupschema, "Users")
|
||||
};
|
||||
export default userModel;
|
Loading…
Reference in New Issue