nikolayneykov

Untitled

Oct 9th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Book } from './book.entity';
  2. import { Rating, Review, Vote as Flag } from '.';
  3. import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, OneToMany, ManyToMany, JoinTable } from 'typeorm';
  4. import { Role } from './role.entity';
  5. import { Exclude } from 'class-transformer';
  6.  
  7. @Entity('users')
  8. export class User {
  9.   @PrimaryGeneratedColumn('increment')
  10.   public id: number;
  11.  
  12.   @Column({ type: 'nvarchar', nullable: false, unique: true, length: 20 })
  13.   public username: string;
  14.  
  15.   @Column({ type: 'nvarchar', nullable: false })
  16.   @Exclude()
  17.   public password: string;
  18.  
  19.   @Column({ type: 'integer', default: 0 })
  20.   public readingPoints: number;
  21.  
  22.   @Column({ type: 'integer', default: 0 })
  23.   public karmaPoints: number;
  24.  
  25.   @Column({ type: 'boolean', default: false })
  26.   @Exclude()
  27.   public isDeleted: boolean;
  28.  
  29.   @Column({ type: 'boolean', default: false })
  30.   public isBanned: boolean;
  31.  
  32.   @Column({ type: 'nvarchar', default: '' })
  33.   public avatarUrl: string;
  34.  
  35.   @ManyToOne(type => Role, role => role.name)
  36.   public role: Promise<Role>;
  37.  
  38.   @OneToMany(type => Book, book => book.borrower)
  39.   public borrowed: Promise<Book[]>;
  40.  
  41.   @ManyToMany(type => Book, book => book.readers)
  42.   @JoinTable()
  43.   public read: Book[];
  44.  
  45.   @OneToMany(type => Review, review => review.user)
  46.   public reviews: Promise<Review[]>;
  47.  
  48.   @OneToMany(type => Rating, rating => rating.user)
  49.   public ratings: Promise<Rating[]>;
  50.  
  51.   @OneToMany(type => Flag, vote => vote.user)
  52.   public votes: Promise<Flag[]>;
  53.  
  54.   @OneToMany(type => Flag, flag => flag.user)
  55.   public flags: Promise<Flag[]>;
  56. }
Add Comment
Please, Sign In to add comment