浏览代码

Insert new boards at last position

boeserwolf 5 年之前
父节点
当前提交
b42d8346cd
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      models/boards.js

+ 8 - 0
models/boards.js

@@ -1295,6 +1295,14 @@ if (Meteor.isServer) {
   });
 }
 
+// Insert new board at last position in sort order.
+Boards.before.insert((userId, doc) => {
+  const lastBoard = Boards.findOne({ sort: { $exists: true } }, { sort: { sort: -1 } });
+  if (lastBoard && typeof lastBoard.sort !== 'undefined') {
+    doc.sort = lastBoard.sort + 1;
+  }
+});
+
 if (Meteor.isServer) {
   // Let MongoDB ensure that a member is not included twice in the same board
   Meteor.startup(() => {