From 90bc29ea5b772dcee418c0c2e2bbc10d2b53adbb Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Thu, 4 Mar 2021 19:11:49 +0100 Subject: [PATCH] fix(post) : fix author to unknow when no one specified --- src/posts/posts.controller.ts | 11 +++++++++-- src/posts/schemas/pagination.schema.ts | 8 ++++++++ src/posts/schemas/post.schema.ts | 1 + src/posts/schemas/postWithMeta.schema.ts | 7 +++++++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/posts/schemas/pagination.schema.ts create mode 100644 src/posts/schemas/postWithMeta.schema.ts diff --git a/src/posts/posts.controller.ts b/src/posts/posts.controller.ts index 69d709984..3b32fa2e1 100644 --- a/src/posts/posts.controller.ts +++ b/src/posts/posts.controller.ts @@ -3,6 +3,7 @@ import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import { ApiQuery } from '@nestjs/swagger'; import { Post } from './schemas/post.schema'; +import { PostWithMeta } from './schemas/PostWithMeta.schema'; @Controller('posts') export class PostsController { @@ -16,8 +17,8 @@ export class PostsController { @ApiQuery({ name: 'limit', type: String, required: false }) @ApiQuery({ name: 'page', type: String, required: false }) @ApiQuery({ name: 'order', type: String, required: false }) - public async findAll(@Query() query): Promise<Observable<{ posts: Post[] }>> { - return this.httpService + public async findAll(@Query() query): Promise<PostWithMeta> { + const result = await this.httpService .get(`${process.env.GHOST_HOST_AND_PORT}/ghost/api/v3/content/posts`, { params: { key: process.env.GHOST_CONTENT_API_KEY, @@ -31,5 +32,11 @@ export class PostsController { }, }) .pipe(map((response) => response.data)); + return new Promise((resolve) => { + result.subscribe((result: PostWithMeta) => { + result.posts.map((post: Post) => (!post.custom_excerpt ? (post.excerpt = 'Inconnu') : '')); + resolve(result); + }); + }); } } diff --git a/src/posts/schemas/pagination.schema.ts b/src/posts/schemas/pagination.schema.ts new file mode 100644 index 000000000..4f9ecaaec --- /dev/null +++ b/src/posts/schemas/pagination.schema.ts @@ -0,0 +1,8 @@ +export class Pagination { + limit: number; + next: any; + page: number; + pages: number; + prev: any; + total: number; +} diff --git a/src/posts/schemas/post.schema.ts b/src/posts/schemas/post.schema.ts index 1711ec1f2..6d5b65ab2 100644 --- a/src/posts/schemas/post.schema.ts +++ b/src/posts/schemas/post.schema.ts @@ -14,6 +14,7 @@ export class Post { published_at: string; url: string; excerpt: string; + custom_excerpt: string; reading_time: string; access: boolean; send_email_when_published: boolean; diff --git a/src/posts/schemas/postWithMeta.schema.ts b/src/posts/schemas/postWithMeta.schema.ts new file mode 100644 index 000000000..e3e781368 --- /dev/null +++ b/src/posts/schemas/postWithMeta.schema.ts @@ -0,0 +1,7 @@ +import { Pagination } from './pagination.schema'; +import { Post } from './post.schema'; + +export class PostWithMeta { + posts: Post[]; + meta: { pagination: Pagination }; +} -- GitLab