ISIL-ESTE / Student-Workflow-Organizer

The Workflow Organizer website helps students to organize their academic workload through features such as a dashboard, timeline, reminders, collaboration tools, resource library, progress tracking, and analytics. It also allows users to share and summarize courses and seek project help.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

implement typegoose, model definitions using decorators

bellaabdelouahab opened this issue · comments

Consider using Typegoose for a better support between TypeScript and Mongoose

@muttaqin1 remind me why this is important ?

Typegoose is used to easily define mongoose models. As we have already defined some models, do we need this now?
It would be better if we have used it earlier. what do you think about this?

Mongoose

const UserModel = mongoose.model('User', {
  name: { type: String },
  age: { type: Number, required: true },
  preferences: [{ type: String }],
  mainJob: { type: JobSchema },
  jobs: [{ type: JobSchema }],
  mainCar: { type: Schema.Types.ObjectId, ref: 'Car' },
  cars: [{ type: Schema.Types.ObjectId, ref: 'Car' }],
});

Typegoose

class User {
  @prop()
  public name?: string;

  @prop({ required: true })
  public age!: number; // This is a single Primitive

  @prop({ type: () => [String] })
  public preferences?: string[]; // This is a Primitive Array

  @prop()
  public mainJob?: Job; // This is a single SubDocument

  @prop({ type: () => [Job] })
  public jobs?: Job[]; // This is a SubDocument Array

  @prop({ ref: () => Car })
  public mainCar?: Ref<Car>; // This is a single Reference

  @prop({ ref: () => [Car] })
  public cars?: Ref<Car>[]; // This is a Reference Array
}

@bellaabdelouahab