Skip to content

Commit

Permalink
Merge pull request #94 from boostcampwm2023/fix/93-fix-tag-diary-conn…
Browse files Browse the repository at this point in the history
…ection

[Fix] 일기 생성 시 태그 관련 동작에 비동기 처리 추가
  • Loading branch information
JoonSoo-Kim authored Nov 22, 2023
2 parents 0092f47 + e952b3c commit c7746a9
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions BE/src/diaries/diaries.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ export class DiariesService {

async writeDiary(createDiaryDto: CreateDiaryDto): Promise<Diary> {
const encodedContent = btoa(createDiaryDto.content);
// 추후 태그 입력 시 반복문으로 createTag를 돌려서 하나씩 Tag 생성
const tags = [];
createDiaryDto.tags.forEach(async (tag) => {
if ((await Tag.findOne({ where: { name: tag } })) !== null) {
const tagEntity = await Tag.findOneBy({ name: tag });
tags.push(tagEntity);
} else {
tags.push(await this.tagsRepository.createTag(tag));
}
});

await Promise.all(
createDiaryDto.tags.map(async (tag) => {
if ((await Tag.findOne({ where: { name: tag } })) !== null) {
const tagEntity = await Tag.findOneBy({ name: tag });
tags.push(tagEntity);
} else {
tags.push(await this.tagsRepository.createTag(tag));
}
}),
);

const diary = await this.diariesRepository.createDiary(
createDiaryDto,
Expand Down

0 comments on commit c7746a9

Please sign in to comment.