11import { Body , Controller , Get , Param , Post , Req , Res } from '@nestjs/common' ;
22import { ApiTags } from '@nestjs/swagger' ;
33import { AgenciesService } from '@gitroom/nestjs-libraries/database/prisma/agencies/agencies.service' ;
4+ import { PostsService } from '@gitroom/nestjs-libraries/database/prisma/posts/posts.service' ;
45import { TrackService } from '@gitroom/nestjs-libraries/track/track.service' ;
56import { RealIP } from 'nestjs-real-ip' ;
67import { UserAgent } from '@gitroom/nestjs-libraries/user/user.agent' ;
78import { TrackEnum } from '@gitroom/nestjs-libraries/user/track.enum' ;
89import { Request , Response } from 'express' ;
9- import { GetUserFromRequest } from '@gitroom/nestjs-libraries/user/user.from.request' ;
10- import { User } from '@prisma/client' ;
1110import { makeId } from '@gitroom/nestjs-libraries/services/make.is' ;
1211import { getCookieUrlFromDomain } from '@gitroom/helpers/subdomain/subdomain.management' ;
13- import { AgentGraphService } from '@gitroom/nestjs-libraries/agent/agent.graph.service' ;
1412import { AgentGraphInsertService } from '@gitroom/nestjs-libraries/agent/agent.graph.insert.service' ;
1513
1614@ApiTags ( 'Public' )
@@ -19,7 +17,8 @@ export class PublicController {
1917 constructor (
2018 private _agenciesService : AgenciesService ,
2119 private _trackService : TrackService ,
22- private _agentGraphInsertService : AgentGraphInsertService
20+ private _agentGraphInsertService : AgentGraphInsertService ,
21+ private _postsService : PostsService
2322 ) { }
2423 @Post ( '/agent' )
2524 async createAgent ( @Body ( ) body : { text : string ; apiKey : string } ) {
@@ -53,6 +52,31 @@ export class PublicController {
5352 return this . _agenciesService . getCount ( ) ;
5453 }
5554
55+ @Get ( `/posts/:id` )
56+ async getPreview ( @Param ( 'id' ) id : string ) {
57+ return ( await this . _postsService . getPostsRecursively ( id , true ) ) . map (
58+ ( { childrenPost, ...p } ) => ( {
59+ ...p ,
60+ ...( p . integration
61+ ? {
62+ integration : {
63+ id : p . integration . id ,
64+ name : p . integration . name ,
65+ picture : p . integration . picture ,
66+ providerIdentifier : p . integration . providerIdentifier ,
67+ profile : p . integration . profile ,
68+ } ,
69+ }
70+ : { } ) ,
71+ } )
72+ ) ;
73+ }
74+
75+ @Get ( `/posts/:id/comments` )
76+ async getComments ( @Param ( 'id' ) postId : string ) {
77+ return { comments : await this . _postsService . getComments ( postId ) } ;
78+ }
79+
5680 @Post ( '/t' )
5781 async trackEvent (
5882 @Res ( ) res : Response ,
0 commit comments