Skip to content

Commit

Permalink
🔧 fix: Bookmark Order Adjustment When Moving Up (#3634)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohneda authored and danny-avila committed Aug 17, 2024
1 parent 31d7e9f commit a2e85eb
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions api/models/ConversationTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,21 @@ const adjustPositions = async (user, oldPosition, newPosition) => {
}

const update = oldPosition < newPosition ? { $inc: { position: -1 } } : { $inc: { position: 1 } };
const position =
oldPosition < newPosition
? {
$gt: Math.min(oldPosition, newPosition),
$lte: Math.max(oldPosition, newPosition),
}
: {
$gte: Math.min(oldPosition, newPosition),
$lt: Math.max(oldPosition, newPosition),
};

await ConversationTag.updateMany(
{
user,
position: {
$gt: Math.min(oldPosition, newPosition),
$lte: Math.max(oldPosition, newPosition),
},
position,
},
update,
);
Expand Down

0 comments on commit a2e85eb

Please sign in to comment.