add Document model

This commit is contained in:
2019-01-12 18:08:38 +03:00
parent 905eb5fe46
commit bfeffe086d
2 changed files with 30 additions and 0 deletions

24
src/entity/Document.ts Normal file
View File

@@ -0,0 +1,24 @@
import {
BaseEntity,
Column,
Entity,
ManyToOne,
PrimaryGeneratedColumn,
} from "typeorm";
import { User } from "./User";
@Entity()
export class Document extends BaseEntity {
@PrimaryGeneratedColumn()
public id: number;
@ManyToOne(type => User, user => user.documents)
public user: User;
@Column()
public name: string;
@Column({ type: "text" })
public content: string;
}

View File

@@ -5,10 +5,13 @@ import {
Column,
Entity,
Index,
OneToOne,
PrimaryGeneratedColumn,
} from "typeorm";
import { config } from "~config";
import { Document } from "./Document";
export type IUserJSON = Pick<User, "id" | "username">;
export interface IUserJWT extends IUserJSON {
@@ -36,6 +39,9 @@ export class User extends BaseEntity {
@Column()
public passwordHash: string;
@OneToOne(type => Document, document => document.user)
public documents: Document[];
constructor(username: string, email: string) {
super();
this.username = username;