Snai3i-LandingPage-FormBuilder / backend / src / models / formModel.ts
formModel.ts
Raw
import { type ObjectId, Schema, model, Model, Document } from 'mongoose';

export interface FormElementsType {
  id: string;
  label: string;
  type: string;
  required: boolean;
  options?: { label: string; value: string }[];
}
 
interface FormI extends Document {
  name: string;
  elements: FormElementsType[];
  isActive: boolean;
  user: ObjectId;
}

export interface FormModelI extends Model<FormI> {}

const formSchema = new Schema<FormI>(
  {
    name: {
      type: String,
      required: true,
    },
    elements: Array,
    isActive: {
      type: Boolean,
      default: true,
    },
    user: {
      type: Schema.ObjectId,
      ref: 'User',
      required: true,
    },
  },
  {
    timestamps: true,
  }
);

const formModel = model<FormI, FormModelI>('Form', formSchema);
export default formModel;