codestates / codestates/Bobpago
[๐จErr Handling] ๋ ์ํผ ์์ ์ ์ฌ๋ฃ๋ฅผ ์ถ๊ฐํ๊ฑฐ๋ ์ญ์ ํ์๋ db๋ด์์ ๋ณ๊ฒฝ๋์ง ์๋ ์๋ฌ
- Dominant language
- TypeScript
- Stars
- 5
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
### ์ด๋ค ์๋ฌ์ธ๊ฐ์?
>๋ ์ํผ ์์ ์ ์ฌ๋ฃ๋ฅผ ์ถ๊ฐํ๊ฑฐ๋ ์ญ์ ํ์๋ db๋ด์์ ๋ณ๊ฒฝ๋์ง ์๋ ์ค๋ฅ๊ฐ ์์๋ค.
์์ ๋ ์ฌ๋ฃ์ ์์ด๋๋ก ์ด๋ค์ง ๋ฐฐ์ด์ ์
๋ ฅ ๋ฐ๋๋ฐ, ๊ธฐ์กด ์ฌ๋ฃ id ๋ฐฐ์ด๊ณผ ๊ธธ์ด๊ฐ ์ผ์นํ๋ฉด ๋ฌธ์ ์์ด ์
๋ฐ์ดํธ๊ฐ ๋์์ผ๋
์ฌ๋ฃ๊ฐ ํด๋ผ์ด์ธํธ์์ ์ถ๊ฐ๋๊ฑฐ๋ ์ญ์ ๊ฐ ๋์ด์ ๋ฐฐ์ด๊ธธ์ด๊ฐ ๋ฌ๋ผ์ง๊ฐ์ ์๋ฒ์์ ๋ฐ๊ฒ๋๋ฉด ์๋ฌ๊ฐ ๋ฐ์ํ๋ค.
### ์๋ฌ ํธ๋ค๋ง ๋ฐฉ๋ฒ
- ์๋ฒ ๋ก์ง์ ์ฌ๋ฃ id๋ก ์ด๋ฃจ์ด์ง ๋ฐฐ์ด ๊ธธ์ด์ ๊ธฐ์ค์ ๋ฐ๋ผ ์กฐ๊ฑด๋ฌธ์ผ๋ก ๋ถ๊ธฐํ์ฌ ์ฒ๋ฆฌํ๋ค.
```js
// recipe.service.ts
async updateRecipeIngredientId(ingredientId, recipeId) {
console.log(ingredientId, recipeId);
const ingredients = await this.recipeIngredientRepository.find({
where: { recipeId },
});
// ๊ธฐ์กด์ ๊ฐ๊ณ ์๋ ์ฌ๋ฃ ๊ธธ์ด์ ์์ ๋ ์ฌ๋ฃ์ ๊ธธ์ด๊ฐ ์ผ์น ํ์ง ์๋ ๊ฒฝ์ฐ
if (ingredients.length !== ingredientId.length) {
// ํ
์ด๋ธ์ ์๋ ๊ธฐ์กด ๋ฐ์ดํฐ๋ ์ญ์ ํ๋ค
await this.recipeIngredientRepository.delete({ recipeId });
// ์๋กญ๊ฒ ์ฌ๋ฃ id๋ฅผ ๋ ์ํผ id ๊ธฐ์ค์ผ๋ก ์ถ๊ฐํด์ค๋ค
await this.createRecipeIngredientId(ingredientId, recipeId);
} else {
for (let i = 0; i < ingredients.length; i++) {
ingredients[i].ingredientId = ingredientId[i];
}
await this.recipeIngredientRepository.save(ingredients);
}
}
```
### ์๋ฌ ํธ๋ค๋ง์ ์ํด ์ฐธ๊ณ ํ ๋ ํผ๋ฐ์ค ๋งํฌ
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.