Schema Model - new Version Added

This commit is contained in:
2025-05-17 11:15:53 +05:30
parent 5566b74633
commit 1c55013c2b
18 changed files with 833 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
import { Schema, Document } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
import { User } from "./userAuthModel.ts";
export interface Token extends Document {
userId: User["_id"];
isArchieve: Boolean;
refreshToken: string;
resetTokenExpiry?: Date;
resetToken: string;
}
const tokenSchema: Schema = new Schema({
userId: { type: Schema.Types.ObjectId, ref: "User" },
isArchieve: { type: Boolean, default: false },
token: { type: String },
refreshToken: { type: String },
tokenCreatedAt: { type: Date },
resetToken: { type: String },
resetTokenExpiry: { type: Date },
});
const tokenType = (db: any) => {
return MainModel(db, "Token", tokenSchema, "Token");
};
export default tokenType;

View File

@@ -0,0 +1,46 @@
import { Schema, Document } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
import { User } from "./userAuthModel.ts";
export interface UserData extends Document {
userId: User["_id"];
notificationEnable: boolean;
About: string;
isArchieve: boolean;
Role: string;
Profilepicture: string;
recentlyViewed: string[];
CheckIn: number;
CheckOut: number;
}
const UserDataSchema: Schema = new Schema({
userId: { type: Schema.Types.ObjectId, ref: "User" },
isArchieve: { type: Boolean, default: false },
notificationEnable: { type: Boolean, default: false },
About: {
type: String,
},
Role: {
type: String,
default: "User",
enum: ["User", "Admin"],
},
recentlyViewed: {
type: [String],
default: [],
},
Profilepicture: {
type: String,
// default: "default-profile-picture.jpg"
},
CheckIn: {
type: Number,
},
CheckOut: {
type: Number,
},
});
const UsersDataModel = (db: any) => {
return MainModel(db, "UsersData", UserDataSchema, "UsersData");
};
export default UsersDataModel;

View File

@@ -0,0 +1,34 @@
import { Schema, Document } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
export interface User extends Document {
Username: string;
Email: string;
Password: string;
isArchieve: boolean;
visitorBrowserID: string;
lastPasswordReset: number;
}
const signupschema: Schema = new Schema({
Username: {
type: String,
required: true,
},
Email: {
type: String,
unique: true,
required: true,
},
Password: {
type: String,
min: 8,
// required: true,
},
isArchieve: { type: Boolean, default: false },
lastPasswordReset: { type: Number },
visitorBrowserID: { type: String },
});
const userModel = (db: any) => {
return MainModel(db, "User", signupschema, "User");
};
export default userModel;

View File

@@ -0,0 +1,71 @@
import { Document, 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";
interface ICommonBase {
type: string;
}
interface IPointsConveyor extends ICommonBase {
points?: {
Uuid: string;
position: [number, number, number];
rotation: [number, number, number];
}[];
}
interface IPoint extends ICommonBase {
point?: {
Uuid: string;
position: [number, number, number];
rotation: [number, number, number];
};
}
export interface AssetData extends Document {
userId: User["_id"];
projectId: Project["_id"];
versionId: Version["_id"];
modelUuid: string;
modelfileID: string;
modelName: string;
isLocked: boolean;
type: string;
isVisible: boolean;
isArchive: false;
// points: [] | {};
position: [];
rotation: {
x: number;
y: number;
z: number;
};
speed: number | string;
eventData: IPoint | IPointsConveyor;
}
const assetDataSchema: Schema = new Schema({
userId: { type: Schema.Types.ObjectId, ref: "User" },
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
isArchive: { type: Boolean, default: false },
modelUuid: { type: String },
modelfileID: { type: String },
modelName: { type: String },
type: { type: String },
position: { type: Array },
rotation: {
x: { type: Number },
y: { type: Number },
z: { type: Number },
},
speed: { type: Schema.Types.Mixed },
isLocked: { type: Boolean },
isVisible: { type: Boolean },
eventData: {
type: Schema.Types.Mixed,
},
});
const assetModel = (db: string) => {
return MainModel(db, "Assets", assetDataSchema, "Assets");
};
export default assetModel;

View File

@@ -0,0 +1,51 @@
import { Document, 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";
export interface Camera extends Document {
userId: User["_id"];
projectId: Project["_id"];
versionId: Version["_id"];
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 };
};
}
const cameraSchema: Schema = new Schema({
userId: { type: Schema.Types.ObjectId, ref: "User" },
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
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 },
},
});
const cameraModel = (db: string) => {
return MainModel(db, "Camera", cameraSchema, "Camera");
};
export default cameraModel;

View File

@@ -0,0 +1,29 @@
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";
const positionSchema = new mongoose.Schema({
x: { type: Number }, // Optional position fields
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
});
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
});
const lineModel = (db: string) => {
return MainModel(db, "lines", LineSchema, "lines");
};
export default lineModel;

View File

@@ -0,0 +1,37 @@
import { Document, 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";
export interface WallItems extends Document {
userId: User["_id"];
projectId: Project["_id"];
versionId: Version["_id"];
modelUuid: string;
modelName: string;
type: string;
csgposition: [];
csgscale: [];
position: [];
quaternion: [];
scale: [];
}
const wallItemsSchema: Schema = new Schema({
userId: { type: Schema.Types.ObjectId, ref: "User" },
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
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 },
});
const wallItemModel = (db: string) => {
return MainModel(db, "wallitems", wallItemsSchema, "wallitems");
};
export default wallItemModel;

View File

@@ -0,0 +1,50 @@
import { Schema, Document } 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";
export interface Zone extends Document {
zoneName: string;
zoneId: string;
zonePoints: [];
viewPortCenter: [];
viewPortposition: [];
isArchive: boolean;
panelOrder: string[];
lockedPanel: string[];
createdBy: User["_id"];
projectId: Project["_id"];
versionId: Version["_id"];
layer: number;
}
const zoneSchema: Schema = new Schema(
{
zoneName: { type: String },
zoneId: { type: String },
createdBy: { type: Schema.Types.ObjectId, ref: "User" },
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
layer: { type: Number },
points: { type: Array },
isArchive: { type: Boolean, default: false },
panelOrder: {
type: [String],
enum: ["left", "right", "top", "bottom"],
},
viewPortCenter: { type: Array, required: true },
viewPortposition: { type: Array, required: true },
lockedPanel: {
type: [String],
default: [],
enum: ["left", "right", "top", "bottom"],
},
// createdBy: { type: mongoose.Schema.Types.ObjectId, ref: "User" },
// sceneID: { type: mongoose.Schema.Types.ObjectId, ref: "Scene" },
},
{ timestamps: true }
);
const zoneModel = (db: any) => {
return MainModel(db, "zones", zoneSchema, "zones");
};
export default zoneModel;

View File

@@ -0,0 +1,25 @@
import { Document, Schema } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
import { User } from "../Auth/userAuthModel.ts";
export interface Environment extends Document {
userId: User["_id"];
roofVisibility: boolean;
wallVisibility: boolean;
renderDistance: number;
shadowVisibility: boolean;
limitDistance: boolean;
}
const environmentSchema: Schema = new Schema({
userId: { type: Schema.Types.ObjectId, ref: "User", unique: true },
roofVisibility: { type: Boolean, default: false },
wallVisibility: { type: Boolean, default: false },
shadowVisibility: { type: Boolean, default: false },
renderDistance: { type: Number, default: 40 },
limitDistance: { type: Boolean, default: true },
});
const environmentModel = (db: string) => {
return MainModel(db, "Environment", environmentSchema, "Environment");
};
export default environmentModel;

View File

@@ -0,0 +1,39 @@
import { Schema, Document } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
import { User } from "../Auth/userAuthModel.ts";
export interface Project extends Document {
projectUuid: string;
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 },
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 }
);
const projectModel = (db: string) => {
return MainModel(db, "Projects", projectSchema, "Projects");
};
export default projectModel;

View File

@@ -0,0 +1,182 @@
// models/Product.ts
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";
}
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;
}
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[];
};
}
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[];
};
}
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[];
}[];
}
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[];
};
}
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;
};
}
interface ConveyorEventSchema extends AssetEventSchema {
type: "transfer";
speed: number;
points: ConveyorPointSchema[];
}
interface VehicleEventSchema extends AssetEventSchema {
type: "vehicle";
speed: number;
point: VehiclePointSchema;
}
interface RoboticArmEventSchema extends AssetEventSchema {
type: "roboticArm";
speed: number;
point: RoboticArmPointSchema;
}
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;
isArchive: boolean;
type: "transfer" | "vehicle" | "roboticArm" | "machine" | "storageUnit";
speed: number;
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 },
},
{ discriminatorKey: "type", timestamps: true }
);
const EventsDataModel = (db: string) => {
return MainModel(db, "EventDatas", BaseEventSchema, "EventDatas");
};
export default EventsDataModel;

View File

@@ -0,0 +1,26 @@
import { Schema, Document } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
import { Project } from "../Project/project-model.ts";
import { Version } from "../Version/versionModel.ts";
export interface Product extends Document {
productName: string;
productId: string;
projectId: Project["_id"];
versionId: Version["_id"];
eventsData: [];
isArchive: boolean;
}
const ProductSchema = new Schema({
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
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;

View File

@@ -0,0 +1,27 @@
import { Schema, Document } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
import { Project } from "../Project/project-model.ts";
import { User } from "../Auth/userAuthModel.ts";
export interface Version extends Document {
versionName: string;
projectId: Project["_id"];
createdBy: User["_id"];
isArchive: boolean;
version: number;
}
const versionSchema: Schema = new Schema(
{
versionName: { type: String },
version: { type: Number },
isArchive: { type: Boolean, default: false },
projectId: { type: Schema.Types.ObjectId, ref: "project" },
createdBy: { type: Schema.Types.ObjectId, ref: "user" },
},
{ timestamps: true }
);
const versionModel = (db: string) => {
return MainModel(db, "Versions", versionSchema, "Versions");
};
export default versionModel;

View File

@@ -0,0 +1,37 @@
import { Schema, Document, model } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
import { Zone } from "../Builder/zoneModel.ts";
export interface Widget3d extends Document {
type: string;
widgetID: string;
widgetName: string;
position: [];
rotation: [];
isArchive: boolean;
zoneId: Zone["_id"];
Data: {
measurements: {};
duration: string;
};
}
const Widget3dSchema: Schema = new Schema(
{
type: { type: String },
widgetID: { type: String },
widgetName: { type: String, default: "Widget3D" },
position: { type: Array },
rotation: { type: Array },
zoneId: { type: Schema.Types.ObjectId, ref: "Zone" },
Data: {
measurements: { type: Object, default: {} },
duration: { type: String, default: "1h" },
},
isArchive: { type: Boolean, default: false },
},
{ timestamps: true }
);
const widget3dModel = (db: any) => {
return MainModel(db, "3dWidget", Widget3dSchema, "3dWidget");
};
export default widget3dModel;

View File

@@ -0,0 +1,46 @@
import { Schema, Document, model } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
import { Zone } from "../Builder/zoneModel.ts";
export interface FloatingWidget extends Document {
className: string;
iconName: string;
header: string;
floatWidgetID: string;
position: {};
per: string;
value: string;
isArchive: boolean;
zoneId: Zone["_id"];
Data: {
measurements: {};
duration: string;
};
}
const floatingWidgetSchema: Schema = new Schema(
{
className: { type: String },
iconName: { type: String },
header: { type: String },
floatWidgetID: { type: String },
position: { type: Object },
per: { type: String },
value: { type: String },
zoneId: { type: Schema.Types.ObjectId, ref: "Zone" },
Data: {
measurements: { type: Object, default: {} },
duration: { type: String, default: "1h" },
},
isArchive: { type: Boolean, default: false },
},
{ timestamps: true }
);
const floatWidgetModel = (db: any) => {
return MainModel(
db,
"FloatingWidget",
floatingWidgetSchema,
"FloatingWidget"
);
};
export default floatWidgetModel;

View File

@@ -0,0 +1,23 @@
import mongoose, { Schema, Document } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
import { Zone } from "../Builder/zoneModel.ts";
export interface Panel extends Document {
zoneId: Zone["_id"];
panelName: string;
widgets: [mongoose.Types.ObjectId];
isArchive: boolean;
}
const panelSchema: Schema = new Schema(
{
zoneId: { type: Schema.Types.ObjectId, ref: "Zone" },
panelName: { type: String },
widgets: [{ type: mongoose.Schema.Types.ObjectId, ref: "Widget" }],
isArchive: { type: Boolean, default: false },
},
{ timestamps: true }
);
const panelModel = (db: any) => {
return MainModel(db, "Panel", panelSchema, "Panel");
};
export default panelModel;

View File

@@ -0,0 +1,39 @@
import { Schema, Document } 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";
export interface Template extends Document {
userId: User["_id"];
projectId: Project["_id"];
versionId: Version["_id"];
templateName: string;
templateID: string;
snapshot: string;
panelOrder: [];
widgets: [];
floatWidgets: [];
Widgets3D: [];
isArchive: boolean;
}
const templateSchema: Schema = new Schema(
{
userId: { type: Schema.Types.ObjectId, ref: "User" },
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
templateName: { type: String },
templateID: { type: String },
snapshot: { type: String },
panelOrder: { type: Array },
widgets: { type: Array },
floatWidgets: { type: Array },
Widgets3D: { type: Array },
isArchive: { type: Boolean, default: false },
},
{ timestamps: true }
);
const templateModel = (db: any) => {
return MainModel(db, "Template", templateSchema, "Template");
};
export default templateModel;

View File

@@ -0,0 +1,47 @@
import mongoose, { Schema, Document } from "mongoose";
import MainModel from "../../connect/mongoose.ts";
import { Zone } from "../Builder/zoneModel.ts";
export interface widget extends Document {
widgetName: string;
widgetside: string;
widgetID: string;
widgetOrder: string;
elementType: string;
elementColor: string;
fontFamily: string;
fontStyle: string;
fontWeight: string;
isArchive: boolean;
panelID: mongoose.Types.ObjectId;
Data: {
measurements: {};
duration: string;
};
zoneId: Zone["_id"];
}
const widgetSchema: Schema = new Schema(
{
widgetName: { type: String, default: "Widget" },
widgetside: { type: String },
widgetID: { type: String },
widgetOrder: { type: String },
elementType: { type: String },
elementColor: { type: String },
fontFamily: { type: String },
fontStyle: { type: String },
Data: {
measurements: { type: Object, default: {} },
duration: { type: String, default: "1h" },
},
fontWeight: { type: String },
isArchive: { type: Boolean, default: false },
panelID: { type: mongoose.Schema.Types.ObjectId, ref: "Panel" },
zoneId: { type: Schema.Types.ObjectId, ref: "Zone" },
},
{ timestamps: true }
);
const widgetModel = (db: any) => {
return MainModel(db, "Widget", widgetSchema, "Widget");
};
export default widgetModel;