Add basic Site, Story and TeamService
This commit is contained in:
parent
b8b7052d71
commit
8865b58747
@ -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
|
||||||
|
|||||||
6
packages/common/src/ISite.ts
Normal file
6
packages/common/src/ISite.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export interface ISite {
|
||||||
|
readonly id: number
|
||||||
|
readonly name: string
|
||||||
|
readonly teamId: number
|
||||||
|
readonly userId: number
|
||||||
|
}
|
||||||
5
packages/common/src/IStory.ts
Normal file
5
packages/common/src/IStory.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export interface IStory {
|
||||||
|
readonly id: number
|
||||||
|
readonly url: string
|
||||||
|
readonly siteId: number
|
||||||
|
}
|
||||||
5
packages/common/src/ITeam.ts
Normal file
5
packages/common/src/ITeam.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export interface ITeam {
|
||||||
|
readonly id: number
|
||||||
|
readonly name: string
|
||||||
|
readonly userId: number
|
||||||
|
}
|
||||||
@ -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'
|
||||||
|
|||||||
@ -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
|
||||||
|
|
||||||
|
|||||||
@ -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[]
|
||||||
|
|
||||||
|
|||||||
11
packages/server/src/services/ISiteService.ts
Normal file
11
packages/server/src/services/ISiteService.ts
Normal 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
|
||||||
|
}
|
||||||
7
packages/server/src/services/IStoryService.ts
Normal file
7
packages/server/src/services/IStoryService.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import {Story} from '../entities/Story'
|
||||||
|
|
||||||
|
export interface IStoryService {
|
||||||
|
findOne(url: string): Promise<Story | undefined>
|
||||||
|
|
||||||
|
// TODO add other methods
|
||||||
|
}
|
||||||
11
packages/server/src/services/ITeamService.ts
Normal file
11
packages/server/src/services/ITeamService.ts
Normal 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
|
||||||
|
}
|
||||||
28
packages/server/src/services/SiteService.ts
Normal file
28
packages/server/src/services/SiteService.ts
Normal 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 },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
10
packages/server/src/services/StoryService.ts
Normal file
10
packages/server/src/services/StoryService.ts
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
24
packages/server/src/services/TeamService.ts
Normal file
24
packages/server/src/services/TeamService.ts
Normal 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 },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user