Skip to content

Commit

Permalink
Update:batchUpdate endpoint validate req.body is an array of objects
Browse files Browse the repository at this point in the history
  • Loading branch information
advplyr committed Dec 1, 2024
1 parent 2b54842 commit 0dedb09
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions server/controllers/LibraryItemController.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,13 @@ class LibraryItemController {
*/
async batchUpdate(req, res) {
const updatePayloads = req.body
if (!updatePayloads?.length) {
return res.sendStatus(500)
if (!Array.isArray(updatePayloads) || !updatePayloads.length) {
Logger.error(`[LibraryItemController] Batch update failed. Invalid payload`)
return res.sendStatus(400)
}

// Ensure that each update payload has a unique library item id
const libraryItemIds = [...new Set(updatePayloads.map((up) => up.id))]
const libraryItemIds = [...new Set(updatePayloads.map((up) => up?.id).filter((id) => id))]
if (!libraryItemIds.length || libraryItemIds.length !== updatePayloads.length) {
Logger.error(`[LibraryItemController] Batch update failed. Each update payload must have a unique library item id`)
return res.sendStatus(400)
Expand Down

0 comments on commit 0dedb09

Please sign in to comment.