From 5ef4205a97e122507fc05747f36e005a320da986 Mon Sep 17 00:00:00 2001
From: Denis Bykhov <bykhov.denis@gmail.com>
Date: Fri, 21 Apr 2023 17:55:29 +0600
Subject: [PATCH] Fix due date (#3042)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
---
 plugins/recruit-resources/src/components/KanbanCard.svelte      | 2 +-
 .../src/components/issues/DueDatePresenter.svelte               | 1 +
 server/mongo/src/storage.ts                                     | 2 +-
 3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/plugins/recruit-resources/src/components/KanbanCard.svelte b/plugins/recruit-resources/src/components/KanbanCard.svelte
index dc306ebae8..49a1d349bf 100644
--- a/plugins/recruit-resources/src/components/KanbanCard.svelte
+++ b/plugins/recruit-resources/src/components/KanbanCard.svelte
@@ -92,7 +92,7 @@
       </div>
       <DueDatePresenter
         value={object.dueDate}
-        shouldRender={object.dueDate !== null}
+        shouldRender={object.dueDate !== null && object.dueDate !== undefined}
         onChange={async (e) => {
           await client.update(object, { dueDate: e })
         }}
diff --git a/plugins/tracker-resources/src/components/issues/DueDatePresenter.svelte b/plugins/tracker-resources/src/components/issues/DueDatePresenter.svelte
index 3dde898156..01cae56b66 100644
--- a/plugins/tracker-resources/src/components/issues/DueDatePresenter.svelte
+++ b/plugins/tracker-resources/src/components/issues/DueDatePresenter.svelte
@@ -41,6 +41,7 @@
 
   $: shouldRenderPresenter =
     dueDateMs !== null &&
+    dueDateMs !== undefined &&
     value.$lookup?.status?.category !== tracker.issueStatusCategory.Completed &&
     value.$lookup?.status?.category !== tracker.issueStatusCategory.Canceled
 </script>
diff --git a/server/mongo/src/storage.ts b/server/mongo/src/storage.ts
index 967c7ce1e0..d505723bdc 100644
--- a/server/mongo/src/storage.ts
+++ b/server/mongo/src/storage.ts
@@ -1063,7 +1063,7 @@ function fillDateSort (key: string, pipeline: any[], sort: any, options: FindOpt
   }
   pipeline.push({
     $addFields: {
-      [`sort_isNull_${key}`]: { $eq: [`$${key}`, null] }
+      [`sort_isNull_${key}`]: { [key]: null }
     }
   })
   sort[`sort_isNull_${key}`] = options.sort[_key] === SortingOrder.Ascending ? 1 : -1