🔧 fix: Bookmark Order Adjustment When Moving Up (#3634)

This commit is contained in:
Yuichi Oneda 2024-08-16 00:01:35 -07:00 committed by GitHub
parent 0ba08b15de
commit e47c3f40f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -133,14 +133,21 @@ const adjustPositions = async (user, oldPosition, newPosition) => {
} }
const update = oldPosition < newPosition ? { $inc: { position: -1 } } : { $inc: { position: 1 } }; 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( await ConversationTag.updateMany(
{ {
user, user,
position: { position,
$gt: Math.min(oldPosition, newPosition),
$lte: Math.max(oldPosition, newPosition),
},
}, },
update, update,
); );