diff --git a/src/posts/posts.controller.ts b/src/posts/posts.controller.ts index a70393a1bb8e8f47b056485e9b5a6c201ee0d51a..2f919b97474661f31fd42052ef998e3fe58fde46 100644 --- a/src/posts/posts.controller.ts +++ b/src/posts/posts.controller.ts @@ -5,6 +5,7 @@ import { ApiQuery } from '@nestjs/swagger'; import { Post } from './schemas/post.schema'; import { PostsService } from './posts.service'; import { Tag } from './schemas/tag.schema'; +import { PostWithMeta } from './schemas/postWithMeta.schema'; @Controller('posts') export class PostsController { @@ -18,8 +19,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, @@ -38,6 +39,12 @@ export class PostsController { throw new HttpException('Invalid structure id', HttpStatus.BAD_REQUEST); }) ); + return new Promise((resolve) => { + result.subscribe((result: PostWithMeta) => { + result.posts.map((post: Post) => (!post.custom_excerpt ? (post.excerpt = 'Inconnu') : '')); + resolve(result); + }); + }); } @Get('tags') diff --git a/src/posts/schemas/pagination.schema.ts b/src/posts/schemas/pagination.schema.ts new file mode 100644 index 0000000000000000000000000000000000000000..4f9ecaaec31d12a488d1ea219500d1fef26da007 --- /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 1711ec1f208295ec71881e4b480f21cd264f2fee..6d5b65ab2df871c3335a296796c8476c71fe3838 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 0000000000000000000000000000000000000000..e3e78136848b79f7eab9d59bdcb48f417cf2aaac --- /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 }; +} diff --git a/src/structures/services/structures.service.ts b/src/structures/services/structures.service.ts index 045ac5a8a821215393fa5a0b22b998f84ceee027..625654f899422fcde49cac808123695581792433 100644 --- a/src/structures/services/structures.service.ts +++ b/src/structures/services/structures.service.ts @@ -31,7 +31,12 @@ export class StructuresService { } const createdStructure = new this.structureModel(structure); createdStructure._id = Types.ObjectId(); - createdStructure.save(); + await createdStructure.save(); + await this.getStructurePosition(createdStructure).then((postition: StructureDocument) => { + return this.structureModel + .findByIdAndUpdate(Types.ObjectId(createdStructure._id), { address: postition.address, coord: postition.coord }) + .exec(); + }); user.structuresLink.push(createdStructure._id); user.save();