@nestjs/mongoose#Schema TypeScript Examples

The following examples show how to use @nestjs/mongoose#Schema. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: lecture.schema.ts    From edu-server with MIT License 6 votes vote down vote up
@Schema({ timestamps: true })
export class Lecture {
  @Prop({ required: true })
  lectureName: string;

  @Prop({ required: true })
  description: string;

  @Prop({ required: true })
  lectureVideoUrl: string;

  @Prop({ required: true })
  time: string;
}
Example #2
Source File: dog.schema.ts    From nestjs-tenancy with MIT License 6 votes vote down vote up
@Schema()
export class Dog extends Document {
    @Prop()
    name: string;

    @Prop()
    age: number;

    @Prop()
    breed: string;
}
Example #3
Source File: cat.schema.ts    From nestjs-tenancy with MIT License 6 votes vote down vote up
@Schema()
export class Cat extends Document {
    @Prop()
    name: string;

    @Prop()
    age: number;

    @Prop()
    breed: string;
}
Example #4
Source File: mentor.schema.ts    From edu-server with MIT License 6 votes vote down vote up
@Schema({ timestamps: true })
export class Mentor {
  @Prop({ required: true })
  name: string;

  @Prop({ required: true })
  email: string;

  @Prop({ default: [] })
  courses: Course[];

  @Prop({ default: 0 })
  number_of_students: number;

  @Prop({ required: true })
  mentorPhoto: string;

  @Prop({ required: true })
  aboutMe: string;

  @Prop({ required: true })
  techStack: string[];
}
Example #5
Source File: doubtAnswer.schema.ts    From edu-server with MIT License 6 votes vote down vote up
@Schema({ timestamps: true })
export class DoubtAnswer {
  @Prop({ required: true })
  answered_by: SchemaType.Types.ObjectId;

  @Prop({ required: true })
  answer: string;

  @Prop()
  photoUrl: string;

  @Prop()
  answeredBy_name: string;
}
Example #6
Source File: doubt.schema.ts    From edu-server with MIT License 6 votes vote down vote up
@Schema({ timestamps: true })
export class Doubt {
  @Prop()
  tags: TagType[];

  @Prop({ required: true })
  asked_by: SchemaType.Types.ObjectId;

  @Prop({ type: [{ type: SchemaType.Types.ObjectId, ref: 'DoubtAnswer' }] })
  answers: DoubtAnswer[];

  @Prop({ required: true })
  question: string;

  @Prop({ default: false })
  is_resolved: boolean;

  @Prop()
  request_mentor: boolean;

  @Prop()
  photoUrl: string;

  @Prop()
  askedBy_name: string;

  @Prop()
  doubtBody: string;
}
Example #7
Source File: schedule.schema.ts    From edu-server with MIT License 6 votes vote down vote up
@Schema({ timestamps: true })
export class Schedule {
  @Prop({ required: true })
  chapterName: string;

  @Prop({ required: true })
  description: string;

  @Prop({ required: true })
  time: string;

  @Prop({ required: true })
  lectureNumber: number;

  @Prop({ type: [{ type: SchemaTypes.Types.ObjectId, ref: 'Review' }] })
  lecture: Lecture[];
}
Example #8
Source File: review.schema.ts    From edu-server with MIT License 6 votes vote down vote up
@Schema({ timestamps: true })
export class Review {
  @Prop({ required: true, type: SchemaTypes.Types.ObjectId, ref: 'User' })
  reviewerId: User;

  @Prop({ required: true })
  reviewerName: string;

  @Prop({ required: true })
  reviewDescription: string;

  @Prop({ required: true })
  occupation: ReviewType;

  @Prop({})
  stars: number;
}
Example #9
Source File: users.schema.ts    From nest-js-boilerplate with MIT License 6 votes vote down vote up
@Schema()
export class User {
  @Prop({
    required: true,
    unique: true,
    type: String,
  })
  email: string = '';

  @Prop({
    required: true,
    type: String,
  })
  password: string = '';

  @Prop({
    required: true,
    type: Boolean,
  })
  verified: boolean = false;

  @Prop({
    type: String,
    required: false,
    default: RolesEnum.user,
  })
  role: RolesEnum = RolesEnum.user;
}
Example #10
Source File: enrolledCourse.schema.ts    From edu-server with MIT License 6 votes vote down vote up
@Schema({
  toJSON: { virtuals: true, getters: true },
  toObject: { virtuals: true, getters: true },
})
export class EnrolledCourse {
  @Prop({ required: true })
  studentId: SchemaType.Types.ObjectId;

  @Prop()
  videosWatched: boolean[];

  @Prop()
  assignmentsDone: boolean[];

  @Prop()
  currentVideo: video[];

  @Prop({ required: true })
  courseId: SchemaType.Types.ObjectId;
}
Example #11
Source File: room.schema.ts    From edu-server with MIT License 6 votes vote down vote up
@Schema()
export class Room {
  @Prop()
  id: string;

  @Prop({ required: true, maxlength: 20, minlength: 5 })
  name: string;

  @Prop({ type: SchemaTypes.Types.ObjectId, ref: 'Chat' })
  chats: Chat;

  @Prop({ type: SchemaTypes.Types.ObjectId, ref: 'User' })
  connectedUsers: User;
}
Example #12
Source File: chat.schema.ts    From edu-server with MIT License 6 votes vote down vote up
@Schema()
export class Chat {
  @Prop({ required: true })
  sender: string;

  @Prop({ required: true })
  original_sender: string;

  @Prop({ required: true })
  message: string;

  @Prop({ type: SchemaType.Types.ObjectId, ref: 'User' })
  owner: User;

  @Prop({ type: SchemaType.Types.ObjectId, ref: 'Room' })
  room: Room | string;
}
Example #13
Source File: assignment.schema.ts    From edu-server with MIT License 6 votes vote down vote up
@Schema({ timestamps: true })
export class Assignment {
  @Prop({ required: true })
  assignmentLink: string;

  @Prop({ required: true })
  assignmenDescription: string;

  @Prop({ required: true })
  createdBy: string;
}
Example #14
Source File: announcement.schema.ts    From edu-server with MIT License 6 votes vote down vote up
@Schema({ timestamps: true })
export class Announcement {
  @Prop({ required: true })
  title: string;

  @Prop({ required: true })
  description: string;

  @Prop({ default: false })
  read: boolean;

  @Prop({ required: true })
  added_by: string;
}
Example #15
Source File: users.schema.ts    From nest-js-boilerplate with MIT License 6 votes vote down vote up
@Schema()
export class User {
  @Prop({
    required: true,
    type: String,
  })
  picture: string = '';

  @Prop({
    required: true,
    type: String,
  })
  firstName: string = '';

  @Prop({
    required: true,
    type: String,
  })
  lastName: string = '';

  @Prop({
    required: true,
    unique: true,
    type: String,
  })
  email: string = '';

  @Prop({
    type: Boolean,
  })
  verified: boolean = false;

  @Prop({
    type: String,
    required: false,
    default: RolesEnum.user,
  })
  role: RolesEnum = RolesEnum.user;
}
Example #16
Source File: user.schema.ts    From uniauth-backend with MIT License 5 votes vote down vote up
@Schema()
export class User {
  constructor(partial: Partial<User>) {
    Object.assign(this, partial);
  }

  /**
   * Personal Details
   */
  @Prop({ required: true })
  name: string;

  @Prop()
  image: string;

  @Prop({ required: true, select: false })
  password: string;

  @Prop({ default: false })
  verified: boolean;

  /**
   * Registration Details
   */
  @Prop({ required: true })
  registrationNumber: string;

  @Prop({ required: true })
  batch: string;

  @Prop({ required: true })
  branch: string;

  /**
   * Emails
   */
  @Prop({ required: true, unique: true })
  collegeEmail: string;

  @Prop()
  personalEmail: string;

  /**
   * Contact Numbers
   */
  @Prop()
  contactPrimary: string;

  @Prop()
  contactSecondary: string;

  /**
   * Social Links
   */
  @Prop([String])
  profile: string[];

  /** Applications created by User */
  @Prop({ type: [MongooseSchema.Types.ObjectId], ref: 'User', required: true, default: [] })
  authorizedApplications: Array<Application>;
}
Example #17
Source File: user.schema.ts    From edu-server with MIT License 5 votes vote down vote up
@Schema({ timestamps: true })
export class User {
  @Prop()
  first_name: string;

  @Prop()
  last_name: string;

  @Prop({ required: true })
  email: string;

  @Prop()
  phone: string;

  @Prop()
  photoUrl: string;

  @Prop()
  coverPhotoUrl: string;

  @Prop()
  address: string;

  @Prop()
  description: string;

  @Prop({ default: 0 })
  score: number;

  @Prop({ default: Role.STUDENT })
  role: string;

  @Prop({ default: [] })
  wishlist: SchemaTypes.Types.ObjectId[];

  @Prop({ default: [] })
  cartList: SchemaTypes.Types.ObjectId[];

  @Prop()
  fId: string;

  @Prop()
  log_in_time: string;
}
Example #18
Source File: user.schema.ts    From nestjs-seeder with MIT License 5 votes vote down vote up
@Schema()
export class User extends Document {
  // @Factory will automatically inject faker to the function that you pass.
  @Factory(faker => faker.random.arrayElement(['male', 'female']))
  @Prop({ required: true })
  gender: string;

  // You could get the previously generated value using the passed context.
  @Factory((faker, ctx) => ({
    first: faker.name.firstName(ctx.gender === 'male' ? 0 : 1),
    last: faker.name.lastName(ctx.gender === 'male' ? 0 : 1),
  }))
  @Prop(
    raw({
      first: { type: String, required: true },
      last: { type: String, required: true },
    }),
  )
  name: Record<string, string>;

  // You could also use custom function without faker.
  @Factory(() => {
    const minAge = 18;
    const maxAge = 30;
    return Math.round(Math.random() * (maxAge - minAge) + minAge);
  })
  @Prop({ required: true })
  age: number;

  // You could also use static value.
  @Factory('admin')
  @Prop({ required: true })
  role: string; 

  // If you pass predefined values to the `generate` function, you will be 
  // able to access it in the context.
  @Factory((faker, ctx) => `${faker.address.streetAddress()} ${ctx.zipCode}`)
  @Prop({ required: true })
  address: string;
}
Example #19
Source File: application.schema.ts    From uniauth-backend with MIT License 5 votes vote down vote up
/**
 * @Todo
 * - add support for participant array
 */
@Schema()
export class Application {
  constructor(partial: Partial<Application>) {
    Object.assign(this, partial);
  }

  /** Application information */
  @Prop({ required: true, unique: true })
  name: string;

  @Prop({ type: MongooseSchema.Types.ObjectId, ref: 'User', required: true })
  admin: User;

  @Prop({ required: true })
  supportEmail: string;

  @Prop()
  description: string;

  /** Application Configuration */
  @Prop({ required: true, type: [String] })
  authorizedOrigin: Array<string>;

  @Prop({ required: true, type: [String] })
  authorizedRedirect: Array<string>;

  @Prop({ required: true, type: [String] })
  scope: Array<string>;

  /** applicaiton keys */
  @Prop({ required: true })
  clientSecret: string;

  @Prop({ required: true, type: Date })
  creationDate: Date;

  /** list of participants */
  //   @Prop({ type: [MongooseSchema.Types.ObjectId], ref: 'User', required: true, default: [] })
  @Prop([{ type: MongooseSchema.Types.ObjectId, ref: 'User', required: true, default: [] }])
  participants: Array<User>;
}
Example #20
Source File: course.schema.ts    From edu-server with MIT License 4 votes vote down vote up
@Schema({ timestamps: true })
export class Course {
  @Prop({ required: true })
  name: string;

  @Prop({ required: true })
  originalPrice: number;

  @Prop({ default: Date.now })
  start_date: Date;

  @Prop()
  end_date: Date;

  @Prop({})
  duration: string;

  @Prop({ default: false })
  active: boolean;

  @Prop()
  couponCode: string;

  @Prop({ default: 0 })
  student_num: number;

  @Prop({ type: [{ type: SchemaTypes.Types.ObjectId, ref: 'Mentor' }] })
  mentor: Mentor[];

  @Prop({})
  video_num: number;

  @Prop({ default: 0 })
  no_of_enrollments: number;

  @Prop()
  sharable_link: string;

  @Prop({ type: [{ type: SchemaTypes.Types.ObjectId, ref: 'Schedule' }] })
  schedule: Schedule[];

  @Prop({ required: true })
  tags: TagType[];

  @Prop({ required: true })
  courseDetails: string;

  @Prop({ default: 'Training', required: true })
  courseLevel: courseLevelType;

  @Prop({ required: true })
  courseThumbnail: string;

  @Prop({})
  courseTrailerUrl: string;

  @Prop({ type: [{ type: SchemaTypes.Types.ObjectId, ref: 'Review' }] })
  reviews: Review[];

  @Prop({ type: [{ type: SchemaTypes.Types.ObjectId, ref: 'Doubt' }] })
  doubts: Doubt[];

  @Prop({ type: [{ type: SchemaTypes.Types.ObjectId, ref: 'Assignment' }] })
  assignments: Assignment[];

  @Prop({ required: true })
  crossPrice: number;

  @Prop()
  courseShortDescription: string;

  @Prop()
  courseLongDescription: string;

  @Prop()
  rating: number;

  @Prop()
  prerequisites: string[];

  @Prop()
  skills: string[];

  @Prop()
  whatYouWillLearn: string[];

  @Prop()
  certificateUrl: string;

  @Prop({ default: false })
  isUpcoming: boolean;
}