mirror of
https://github.com/usatiuk/writer.git
synced 2025-10-29 00:17:48 +01:00
add Document model
This commit is contained in:
24
src/entity/Document.ts
Normal file
24
src/entity/Document.ts
Normal 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;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user