浏览代码

fix incorrect position bug

Aneurin Barker Snook 1 年之前
父节点
当前提交
83932725a0
共有 1 个文件被更改,包括 5 次插入1 次删除
  1. 5 1
      src/task/model.ts

+ 5 - 1
src/task/model.ts

@@ -17,7 +17,11 @@ async function createTaskModel(ctx: Context) {
   async function create(input: TaskCreate) {
     let position = input.position
     if (!position) {
-      position = 1 + await collection.countDocuments({ _herd: input._herd })
+      const highest = await collection.findOne(
+        { _herd: input._herd },
+        { sort: { position: -1 } },
+      )
+      position = 1 + (highest?.position || 0)
     }
 
     const result = await collection.insertOne({