11import { Controller , Get , Param } 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' ;
45
56@ApiTags ( 'Public' )
67@Controller ( '/public' )
78export class PublicController {
8- constructor ( private _agenciesService : AgenciesService ) { }
9+ constructor (
10+ private _agenciesService : AgenciesService ,
11+ private _postsService : PostsService
12+ ) { }
913 @Get ( '/agencies-list' )
1014 async getAgencyByUser ( ) {
1115 return this . _agenciesService . getAllAgencies ( ) ;
@@ -17,14 +21,32 @@ export class PublicController {
1721 }
1822
1923 @Get ( '/agencies-information/:agency' )
20- async getAgencyInformation (
21- @Param ( 'agency' ) agency : string ,
22- ) {
24+ async getAgencyInformation ( @Param ( 'agency' ) agency : string ) {
2325 return this . _agenciesService . getAgencyInformation ( agency ) ;
2426 }
2527
2628 @Get ( '/agencies-list-count' )
2729 async getAgenciesCount ( ) {
2830 return this . _agenciesService . getCount ( ) ;
2931 }
32+
33+ @Get ( `/posts/:id` )
34+ async getPreview ( @Param ( 'id' ) id : string ) {
35+ return ( await this . _postsService . getPostsRecursively ( id , true ) ) . map (
36+ ( { childrenPost, ...p } ) => ( {
37+ ...p ,
38+ ...( p . integration
39+ ? {
40+ integration : {
41+ id : p . integration . id ,
42+ name : p . integration . name ,
43+ picture : p . integration . picture ,
44+ providerIdentifier : p . integration . providerIdentifier ,
45+ profile : p . integration . profile ,
46+ } ,
47+ }
48+ : { } ) ,
49+ } )
50+ ) ;
51+ }
3052}
0 commit comments