Skip to content

Instantly share code, notes, and snippets.

@royib
Created January 19, 2022 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save royib/2c529724a69419266774cdeb20bdece1 to your computer and use it in GitHub Desktop.
Save royib/2c529724a69419266774cdeb20bdece1 to your computer and use it in GitHub Desktop.
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import * as mongoose from 'mongoose';
import { Author, Genre } from './';
export type BookDocument = Book & Document;
@Schema()
export class Book {
@Prop({ required: true, unique: true })
title: string;
@Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'Author', required: true })
author: Author;
@Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'Genre', required: true })
genre: Genre;
@Prop()
publishDate: Date;
}
export const BookSchema = SchemaFactory.createForClass(Book);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment