Add lots of default entities
This commit is contained in:
parent
10e5775bf4
commit
0a87e9a498
16
packages/server/src/entities/BaseEntity.ts
Normal file
16
packages/server/src/entities/BaseEntity.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import {
|
||||
PrimaryGeneratedColumn,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm'
|
||||
|
||||
export abstract class BaseEntity {
|
||||
@PrimaryGeneratedColumn()
|
||||
id!: number
|
||||
|
||||
@CreateDateColumn()
|
||||
createDate!: Date
|
||||
|
||||
@UpdateDateColumn()
|
||||
updateDate!: Date
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
import {Column, Entity, ManyToOne} from 'typeorm'
|
||||
import {User} from './User'
|
||||
import {Story} from './Story'
|
||||
import {BaseEntity} from './BaseEntity'
|
||||
|
||||
@Entity()
|
||||
export class Comment extends BaseEntity {
|
||||
@Column({type: 'text'})
|
||||
message!: string
|
||||
|
||||
@ManyToOne(type => Story, story => story.comments)
|
||||
story?: Story
|
||||
|
||||
@Column()
|
||||
storyId!: number
|
||||
|
||||
@ManyToOne(type => User, user => user.comments)
|
||||
user?: User
|
||||
|
||||
@Column()
|
||||
userId!: number
|
||||
|
||||
@Column()
|
||||
parentId!: number
|
||||
|
||||
@Column()
|
||||
spams!: number
|
||||
|
||||
@Column()
|
||||
votes!: number
|
||||
}
|
||||
8
packages/server/src/entities/Role.ts
Normal file
8
packages/server/src/entities/Role.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import {BaseEntity} from './BaseEntity'
|
||||
import {Column, Entity} from 'typeorm'
|
||||
|
||||
@Entity()
|
||||
export class Role extends BaseEntity {
|
||||
@Column()
|
||||
name!: string
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
import {BaseEntity} from './BaseEntity'
|
||||
import {Column, Entity, ManyToOne, OneToMany} from 'typeorm'
|
||||
import {User} from './User'
|
||||
import {Story} from './Story'
|
||||
import {Team} from './Team'
|
||||
|
||||
@Entity()
|
||||
export class Site extends BaseEntity {
|
||||
@Column()
|
||||
name!: string
|
||||
|
||||
@Column()
|
||||
domain!: string
|
||||
|
||||
@Column()
|
||||
userId!: number
|
||||
|
||||
@ManyToOne(type => User, user => user.sites)
|
||||
user?: User
|
||||
|
||||
@Column()
|
||||
teamId!: number
|
||||
|
||||
@ManyToOne(type => Team, team => team.sites)
|
||||
team?: Team
|
||||
|
||||
@OneToMany(type => Story, story => story.site)
|
||||
stories!: Story[]
|
||||
}
|
||||
19
packages/server/src/entities/Spam.ts
Normal file
19
packages/server/src/entities/Spam.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import {BaseEntity} from './BaseEntity'
|
||||
import {Column, Entity, ManyToOne} from 'typeorm'
|
||||
import {User} from './User'
|
||||
import {Comment} from './Comment'
|
||||
|
||||
@Entity()
|
||||
export class Spam extends BaseEntity {
|
||||
@ManyToOne(type => User)
|
||||
user?: User
|
||||
|
||||
@Column()
|
||||
userId!: number
|
||||
|
||||
@ManyToOne(type => Comment)
|
||||
comment?: Comment
|
||||
|
||||
@Column()
|
||||
commentId!: number
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
import {BaseEntity} from './BaseEntity'
|
||||
import {Column, Entity, ManyToOne} from 'typeorm'
|
||||
import {Comment} from './Comment'
|
||||
import {Site} from './Site'
|
||||
|
||||
@Entity()
|
||||
export class Story extends BaseEntity {
|
||||
@Column()
|
||||
url!: string
|
||||
|
||||
@Column()
|
||||
siteId!: number
|
||||
|
||||
@ManyToOne(type => Site, site => site.stories)
|
||||
site?: Site
|
||||
|
||||
@ManyToOne(type => Comment, comment => comment.story)
|
||||
comments!: Comment[]
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
import {BaseEntity} from './BaseEntity'
|
||||
import {Column, Entity, OneToMany} from 'typeorm'
|
||||
import {Site} from './Site'
|
||||
import {UserTeam} from './UserTeam'
|
||||
|
||||
@Entity()
|
||||
export class Team extends BaseEntity {
|
||||
@Column()
|
||||
url!: string
|
||||
|
||||
@OneToMany(type => Site, site => site.team)
|
||||
sites!: Site[]
|
||||
|
||||
@OneToMany(type => UserTeam, userTeam => userTeam.team)
|
||||
userTeams!: UserTeam[]
|
||||
}
|
||||
@ -1,12 +1,13 @@
|
||||
import {Column, Entity, PrimaryGeneratedColumn, OneToMany} from 'typeorm'
|
||||
import {UserEmail} from './UserEmail'
|
||||
import {BaseEntity} from './BaseEntity'
|
||||
import {Column, Entity, OneToMany} from 'typeorm'
|
||||
import {Comment} from './Comment'
|
||||
import {Session} from './Session'
|
||||
import {Site} from './Site'
|
||||
import {UserTeam} from './UserTeam'
|
||||
import {UserEmail} from './UserEmail'
|
||||
|
||||
@Entity()
|
||||
export class User {
|
||||
@PrimaryGeneratedColumn()
|
||||
id!: number
|
||||
|
||||
export class User extends BaseEntity {
|
||||
@OneToMany(type => UserEmail, email => email.user)
|
||||
emails!: UserEmail[]
|
||||
|
||||
@ -16,4 +17,13 @@ export class User {
|
||||
|
||||
@OneToMany(type => Session, session => session.user)
|
||||
sessions!: Session[]
|
||||
|
||||
@OneToMany(type => Site, site => site.user)
|
||||
sites!: Site[]
|
||||
|
||||
@OneToMany(type => Comment, comment => comment.user)
|
||||
comments!: Comment[]
|
||||
|
||||
@OneToMany(type => UserTeam, userTeam => userTeam.user)
|
||||
userTeams!: UserTeam[]
|
||||
}
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
import {BaseEntity} from './BaseEntity'
|
||||
import {Column, Entity, PrimaryGeneratedColumn, ManyToOne} from 'typeorm'
|
||||
import {User} from './User'
|
||||
|
||||
@Entity()
|
||||
export class UserEmail {
|
||||
export class UserEmail extends BaseEntity {
|
||||
@PrimaryGeneratedColumn()
|
||||
id!: number
|
||||
|
||||
|
||||
26
packages/server/src/entities/UserTeam.ts
Normal file
26
packages/server/src/entities/UserTeam.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import {BaseEntity} from './BaseEntity'
|
||||
import {Column, Entity, ManyToOne} from 'typeorm'
|
||||
import {Role} from './Role'
|
||||
import {Team} from './Team'
|
||||
import {User} from './User'
|
||||
|
||||
@Entity()
|
||||
export class UserTeam extends BaseEntity {
|
||||
@ManyToOne(type => User, user => user.userTeams)
|
||||
user!: User
|
||||
|
||||
@Column()
|
||||
userId!: number
|
||||
|
||||
@ManyToOne(type => Team, team => team.userTeams)
|
||||
team?: Team
|
||||
|
||||
@Column()
|
||||
teamId!: number
|
||||
|
||||
@ManyToOne(type => Role)
|
||||
role?: Role
|
||||
|
||||
@Column()
|
||||
roleId!: number
|
||||
}
|
||||
19
packages/server/src/entities/Vote.ts
Normal file
19
packages/server/src/entities/Vote.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import {BaseEntity} from './BaseEntity'
|
||||
import {Column, Entity, ManyToOne} from 'typeorm'
|
||||
import {Comment} from './Comment'
|
||||
import {User} from './User'
|
||||
|
||||
@Entity()
|
||||
export class Vote extends BaseEntity {
|
||||
@ManyToOne(type => User)
|
||||
user?: User
|
||||
|
||||
@Column()
|
||||
userId!: number
|
||||
|
||||
@ManyToOne(type => Comment)
|
||||
comment?: Comment
|
||||
|
||||
@Column()
|
||||
commentId!: number
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user