creation thread and comments in socket

This commit is contained in:
2025-05-27 18:00:35 +05:30
parent 2c28ffe9aa
commit 694d50b278
10 changed files with 583 additions and 59 deletions

View File

@@ -0,0 +1,59 @@
import { Document, Schema } from "mongoose";
import { User } from "../Auth/userAuthModel.ts";
import { Project } from "../Project/project-model.ts";
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 {
projectId: Project["_id"];
versionId: Version["_id"];
state: string;
commentId: string;
createdBy: User["_id"];
createdAt: number;
lastUpdatedAt: string;
position: [number, number, number];
rotation: [number, number, number];
replies: IComment[];
}
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 },
state: { type: String, enum: ['active', 'inactive'], required: true },
commentId: { type: String, },
createdBy: { type: Schema.Types.ObjectId, ref: 'User', required: true },
createdAt: { type: Number,},
lastUpdatedAt: { type: String, },
position: {
type: [Number],
required: true,
},
rotation: {
type: [Number],
required: true,
},
replies: { type: [CommentSchema ], default: [] },
});
const ThreadModel = (db: string) => {
return MainModel(db, "Threads", threadSchema, "Threads");
};
export default ThreadModel;