소스 검색

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) {
   async function create(input: TaskCreate) {
     let position = input.position
     let position = input.position
     if (!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({
     const result = await collection.insertOne({