Преглед изворни кода

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({