From c0ce862b52e2a4f0277980ab788de38fcd5f14a5 Mon Sep 17 00:00:00 2001 From: RXRD Date: Wed, 15 Nov 2023 12:41:30 +0700 Subject: [PATCH] Update post.service.ts --- src/services/post.service.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/services/post.service.ts b/src/services/post.service.ts index 54331c591..802611046 100644 --- a/src/services/post.service.ts +++ b/src/services/post.service.ts @@ -24,6 +24,7 @@ import { DraftPost, Experience, ExperiencePost, + ExperienceRelations, ExtendedPost, Friend, People, @@ -37,6 +38,7 @@ import { CommentRepository, DraftPostRepository, ExperiencePostRepository, + ExperienceEditorRepository, ExperienceRepository, FriendRepository, PeopleRepository, @@ -68,6 +70,8 @@ export class PostService { private experienceRepository: ExperienceRepository, @repository(ExperiencePostRepository) private experiencePostRepository: ExperiencePostRepository, + @repository(ExperienceEditorRepository) + private experienceEditorRepository: ExperienceEditorRepository, @repository(FriendRepository) private friendRepository: FriendRepository, @repository(PeopleRepository) @@ -743,12 +747,28 @@ export class PostService { } private async getVisibility(userId: string, timelineIds = [] as string[]) { - const timelines = await this.experienceRepository.find({ + const timeline = this.experienceRepository.find({ where: { id: {inq: timelineIds}, createdBy: userId, }, }); + const editable = this.experienceEditorRepository.find({ + where: { + experienceId: {inq: timelineIds}, + userId, + }, + }).then(res => { + const query = res.map(res => res.userId) + return this.experienceRepository.find({ + where: { + id: {inq: query}, + }, + }); + }); + const timelines = await Promise.all([timeline,editable]).then(res => { + return [...res[0],...res[1]] + }) if (timelines.length <= 0) { throw new HttpErrors.UnprocessableEntity('TimelineNotFound');