Skip to content

Commit

Permalink
Added enrolledOffer filed to updateOffer and gave possibility to upda…
Browse files Browse the repository at this point in the history
…te this field for student (#658)
  • Loading branch information
Tolik170 authored Dec 4, 2023
1 parent ea060f9 commit 72c4b2e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 1 addition & 2 deletions models/offer.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ const offerSchema = new Schema(
},
enrolledUsers: {
type: [Schema.Types.ObjectId],
ref: USER,
required: false
ref: USER
},
subject: {
type: Schema.Types.ObjectId,
Expand Down
3 changes: 2 additions & 1 deletion services/offer.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ const offerService = {
}

const author = offer.author.toString()
const enrollUpdate = Boolean(Object.keys(updateData).length === 1 && updateData.enrolledUsers)

if (author !== currentUserId) {
if (author !== currentUserId && !enrollUpdate) {
throw createForbiddenError()
}

Expand Down
1 change: 1 addition & 0 deletions validation/services/offer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const allowedOfferFieldsForUpdate = {
title: true,
description: true,
languages: true,
enrolledUsers: true,
subject: true,
category: true,
status: true,
Expand Down

0 comments on commit 72c4b2e

Please sign in to comment.