Skip to content

Commit

Permalink
merge #351: 타임라인 반환 (timelines/:id) 시 isOwner 필드 추가
Browse files Browse the repository at this point in the history
[refactor] 타임라인 반환 (timelines/:id) 시 isOwner 필드 추가
  • Loading branch information
yaongmeow authored Dec 11, 2023
2 parents ebdf3db + 2c2cce9 commit fe6950a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
11 changes: 9 additions & 2 deletions BE/src/timelines/timelines.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,15 @@ export class TimelinesController {
description: 'id에 해당하는 타임라인을 반환합니다.',
})
@ApiOkResponse({ schema: { example: findOne_OK } })
async findOne(@Param('id', ParseUUIDPipe) id: string): Promise<Timeline> {
return this.timelinesService.findOneWithURL(id);
async findOne(@Req() request, @Param('id', ParseUUIDPipe) id: string) {
const timeline = await this.timelinesService.findOneWithURL(id);
delete timeline.posting.writer.resourceId;
delete timeline.posting.writer.socialType;
delete timeline.posting.writer.allowedIp;
delete timeline.posting.writer.bannedIp;

const userId = request['user'].id;
return { ...timeline, isOwner: timeline.posting.writer.id === userId };
}

@Put(':id')
Expand Down
10 changes: 6 additions & 4 deletions BE/src/timelines/timelines.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ export class TimelinesRepository {
}

async findOne(id: string) {
return this.timelineRepository.findOne({
where: { id },
relations: { posting: true },
});
return this.timelineRepository
.createQueryBuilder('t')
.leftJoinAndSelect('t.posting', 'p')
.leftJoinAndSelect('p.writer', 'u')
.where('t.id = :id', { id })
.getOne();
}

async findAll(posting: string, day: number) {
Expand Down

0 comments on commit fe6950a

Please sign in to comment.