Add basic Site, Story and TeamService

This commit is contained in:
Jerko Steiner 2019-01-22 12:29:47 +01:00
parent b8b7052d71
commit 8865b58747
13 changed files with 124 additions and 3 deletions

View File

@ -1,4 +1,5 @@
export interface IComment { export interface IComment {
// TODO make readonly
id: number id: number
storyId: number storyId: number
message: string message: string

View File

@ -0,0 +1,6 @@
export interface ISite {
readonly id: number
readonly name: string
readonly teamId: number
readonly userId: number
}

View File

@ -0,0 +1,5 @@
export interface IStory {
readonly id: number
readonly url: string
readonly siteId: number
}

View File

@ -0,0 +1,5 @@
export interface ITeam {
readonly id: number
readonly name: string
readonly userId: number
}

View File

@ -3,4 +3,6 @@ export * from './IComment'
export * from './ICommentTree' export * from './ICommentTree'
export * from './ICredentials' export * from './ICredentials'
export * from './IRoutes' export * from './IRoutes'
export * from './ISite'
export * from './IUser' export * from './IUser'
import * from './ITeam'

View File

@ -1,5 +1,5 @@
import {BaseEntity} from './BaseEntity' import {BaseEntity} from './BaseEntity'
import {Column, Entity, ManyToOne, OneToMany} from 'typeorm' import {Column, Entity, Index, ManyToOne, OneToMany} from 'typeorm'
import {User} from './User' import {User} from './User'
import {Story} from './Story' import {Story} from './Story'
import {Team} from './Team' import {Team} from './Team'
@ -9,15 +9,17 @@ export class Site extends BaseEntity {
@Column() @Column()
name!: string name!: string
@Column() @Column({ unique: true })
domain!: string domain!: string
@Index()
@Column() @Column()
userId!: number userId!: number
@ManyToOne(type => User, user => user.sites) @ManyToOne(type => User, user => user.sites)
user?: User user?: User
@Index()
@Column() @Column()
teamId!: number teamId!: number

View File

@ -1,13 +1,22 @@
import {BaseEntity} from './BaseEntity' import {BaseEntity} from './BaseEntity'
import {Column, Entity, OneToMany} from 'typeorm' import {Column, Entity, OneToMany, ManyToOne, Index} from 'typeorm'
import {Site} from './Site' import {Site} from './Site'
import {UserTeam} from './UserTeam' import {UserTeam} from './UserTeam'
import {User} from './User'
@Entity() @Entity()
export class Team extends BaseEntity { export class Team extends BaseEntity {
@Column() @Column()
url!: string url!: string
@Column()
@Index()
userId!: number
@ManyToOne(type => User)
@Column()
user?: User
@OneToMany(type => Site, site => site.team) @OneToMany(type => Site, site => site.team)
sites!: Site[] sites!: Site[]

View File

@ -0,0 +1,11 @@
import {ISite} from '@rondo/common'
export interface ISiteService {
create(name: string, teamId: number, userId: number): Promise<ISite>
findOne(id: number, teamId: number): Promise<ISite | undefined>
find(userId: number): Promise<ISite[]>
// TODO add other methods
}

View File

@ -0,0 +1,7 @@
import {Story} from '../entities/Story'
export interface IStoryService {
findOne(url: string): Promise<Story | undefined>
// TODO add other methods
}

View File

@ -0,0 +1,11 @@
import {Team} from '../entities/Team'
export interface ITeamService {
create(name: string, userId: number): Promise<Team>
findOne(id: number, userId: number): Promise<Team | undefined>
find(userId: number): Promise<Team[]>
// TODO add other methods
}

View File

@ -0,0 +1,28 @@
import {BaseService} from './BaseService'
import {ISiteService} from './ISiteService'
import {Site} from '../entities/Site'
export class SiteService extends BaseService implements ISiteService {
async create(name: string, teamId: number, userId: number) {
return this.getRepository(Site).save({
name,
teamId,
userId,
})
}
findOne(id: number, teamId: number) {
return this.getRepository(Site).findOne({
where: {
id,
teamId,
},
})
}
async find(teamId: number) {
return this.getRepository(Site).find({
where: { teamId },
})
}
}

View File

@ -0,0 +1,10 @@
import {IStoryService} from './IStoryService'
import {Story} from '../entities/Story'
import URL from 'url'
export class StoryService implements IStoryService {
async findOne(url: string) {
const parsedUrl = URL.parse(url)
const hostname = parsedUrl.hostname
}
}

View File

@ -0,0 +1,24 @@
import {BaseService} from './BaseService'
import {ITeamService} from './ITeamService'
import {Team} from '../entities/Team'
export class TeamService extends BaseService implements ITeamService {
async create(name: string, userId: number) {
return this.getRepository(Team).save({
name,
userId,
})
}
findOne(id: number) {
return this.getRepository(Team).findOne(id)
}
find(userId: number) {
// TODO find all teams via UserTeam instead of userId
return this.getRepository(Team).find({
where: { userId },
})
}
}