Commit 77262376 authored by Yoon, Daeki's avatar Yoon, Daeki 😅
Browse files

백엔드 설문 업데이트 로직 변경

parent a32e85ac
......@@ -46,7 +46,18 @@ export const getSurveys = async (userId: string) => {
};
export const updateSurvey = async (survey: HydratedDocument<ISurvey>) => {
const newSurvey = await Survey.findOneAndUpdate({ _id: survey._id }, survey);
console.log("update survey", survey);
await Promise.all(
survey.questions.map(
async (question) =>
await Question.findOneAndUpdate({ _id: question._id }, question, {
upsert: true,
})
)
);
const newSurvey = await Survey.findOneAndUpdate({ _id: survey._id }, survey, {
new: true,
}).populate("questions");
return newSurvey;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment