From 4d410fed693904d644b32651af0239a1f98e3e75 Mon Sep 17 00:00:00 2001 From: Ayush Gaud Date: Wed, 15 Nov 2023 04:20:43 +0900 Subject: [PATCH] always return promise --- src/wrike_ist/wrike.cljs | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/wrike_ist/wrike.cljs b/src/wrike_ist/wrike.cljs index 6558390..8e97a71 100644 --- a/src/wrike_ist/wrike.cljs +++ b/src/wrike_ist/wrike.cljs @@ -93,22 +93,25 @@ (defn check-valid-task [{:keys [permalink target-branch folder-names]}] - (.info js/console "check-valid-task: Start of the function") - (when (and target-branch (str/starts-with? target-branch "main")) - (let [folder-ids (get-folder-id folder-names)] - (if (seq folder-ids) - (do - (log-folder-ids folder-names folder-ids) - (if (is-wrike-task-in-folder? permalink (first folder-ids)) - (do - (.info js/console "check-valid-task: Task is in the folder or an inherited folder: true") - (js/Promise.resolve permalink)) - (do - (.error js/console "check-valid-task: Task not found") - (js/Promise.reject (js/Error. "Task not found"))))) - (do - (.error js/console "check-valid-task: No matching folder found") - (js/Promise.reject (js/Error. "No matching folder found"))))))) + (js/Promise. + (fn [resolve reject] + (.info js/console "check-valid-task: Start of the function") + (when (and target-branch (str/starts-with? target-branch "main")) + (let [folder-ids (get-folder-id folder-names)] + (if (seq folder-ids) + (do + (log-folder-ids folder-names folder-ids) + (if (is-wrike-task-in-folder? permalink (first folder-ids)) + (do + (.info js/console "check-valid-task: Task is in the folder or an inherited folder: true") + (resolve permalink)) + (do + (.error js/console "check-valid-task: Task not found") + (reject (js/Error. "Task not found"))))) + (do + (.error js/console "check-valid-task: No matching folder found") + (reject (js/Error. "No matching folder found"))))))))) +