import mongoose, { Document, Schema } from "mongoose"; import MainModel from "../connection/connection"; import { IProject } from "./projectmodel"; import { User } from "./userModel"; export interface ISharedUser { userId: User["_id"]; accessLevel: "Viewer" | "Editor" | "Admin"; } export interface IShare extends Document { projectId: IProject["_id"]; sharedBy: mongoose.Types.ObjectId; sharedWith: ISharedUser[]; description?: string; isArchived: boolean; createdAt: Date; updatedAt: Date; } const shareSchema = new Schema( { projectId: { type: mongoose.Schema.Types.ObjectId, ref: "Project", }, sharedBy: { type: mongoose.Schema.Types.ObjectId, ref: "User", }, sharedWith: [ { userId: { type: mongoose.Schema.Types.ObjectId, ref: "User", }, accessLevel: { type: String, enum: ["Viewer", "Editor", "Admin"], default: "Viewer", }, }, ], description: { type: String, }, isArchived: { type: Boolean, default: false, }, }, { timestamps: true, } ); const shareModel = (db: any) => { return MainModel(db, "Share", shareSchema, "Share"); }; export default shareModel;