Skip to content

Commit a8fd540

Browse files
authored
Merge pull request #60 from InserToken/feat/17-pracMain/minseon
[modify] 미완
2 parents 7296dba + 9337cc1 commit a8fd540

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

routes/userStock.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { getBalance } = require("../services/stockService");
44
const { authenticate } = require("../middleware/auth");
55
const UserStock = require("../models/UserStock");
66

7+
// 보유 주식 저장
78
// 보유 주식 저장
89
router.post("/", authenticate, async (req, res) => {
910
const cano = "50143725";
@@ -28,7 +29,21 @@ router.post("/", authenticate, async (req, res) => {
2829
output1: result.output1,
2930
});
3031
} catch (err) {
31-
console.error("계좌 연동 오류:", err.message);
32+
if (err.code === 11000) {
33+
// 이미 연동된 경우 DB에서 해당 유저의 주식 다시 조회해서 내려주기!
34+
const existingStocks = await UserStock.find({ user_id: userId });
35+
// 필요한 정보만 추리기
36+
const formatted = existingStocks.map((s) => ({
37+
pdno: s.stock_code,
38+
prdt_name: s.company || "", // company 필드가 없다면 적절히 수정!
39+
}));
40+
41+
return res.status(200).json({
42+
success: true,
43+
message: "이미 연동된 주식이 있습니다.",
44+
output1: formatted,
45+
});
46+
}
3247
res.status(500).json({ error: "계좌 연동 실패" });
3348
}
3449
});

0 commit comments

Comments
 (0)