Skip to content

Commit

Permalink
Merge pull request #636 from ita-social-projects/bugfix/635/update-le…
Browse files Browse the repository at this point in the history
…sson-service

Fixed updateLesson
  • Loading branch information
OlyaKorchan authored Nov 17, 2023
2 parents 406547c + 991a851 commit cabd68a
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions services/lesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ const lessonService = {
},

updateLesson: async (id, currentUser, updateData) => {
const { title, description, attachments, rewriteAttachments = false } = updateData

const lesson = await Lesson.findById(id).exec()

if (!lesson) {
Expand All @@ -41,12 +39,8 @@ const lessonService = {
throw createForbiddenError()
}

if (attachments) {
lesson.attachments = rewriteAttachments ? attachments : lesson.attachments.concat(attachments)
}

for (const [key, value] of Object.entries({ title, description })) {
if (value) lesson[key] = value
for (const field in updateData) {
lesson[field] = updateData[field]
}

await lesson.validate()
Expand Down

0 comments on commit cabd68a

Please sign in to comment.