Advertisement
nikolayneykov

Untitled

Oct 9th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Exclude } from 'class-transformer';
  2. import { Review } from './review.entity';
  3. import { BookStatus } from '../../common/enums';
  4. import { Entity, PrimaryGeneratedColumn, Column, OneToMany, ManyToOne, ManyToMany, JoinTable } from 'typeorm';
  5. import { Rating } from './rating.entity';
  6. import { User } from '.';
  7. import { IsNumber, IsISBN } from 'class-validator';
  8. import { Author } from './author.entity';
  9.  
  10. @Entity('books')
  11. export class Book {
  12.   @PrimaryGeneratedColumn('increment')
  13.   public id: number;
  14.  
  15.   @Column({ type: 'nvarchar', nullable: false, length: 13 })
  16.   @IsISBN()
  17.   public ISBN: string;
  18.  
  19.   @Column({ type: 'nvarchar', nullable: false, length: 100 })
  20.   public title: string;
  21.  
  22.   @ManyToOne(type => Author, author => author.books)
  23.   public author: Promise<Author>;
  24.  
  25.   @Column({type: 'nvarchar', nullable: false, length: 1000, default: ''})
  26.   public description: string;
  27.  
  28.   @Column({ type: 'enum', nullable: false, enum: BookStatus, default: BookStatus.Unlisted })
  29.   public status: BookStatus;
  30.  
  31.   @Column({ type: 'boolean', default: false })
  32.   @Exclude()
  33.   public isDeleted: boolean;
  34.  
  35.   @ManyToOne(type => User, user => user.borrowed)
  36.   public borrower: Promise<User>;
  37.  
  38.   @ManyToMany(type => User, user => user.read)
  39.   public readers: User[];
  40.  
  41.   @OneToMany(type => Review, review => review.book)
  42.   public reviews: Promise<Review[]>;
  43.  
  44.   @OneToMany(type => Rating, rating => rating.book)
  45.   public ratings: Promise<Rating[]>;
  46.  
  47.   @Column({ type: 'decimal', precision: 5, scale: 2, default: 0 })
  48.   public avgRating: number;
  49.  
  50.   @Column({ type: 'nvarchar', default: '' })
  51.   public coverURL: string;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement