Add SiteRoutes, StoryRoutes and TeamRoutes
This commit is contained in:
parent
d0e94808bb
commit
f0943cfe80
@ -1,6 +1,9 @@
|
|||||||
import {ICommentTree} from './ICommentTree'
|
import {ICommentTree} from './ICommentTree'
|
||||||
import {IComment} from './IComment'
|
import {IComment} from './IComment'
|
||||||
import {ICredentials} from './ICredentials'
|
import {ICredentials} from './ICredentials'
|
||||||
|
import {ISite} from './ISite'
|
||||||
|
import {IStory} from './IStory'
|
||||||
|
import {ITeam} from './ITeam'
|
||||||
import {IUser} from './IUser'
|
import {IUser} from './IUser'
|
||||||
|
|
||||||
export interface IAPIDef {
|
export interface IAPIDef {
|
||||||
@ -33,7 +36,86 @@ export interface IAPIDef {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'/story/:storyId/comments': {
|
|
||||||
|
// TEAM
|
||||||
|
|
||||||
|
'/teams': {
|
||||||
|
post: {
|
||||||
|
body: {
|
||||||
|
name: string
|
||||||
|
}
|
||||||
|
response: ITeam
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
'/teams/:id': {
|
||||||
|
get: {
|
||||||
|
params: {
|
||||||
|
id: number
|
||||||
|
}
|
||||||
|
response: ITeam | undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
'/my/teams': {
|
||||||
|
get: {
|
||||||
|
response: ITeam[]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SITE
|
||||||
|
|
||||||
|
'/sites/:domain': {
|
||||||
|
'get': {
|
||||||
|
params: {domain: string}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
'/teams/:teamId/sites/:id': {
|
||||||
|
get: {
|
||||||
|
params: {
|
||||||
|
teamId: number
|
||||||
|
id: number
|
||||||
|
}
|
||||||
|
response: ISite | undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
'/teams/:teamId/sites': {
|
||||||
|
get: {
|
||||||
|
params: {
|
||||||
|
teamId: number
|
||||||
|
}
|
||||||
|
response: ISite[]
|
||||||
|
}
|
||||||
|
post: {
|
||||||
|
params: {
|
||||||
|
teamId: number
|
||||||
|
}
|
||||||
|
body: {
|
||||||
|
name: string
|
||||||
|
}
|
||||||
|
response: ISite
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
'/my/sites': {
|
||||||
|
get: {
|
||||||
|
response: ISite[]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// STORY
|
||||||
|
|
||||||
|
'/stories/by-url': {
|
||||||
|
'get': {
|
||||||
|
response: IStory | undefined
|
||||||
|
query: {
|
||||||
|
url: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'/stories/:storyId/comments': {
|
||||||
'get': {
|
'get': {
|
||||||
response: ICommentTree,
|
response: ICommentTree,
|
||||||
params: {
|
params: {
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import {User} from './User'
|
|||||||
@Entity()
|
@Entity()
|
||||||
export class Team extends BaseEntity {
|
export class Team extends BaseEntity {
|
||||||
@Column()
|
@Column()
|
||||||
url!: string
|
name!: string
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
@Index()
|
@Index()
|
||||||
|
|||||||
@ -14,14 +14,14 @@ export class CommentRoutes extends BaseRoute<IAPIDef> {
|
|||||||
|
|
||||||
setup(t: AsyncRouter<IAPIDef>) {
|
setup(t: AsyncRouter<IAPIDef>) {
|
||||||
|
|
||||||
t.get('/story/:storyId/comments', async req => {
|
t.get('/stories/:storyId/comments', async req => {
|
||||||
const {storyId} = req.params
|
const {storyId} = req.params
|
||||||
return this.commentService.find(storyId)
|
return this.commentService.find(storyId)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.use(ensureLoggedInApi)
|
t.use(ensureLoggedInApi)
|
||||||
|
|
||||||
t.post('/story/:storyId/comments', async req => {
|
t.post('/stories/:storyId/comments', async req => {
|
||||||
const {storyId} = req.params
|
const {storyId} = req.params
|
||||||
const comment = req.body
|
const comment = req.body
|
||||||
comment.storyId = storyId
|
comment.storyId = storyId
|
||||||
|
|||||||
45
packages/server/src/routes/SiteRoutes.ts
Normal file
45
packages/server/src/routes/SiteRoutes.ts
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import {AsyncRouter} from '../router'
|
||||||
|
import {BaseRoute} from './BaseRoute'
|
||||||
|
import {IAPIDef} from '@rondo/common'
|
||||||
|
import {ISiteService} from '../services/ISiteService'
|
||||||
|
import {ensureLoggedInApi} from '../middleware'
|
||||||
|
|
||||||
|
export class SiteRoutes extends BaseRoute<IAPIDef> {
|
||||||
|
constructor(
|
||||||
|
protected readonly siteService: ISiteService,
|
||||||
|
protected readonly t: AsyncRouter<IAPIDef>,
|
||||||
|
) {
|
||||||
|
super(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
setup(t: AsyncRouter<IAPIDef>) {
|
||||||
|
|
||||||
|
t.get('/sites/:domain', async req => {
|
||||||
|
const {domain} = req.params
|
||||||
|
return this.siteService.findByDomain(domain)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.get('/teams/:teamId/sites/:id', async req => {
|
||||||
|
const {id, teamId} = req.params
|
||||||
|
return this.siteService.findOne(id, teamId)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.get('/teams/:teamId/sites', async req => {
|
||||||
|
return this.siteService.findByTeam(req.params.teamId)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.use(ensureLoggedInApi)
|
||||||
|
|
||||||
|
t.get('/my/sites', async req => {
|
||||||
|
return this.siteService.findByUser(req.user!.id)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.post('/teams/:teamId/sites', async req => {
|
||||||
|
const {name} = req.body
|
||||||
|
const {teamId} = req.params
|
||||||
|
return this.siteService.create(name, teamId, req.user!.id)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
23
packages/server/src/routes/StoryRoutes.ts
Normal file
23
packages/server/src/routes/StoryRoutes.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import {AsyncRouter} from '../router'
|
||||||
|
import {BaseRoute} from './BaseRoute'
|
||||||
|
import {IAPIDef} from '@rondo/common'
|
||||||
|
import {IStoryService} from '../services/IStoryService'
|
||||||
|
|
||||||
|
export class StoryRoutes extends BaseRoute<IAPIDef> {
|
||||||
|
constructor(
|
||||||
|
protected readonly storyService: IStoryService,
|
||||||
|
protected readonly t: AsyncRouter<IAPIDef>,
|
||||||
|
) {
|
||||||
|
super(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
setup(t: AsyncRouter<IAPIDef>) {
|
||||||
|
|
||||||
|
t.get('/stories/by-url', async req => {
|
||||||
|
const {url} = req.query
|
||||||
|
return this.storyService.findOne(url)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
35
packages/server/src/routes/TeamRoutes.ts
Normal file
35
packages/server/src/routes/TeamRoutes.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import {AsyncRouter} from '../router'
|
||||||
|
import {BaseRoute} from './BaseRoute'
|
||||||
|
import {IAPIDef} from '@rondo/common'
|
||||||
|
import {ITeamService} from '../services/ITeamService'
|
||||||
|
import {ensureLoggedInApi} from '../middleware'
|
||||||
|
|
||||||
|
export class TeamRoutes extends BaseRoute<IAPIDef> {
|
||||||
|
constructor(
|
||||||
|
protected readonly teamService: ITeamService,
|
||||||
|
protected readonly t: AsyncRouter<IAPIDef>,
|
||||||
|
) {
|
||||||
|
super(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
setup(t: AsyncRouter<IAPIDef>) {
|
||||||
|
|
||||||
|
t.get('/teams/:id', async req => {
|
||||||
|
const {id} = req.params
|
||||||
|
return this.teamService.findOne(id, req.user!.id)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.use(ensureLoggedInApi)
|
||||||
|
|
||||||
|
t.get('/my/teams', async req => {
|
||||||
|
return this.teamService.find(req.user!.id)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.post('/teams', async req => {
|
||||||
|
const {name} = req.body
|
||||||
|
return this.teamService.create(name, req.user!.id)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -5,7 +5,9 @@ export interface ISiteService {
|
|||||||
|
|
||||||
findOne(id: number, teamId: number): Promise<ISite | undefined>
|
findOne(id: number, teamId: number): Promise<ISite | undefined>
|
||||||
|
|
||||||
find(userId: number): Promise<ISite[]>
|
findByUser(userId: number): Promise<ISite[]>
|
||||||
|
|
||||||
|
findByTeam(teamId: number): Promise<ISite[]>
|
||||||
|
|
||||||
findByDomain(domain: string): Promise<ISite | undefined>
|
findByDomain(domain: string): Promise<ISite | undefined>
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,13 @@ export class SiteService extends BaseService implements ISiteService {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async find(teamId: number) {
|
async findByUser(userId: number) {
|
||||||
|
return this.getRepository(Site).find({
|
||||||
|
where: { userId },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async findByTeam(teamId: number) {
|
||||||
return this.getRepository(Site).find({
|
return this.getRepository(Site).find({
|
||||||
where: { teamId },
|
where: { teamId },
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user