V2 API for visualization gomathi part completed

This commit is contained in:
2025-03-28 17:44:49 +05:30
parent dc5d7c2ebf
commit 2b34040d8c
17 changed files with 658 additions and 160 deletions

View File

@@ -16,7 +16,7 @@ const MainModel = <T>(
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
authSource: process.env.MONGO_AUTH_DB || "admin", // Default to 'admin' if not provided
maxPoolSize: 50,
};
@@ -24,9 +24,9 @@ const MainModel = <T>(
if (connections[db]) {
return connections[db].model<T>(modelName, schema, collectionName);
}
try {
const db1 = mongoose.createConnection(db1_url,authOptions);
const db1 = mongoose.createConnection(db1_url, authOptions);
// Cache the connection
connections[db] = db1;
@@ -37,7 +37,10 @@ const MainModel = <T>(
});
db1.on("error", (err) => {
console.error(`MongoDB connection error for database ${db}:`, err.message);
console.error(
`MongoDB connection error for database ${db}:`,
err.message
);
});
return db1.model<T>(modelName, schema, collectionName);
@@ -48,4 +51,3 @@ const MainModel = <T>(
};
export default MainModel;

View File

@@ -1,6 +1,16 @@
import mongoose, { Document, Schema } from "mongoose";
import MainModel from "../../../connect/mongoose.ts";
interface IAction {
uuid: string;
name: string;
type: string;
material: string;
delay: string;
spawnInterval: string;
isUsed: boolean;
}
// Interface for TypeScript with PascalCase
export interface assetData extends Document {
modeluuid: string;
@@ -42,16 +52,16 @@ const assetDataSchema: Schema = new Schema({
uuid: { type: String },
position: { type: Array },
rotation: { type: Array },
actions: [{ type: mongoose.Schema.Types.ObjectId, ref: "Widget" }],
triggers: [{ type: mongoose.Schema.Types.ObjectId, ref: "Widget" }],
actions: [{ type: mongoose.Schema.Types.ObjectId, ref: "Actions" }],
triggers: [{ type: mongoose.Schema.Types.ObjectId, ref: "Triggers" }],
},
],
isLocked: { type: Boolean },
isVisible: { type: Boolean },
rotation: {
x: { type: Number, required: true },
y: { type: Number, required: true },
z: { type: Number, required: true },
x: { type: Number },
y: { type: Number },
z: { type: Number },
},
});

View File

@@ -0,0 +1,80 @@
import mongoose, { Schema, Document } from "mongoose";
import MainModel from "../../../connect/mongoose.ts";
interface IAction {
uuid: string;
name: string;
type: string;
material: string;
delay: string;
spawnInterval: string;
isUsed: boolean;
}
// interface IConnection {
// source: { pathUUID: string; pointUUID: string };
// targets: string[];
// }
interface IPoint {
uuid: string;
position: number[];
rotation: number[];
actions: IAction[];
triggers: string[];
// connections: IConnection;
}
interface IBaseModel extends Document {
modelfileID: string;
type: "Conveyor" | "Vehicle";
points: IPoint[] | IPoint;
speed: number;
}
// Base Schema
const PointSchema = new Schema<IPoint>({
uuid: { type: String, required: true },
position: { type: [Number], required: true },
rotation: { type: [Number], required: true },
actions: [
{
uuid: { type: String, default: "" },
name: { type: String, required: true },
type: { type: String, required: true },
material: { type: String, required: true },
delay: { type: String, required: true },
spawnInterval: { type: String, required: true },
isUsed: { type: Boolean, required: true },
},
],
triggers: { type: [String], default: [] },
// connections: {
// source: {
// pathUUID: { type: String, required: true },
// pointUUID: { type: String, required: true },
// },
// targets: { type: [String], default: [] },
// },
});
const BaseSchema = new Schema<IBaseModel>(
{
modelfileID: { type: String },
type: { type: String, enum: ["Conveyor", "Vehicle"] },
points: {
type: Schema.Types.Mixed,
required: true,
},
speed: { type: Number },
},
{ discriminatorKey: "type", timestamps: true }
);
const pointModel = (db: string) => {
return MainModel(db, "Points", BaseSchema, "Points");
};
export default pointModel;
// const pointModel = mongoose.model<IBaseModel>("Points", BaseSchema, "Points");
// export default pointModel;

View File

@@ -1,59 +0,0 @@
import mongoose, { Document, Schema } from "mongoose";
import MainModel from "../../../connect/mongoose.ts";
// Interface for TypeScript with PascalCase
export interface Points extends Document {
modelfileID: string;
points: {
uuid: string;
position: number[];
rotation: number[];
actions: string[];
triggers: string[];
}[];
}
const defaultPoints = [
{
uuid: "",
position: [0, 1.25, 3.3],
rotation: [0, 0, 0],
actions: [],
triggers: [],
},
{
uuid: "",
position: [0, 1.25, 3.3],
rotation: [0, 0, 0],
actions: [],
triggers: [],
},
{
uuid: "",
position: [0, 1.25, 3.3],
rotation: [0, 0, 0],
actions: [],
triggers: [],
},
];
// Define the Mongoose Schema
const pointSchema: Schema = new Schema({
modelfileID: { type: String, required: true },
points: {
type: [
{
uuid: { type: String },
position: { type: [Number], default: [0, 1.25, 3.3] },
rotation: { type: [Number], default: [0, 0, 0] },
actions: { type: [String], default: [] },
triggers: { type: [String], default: [] },
},
],
default: defaultPoints,
},
});
const pointModel = (db: string) => {
return MainModel(db, "Points", pointSchema, "Points");
};
export default pointModel;

View File

@@ -19,7 +19,6 @@ const eventSchema: Schema = new Schema(
pointsUUID: { type: String },
isArchive: { type: Boolean, default: false },
actionUUID: { type: String },
sceneID: { type: String },
eventData: [
{
uuid: { type: String },
@@ -34,6 +33,6 @@ const eventSchema: Schema = new Schema(
);
const actionModel = (db: any) => {
return MainModel(db, "Events", eventSchema, "Events");
return MainModel(db, "Actions", eventSchema, "Actions");
};
export default actionModel;

View File

@@ -14,7 +14,7 @@ export interface widget extends Document {
isArchive: boolean;
panelID: mongoose.Types.ObjectId;
Data: {
measurement: Record<string, any>;
measurement: [any];
duration: string;
};
}
@@ -29,10 +29,7 @@ const widgetSchema: Schema = new Schema(
fontFamily: { type: String },
fontStyle: { type: String },
Data: {
measurements: {
type: Object,
default: {},
},
measurements: { type: Array, default: [] },
duration: { type: String, default: "1hr" },
},
fontWeight: { type: String },