codestates / codestates/Bobpago

[๐ŸšจErr Handling] ๋ ˆ์‹œํ”ผ๋ฅผ ํ…Œ์ด๋ธ”์—์„œ ๋‹จ๋…์ ์œผ๋กœ ์‚ญ์ œํ• ๋•Œ ๋ฐœ์ƒํ•˜๋Š” ์—๋Ÿฌ

Open
#120 0 comments 0 reactions 1 assignee Claimed by @tjdgns5272 View on GitHub
complete error handling
Dominant language
TypeScript
Stars
5
Forks
3
PR merge metrics
No merged PRs in 30d

Description

> ํ•ด๊ฒฐ๋œ ์—๋Ÿฌ๋ผ๋ฉด ๋ผ๋ฒจ์— 'Complete' ๋ฅผ ๋‹ฌ์•„์ฃผ์„ธ์š”.
> ๋ฏธํ•ด๊ฒฐ๋œ ์—๋Ÿฌ๋ผ๋ฉด ๋ผ๋ฒจ์„ 'In progress' ๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”.

### ์–ด๋–ค ์—๋Ÿฌ์ธ๊ฐ€์š”?
- ๋ ˆ์‹œํ”ผ๋ฅผ recipeํ…Œ์ด๋ธ”์—์„œ๋งŒ ๋‹จ๋…์ ์œผ๋กœ ์‚ญ์ œํ• ๋•Œ ๋ฐœ์ƒํ•˜๋Š” ์—๋Ÿฌ

### ์—๋Ÿฌ ๋ฉ”์‹œ์ง€

```bash
$ error FK cannot add foreign key constraint ...
```

### ์—๋Ÿฌ ํ•ธ๋“ค๋ง ๋ฐฉ๋ฒ•

- - ๋ ˆ์‹œํ”ผ๋ฅผ ๋จผ์ € ํ…Œ์ด๋ธ”์—์„œ ์‚ญ์ œํ•˜๊ฒŒ๋˜๋ฉด ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š”๋ฐ, ์ด๋Š” ๋ ˆ์‹œํ”ผ id๋ฅผ ์™ธ๋ž˜ํ‚ค๋กœ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํ…Œ์ด๋ธ”์˜ ๋ฌด๊ฒฐ์„ฑ์— ์œ„๋ฐฐ๋˜๊ธฐ ๋•Œ๋ฌธ์ž„์„ ๊นจ๋‹ณ์Œ
- ๋”ฐ๋ผ์„œ ์™ธ๋ž˜ํ‚ค๋ฅผ ์ฐธ์กฐํ•˜๊ณ  ์žˆ๋Š”ํ…Œ์ด๋ธ”๋“ค์„ ๋จผ์ € ์ง€์›Œ์•ผ๊ฒ ๋‹ค ์ƒ๊ฐํ•˜๊ณ  ๊ฐ์ข… ํ…Œ์ด๋ธ”์„ ๋จผ์ € ์‚ญ์ œ ํ•ด์ฃผ์—ˆ๋‹ค.
- ๊ทผ๋ฐ comment ํ…Œ์ด๋ธ”์˜ id ๊ฒฝ์šฐ comment_reaction ํ…Œ์ด๋ธ”์— ์™ธ๋ž˜ํ‚ค๋กœ ์ฐธ์กฐํ•˜๊ณ  ์žˆ๊ธฐ๋•Œ๋ฌธ์— comment_reaction ํ…Œ์ด๋ธ”์„ ๋จผ์ € ์ง€์›Œ์•ผ๋œ๋‹ค๋ผ๊ณ  ์ƒ๊ฐํ•˜๊ฒŒ๋ฌ๋‹ค.
- ๊ทธ๋Ÿฌ๋‚˜ ์ด๋Ÿฐ๋ฐฉ๋ฒ•์ด ๊ต‰์žฅํžˆ ๋น„ํšจ์œจ์ ์ด๋ผ๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ๊ณ  ์ด์™€ ๊ด€๋ จํ•ด์„œ ์กฐ๊ธˆ ์ฐพ์•„๋ณด๋‹ˆ ManyToOne๊ด€๊ณ„์— `onDelete: 'CASCADE'` ์˜ต์…˜์„ ์ฃผ๋ฉด ์ž๋™์œผ๋กœ ์™ธ๋ž˜ํ‚ค๋ฅผ ์ฐธ์กฐํ•˜๊ณ ์žˆ๋Š” ํ…Œ์ด๋ธ”์ด ๊ฐ™์ด ์‚ญ์ œ๊ฐ€ ๋˜๋Š”๊ฑธ ๊นจ๋‹ณ์•˜๋‹ค!

```ts
// recipes.service.ts
// Before
// 1. AWS S3์—์„œ ์ด๋ฏธ์ง€ ๊ฐ์ฒด ์‚ญ์ œ
await this.imageService.deleteById(recipeId, 'recipe');

// 2. ๋ ˆ์‹œํ”ผ_์žฌ๋ฃŒ ํ…Œ์ด๋ธ”์—์„œ ๋ ˆ์‹œํ”ผ ์•„์ด๋”” ๊ธฐ์ค€์œผ๋กœ ์‚ญ์ œ
await this.recipeIngredientRepository.delete({ recipeId });

// 3. ๋ ˆ์‹œํ”ผ_์ด๋ฏธ์ง€ ํ…Œ์ด๋ธ”์—์„œ ๋ ˆ์‹œํ”ผ ์•„์ด๋”” ๊ธฐ์ค€์œผ๋กœ ์‚ญ์ œ
await this.recipeImageRepository.delete({ recipeId });

// 4. ๋Œ“๊ธ€_๋ฆฌ์•ก์…˜ ํ…Œ์ด๋ธ”์—์„œ ๋ ˆ์‹œํ”ผ ์•„์ด๋”” ๊ธฐ์ค€์œผ๋กœ ์‚ญ์ œ
await this.commentReactionRepository.delete({ recipeId });

// 5. ๋Œ“๊ธ€ ํ…Œ์ด๋ธ”์—์„œ ๋ ˆ์‹œํ”ผ ์•„์ด๋”” ๊ธฐ์ค€์œผ๋กœ ์‚ญ์ œ
await this.commentRepository.delete({ recipeId });

// 6. ๋ ˆ์‹œํ”ผ ํ…Œ์ด๋ธ”์—์„œ ์‚ญ์ œ
await this.recipeRepository.delete({ id: recipeId });
```
```ts
// After
// 1. AWS S3์—์„œ ์ด๋ฏธ์ง€ ๊ฐ์ฒด ์‚ญ์ œ
await this.imageService.deleteById(recipeId, 'recipe');

// 2. ๋Œ“๊ธ€ S3 ์ด๋ฏธ์ง€ ์‚ญ์ œ
await this.imageService.deleteComments(recipeId);

// 3. ๋ ˆ์‹œํ”ผ ํ…Œ์ด๋ธ”์—์„œ ์‚ญ์ œ
await this.recipeRepository.delete({ id: recipeId });
```

### ์—๋Ÿฌ ํ•ธ๋“ค๋ง์„ ์œ„ํ•ด ์ฐธ๊ณ ํ•œ ๋ ˆํผ๋Ÿฐ์Šค ๋งํฌ

[https://github.com/typeorm/typeorm/issues/1460](https://github.com/typeorm/typeorm/issues/1460)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.