modify: asyncWrapper(async (req, res) => {
const user = req.user;
if (!user) {
return res.status(400).json({
isSuccess: false,
msg: '토큰값이 이상한데요?',
});
}
const { scheduleId } = req.params;
const { image, companyName, color, title, sticker, date, place, memo } =
req.body;
🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳
await user_schedule.update(
{
image,
color,
memo,
sticker,
},
{
where: { userId: user.id, scheduleId }, // user_sc => userId(9) , scheduleId(25)
include: [
{
model: Schedule,
attributes: attributesOption(),
},
],
}
);
🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳🍳
await Schedule.update(
{
title,
place,
date,
companyName,
},
{
where: { Id: scheduleId }, // Schedule => Id(25) === sceduleId(25)
}
);
return res.status(200).json({
isSuccess: true,
msg: '일정 내용 수정하기 완료!',
});
}),
},
주석처리로 설명이 되있듯이
where 이 의미하는것은 🍳 표시된부분만 확인해보자면
user_schedule.update 이라는 테이블을 수정할것이며
바뀌는 내용은 이 테이블에 있는 컬럼 항목인 image,color,memo,sticker, 이다.
근데 user_schedule.update 에 실제 id 도 여러개이고 그 id가 가진 게시물 (row) 도 여러개일텐데
저대로 바꿔버리면 저 테이블에 있는 모든 값들이 바뀌게 될것이다.
그러므로 원래 목적인 내 아이디로 작성된 특성 row 만을 지정하기 위해서
추가적으로 작성이 필요한 부분이 바로 where 에 적혀있따
where은 우선 user_schedule 라는 테이블 안에 있는 컬럼중에 하나를 골라야하는데,
사진처럼 user_schedule 테이블의 id 값은 userId 여서 user.id 라고 지정해놓은것이고
여기까지만 적으면 내 userId 9번에 적힌 모든 row가 바뀌어버리니 scheduleId 를
바꾸고자 했던 25번 만 바꾸기 위해서 추가적으로 작성해준 것이다.