@burgan-tech/morph-touch-runtime 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/burgan-tech-morph-touch-runtime-0.0.2.tgz +0 -0
- package/package.json +21 -0
- package/touch/Extensions/.gitkeep +0 -0
- package/touch/Functions/.gitkeep +0 -0
- package/touch/Functions/check-livekit-room-access.1.0.0.json +28 -0
- package/touch/Functions/check-livekit-room-access.http +44 -0
- package/touch/Functions/get-absence-entry.1.0.0.json +28 -0
- package/touch/Functions/get-advisor-stats.1.0.0.json +27 -0
- package/touch/Functions/get-available-slots.1.0.0.json +30 -0
- package/touch/Functions/get-available-slots.http +29 -0
- package/touch/Functions/get-chat-rooms.1.0.0.json +28 -0
- package/touch/Functions/get-chat-rooms.http +62 -0
- package/touch/Functions/get-customer-info.1.0.0.json +27 -0
- package/touch/Functions/get-matrix-sync.1.0.0.json +28 -0
- package/touch/Functions/get-rezervations.1.0.0.json +26 -0
- package/touch/Functions/get-rezervations.http +59 -0
- package/touch/Functions/get-room-messages.1.0.0.json +29 -0
- package/touch/Functions/get-room-messages.http +45 -0
- package/touch/Functions/rezervation-transfer.http +118 -0
- package/touch/Functions/send-room-message.1.0.0.json +29 -0
- package/touch/Functions/src/CheckLivekitRoomAccessMapping.csx +238 -0
- package/touch/Functions/src/GetAbsenceEntryMapping.csx +225 -0
- package/touch/Functions/src/GetAdvisorStatsMapping.csx +190 -0
- package/touch/Functions/src/GetAvailableSlotsMapping.csx +468 -0
- package/touch/Functions/src/GetChatRoomsMapping.csx +202 -0
- package/touch/Functions/src/GetCustomerInfoMapping.csx +140 -0
- package/touch/Functions/src/GetMatrixSyncMapping.csx +197 -0
- package/touch/Functions/src/GetRezervationsMapping.csx +162 -0
- package/touch/Functions/src/GetRoomMessagesMapping.csx +165 -0
- package/touch/Functions/src/SendCancelNotificationMapping.csx +63 -0
- package/touch/Functions/src/SendRoomMessageMapping.csx +131 -0
- package/touch/Schemas/.gitkeep +0 -0
- package/touch/Schemas/absence-entry.1.0.0.json +232 -0
- package/touch/Schemas/advisor-chat-rooms.1.0.0.json +62 -0
- package/touch/Schemas/chat-room.1.0.0.json +110 -0
- package/touch/Schemas/notification-sender.1.0.0.json +159 -0
- package/touch/Schemas/portfolio-manager.1.0.0.json +63 -0
- package/touch/Schemas/rezervation.1.0.0.json +102 -0
- package/touch/Tasks/.gitkeep +0 -0
- package/touch/Tasks/cancel-absence-entry-for-rezervation.1.0.0.json +21 -0
- package/touch/Tasks/check-already-completed-chat-room.1.0.0.json +24 -0
- package/touch/Tasks/check-duplicate-portfolio-manager.1.0.0.json +23 -0
- package/touch/Tasks/check-duplicate-rezervation.1.0.0.json +23 -0
- package/touch/Tasks/check-existing-permanent-chat-room.1.0.0.json +21 -0
- package/touch/Tasks/check-randevu-time.1.0.0.json +17 -0
- package/touch/Tasks/create-permanent-chat-room.1.0.0.json +28 -0
- package/touch/Tasks/determine-transfer-type.1.0.0.json +16 -0
- package/touch/Tasks/enrich-rezervations-for-transfer.1.0.0.json +23 -0
- package/touch/Tasks/execute-permanent-chatroom-update.1.0.0.json +21 -0
- package/touch/Tasks/execute-rez-chatroom-transfer.1.0.0.json +21 -0
- package/touch/Tasks/execute-rezervation-transfer.1.0.0.json +19 -0
- package/touch/Tasks/fetch-absence-entries-for-transfer.1.0.0.json +23 -0
- package/touch/Tasks/fetch-advisors-for-transfer.1.0.0.json +23 -0
- package/touch/Tasks/fetch-permanent-chatrooms-for-transfer.1.0.0.json +23 -0
- package/touch/Tasks/fetch-rez-chatrooms-for-transfer.1.0.0.json +23 -0
- package/touch/Tasks/fetch-rezervations-for-transfer.1.0.0.json +22 -0
- package/touch/Tasks/get-absence-entry-task.1.0.0.json +23 -0
- package/touch/Tasks/get-available-slots-http.1.0.0.json +27 -0
- package/touch/Tasks/get-available-slots.1.0.0.json +24 -0
- package/touch/Tasks/get-chat-room-data-for-rezervation.1.0.0.json +23 -0
- package/touch/Tasks/get-chat-token.1.0.0.json +27 -0
- package/touch/Tasks/get-matrix-room-messages.1.0.0.json +25 -0
- package/touch/Tasks/get-matrix-sync.1.0.0.json +25 -0
- package/touch/Tasks/get-rezervation-data-task.1.0.0.json +22 -0
- package/touch/Tasks/get-rezervation-state-task.1.0.0.json +22 -0
- package/touch/Tasks/get-rezervations-task.1.0.0.json +21 -0
- package/touch/Tasks/get-user-info-for-rezervation.1.0.0.json +24 -0
- package/touch/Tasks/get-video-call-url.1.0.0.json +17 -0
- package/touch/Tasks/invite-user-to-rezervation-room.1.0.0.json +27 -0
- package/touch/Tasks/join-chat-room-for-rezervation.1.0.0.json +28 -0
- package/touch/Tasks/join-matrix-room.1.0.0.json +27 -0
- package/touch/Tasks/join-user-to-room.1.0.0.json +27 -0
- package/touch/Tasks/merge-invited-user.1.0.0.json +17 -0
- package/touch/Tasks/merge-rezervation-update.1.0.0.json +16 -0
- package/touch/Tasks/merge-target-advisor-for-transfer.1.0.0.json +17 -0
- package/touch/Tasks/merge-update-body-for-randevu-update.1.0.0.json +16 -0
- package/touch/Tasks/merge-video-call-urls.1.0.0.json +17 -0
- package/touch/Tasks/query-chat-room-instances.1.0.0.json +23 -0
- package/touch/Tasks/remove-member-from-room.1.0.0.json +28 -0
- package/touch/Tasks/send-matrix-room-message.1.0.0.json +26 -0
- package/touch/Tasks/send-push-notification.1.0.0.json +26 -0
- package/touch/Tasks/send-sms-notification.1.0.0.json +26 -0
- package/touch/Tasks/set-chat-room-status-active.1.0.0.json +16 -0
- package/touch/Tasks/set-chat-room-status-deactive.1.0.0.json +16 -0
- package/touch/Tasks/set-previous-advisor.1.0.0.json +16 -0
- package/touch/Tasks/set-user-from-headers-for-rezervation.1.0.0.json +17 -0
- package/touch/Tasks/start-absence-entry-for-rezervation.1.0.0.json +21 -0
- package/touch/Tasks/start-chat-room-for-rezervation.1.0.0.json +20 -0
- package/touch/Tasks/start-notification-sender.1.0.0.json +20 -0
- package/touch/Tasks/start-permanent-chat-room.1.0.0.json +21 -0
- package/touch/Tasks/start-transfer-from-absence-entry.1.0.0.json +19 -0
- package/touch/Tasks/start-video-call.1.0.0.json +22 -0
- package/touch/Tasks/trigger-chat-room-deactivate.1.0.0.json +21 -0
- package/touch/Tasks/trigger-chat-room-transfer.1.0.0.json +21 -0
- package/touch/Tasks/trigger-chat-room-update.1.0.0.json +20 -0
- package/touch/Tasks/trigger-rezervation-add-invited-participant.1.0.0.json +20 -0
- package/touch/Tasks/trigger-rezervation-apply-update.1.0.0.json +20 -0
- package/touch/Tasks/trigger-rezervation-to-in-meet.1.0.0.json +20 -0
- package/touch/Tasks/trigger-rezervation-video-call-update.1.0.0.json +21 -0
- package/touch/Tasks/validate-date-for-rezervation.1.0.0.json +18 -0
- package/touch/Tasks/validate-slot-for-rezervation.1.0.0.json +24 -0
- package/touch/Tasks/validate-transfer-availability.1.0.0.json +23 -0
- package/touch/Views/.gitkeep +0 -0
- package/touch/Workflows/.gitkeep +0 -0
- package/touch/Workflows/absence-entry.http +458 -0
- package/touch/Workflows/absence-entry.json +179 -0
- package/touch/Workflows/add-participant-to-rezervation.http +47 -0
- package/touch/Workflows/add-participant-to-rezervation.json +340 -0
- package/touch/Workflows/chat-room.http +207 -0
- package/touch/Workflows/chat-room.json +452 -0
- package/touch/Workflows/investment-advisor.json +367 -0
- package/touch/Workflows/notification-sender.http +299 -0
- package/touch/Workflows/notification-sender.json +262 -0
- package/touch/Workflows/portfolio-manager.json +367 -0
- package/touch/Workflows/randevu-update.http +87 -0
- package/touch/Workflows/rezervation-start.json +467 -0
- package/touch/Workflows/rezervation-transfer.json +512 -0
- package/touch/Workflows/rezervation-update.http +87 -0
- package/touch/Workflows/rezervation-update.json +485 -0
- package/touch/Workflows/rezervation.http +214 -0
- package/touch/Workflows/rezervation.json +726 -0
- package/touch/Workflows/src/AllChatRoomsSuccessRule.csx +65 -0
- package/touch/Workflows/src/AlwaysTrueRule.csx +13 -0
- package/touch/Workflows/src/AnyChatRoomFailedRule.csx +64 -0
- package/touch/Workflows/src/AutoProcessRule.csx +38 -0
- package/touch/Workflows/src/BuildRezChatRoomPlanMapping.csx +160 -0
- package/touch/Workflows/src/CanStartRezervationTimerMapping.csx +48 -0
- package/touch/Workflows/src/CanStartTransferMapping.csx +14 -0
- package/touch/Workflows/src/CancelAbsenceEntryForRezervationMapping.csx +48 -0
- package/touch/Workflows/src/CancelAbsenceForRandevuUpdateMapping.csx +62 -0
- package/touch/Workflows/src/ChatRoomCreatedFailedRule.csx +54 -0
- package/touch/Workflows/src/ChatRoomCreatedSuccessRule.csx +54 -0
- package/touch/Workflows/src/ChatRoomRemoveMapping.csx +104 -0
- package/touch/Workflows/src/ChatRoomTransferInviteMapping.csx +109 -0
- package/touch/Workflows/src/ChatRoomTransferRemoveMapping.csx +71 -0
- package/touch/Workflows/src/ChatRoomUpdateMapping.csx +107 -0
- package/touch/Workflows/src/CheckAlreadyCompletedChatRoomMapping.csx +100 -0
- package/touch/Workflows/src/CheckDuplicatePortfolioManagerMapping.csx +119 -0
- package/touch/Workflows/src/CheckDuplicateRezervationMapping.csx +150 -0
- package/touch/Workflows/src/CheckExistingPermanentChatRoomMapping.csx +169 -0
- package/touch/Workflows/src/CheckRandevuTimeMapping.csx +67 -0
- package/touch/Workflows/src/CheckRezervationStateActiveOrInMeetRule.csx +14 -0
- package/touch/Workflows/src/CreateAbsenceEntryForRezervationMapping.csx +111 -0
- package/touch/Workflows/src/CreateAbsenceForRandevuUpdateMapping.csx +108 -0
- package/touch/Workflows/src/CreateChatRoomForRezervationMapping.csx +122 -0
- package/touch/Workflows/src/CreatePermanentChatRoomMapping.csx +140 -0
- package/touch/Workflows/src/CustomerControlToEndRule.csx +14 -0
- package/touch/Workflows/src/DetermineTransferTypeMapping.csx +92 -0
- package/touch/Workflows/src/EnrichRezervationsForTransferMapping.csx +495 -0
- package/touch/Workflows/src/ExecutePermanentChatRoomUpdateMapping.csx +124 -0
- package/touch/Workflows/src/ExecuteRezChatRoomTransferMapping.csx +95 -0
- package/touch/Workflows/src/ExecuteTransferMapping.csx +152 -0
- package/touch/Workflows/src/FetchAbsenceEntriesForTransferMapping.csx +116 -0
- package/touch/Workflows/src/FetchAdvisorsForTransferMapping.csx +145 -0
- package/touch/Workflows/src/FetchPermanentChatRoomsMapping.csx +128 -0
- package/touch/Workflows/src/FetchRezervationsForTransferMapping.csx +124 -0
- package/touch/Workflows/src/GetChatRoomDataForRezervationMapping.csx +100 -0
- package/touch/Workflows/src/GetChatTokenMapping.csx +85 -0
- package/touch/Workflows/src/GetRezervationDataForAddParticipantMapping.csx +105 -0
- package/touch/Workflows/src/GetRezervationDataForRandevuUpdateMapping.csx +110 -0
- package/touch/Workflows/src/GetRezervationDataMapping.csx +111 -0
- package/touch/Workflows/src/GetRezervationStateForRandevuUpdateMapping.csx +80 -0
- package/touch/Workflows/src/GetRezervationStateMapping.csx +92 -0
- package/touch/Workflows/src/GetUserInfoForRezervationMapping.csx +63 -0
- package/touch/Workflows/src/GetVideoCallUrlMapping.csx +62 -0
- package/touch/Workflows/src/HasChangedAdvisorRule.csx +28 -0
- package/touch/Workflows/src/HasChatIntegrationRule.csx +41 -0
- package/touch/Workflows/src/HasExistingPermanentRoomRule.csx +28 -0
- package/touch/Workflows/src/InviteAdvisorForRandevuUpdateMapping.csx +86 -0
- package/touch/Workflows/src/InviteNewAdvisorToRezervationRoomMapping.csx +78 -0
- package/touch/Workflows/src/InviteNewParticipantToRandevuRoomMapping.csx +88 -0
- package/touch/Workflows/src/InvitedUserMergeMapping.csx +77 -0
- package/touch/Workflows/src/InvitedUserNotAllowedRule.csx +71 -0
- package/touch/Workflows/src/InvitedUserNotInMeetRule.csx +19 -0
- package/touch/Workflows/src/IsNotfSentRule.csx +36 -0
- package/touch/Workflows/src/JoinChatRoomForAddParticipantMapping.csx +118 -0
- package/touch/Workflows/src/JoinChatRoomForRandevuStartMapping.csx +119 -0
- package/touch/Workflows/src/JoinChatRoomForRezervationMapping.csx +118 -0
- package/touch/Workflows/src/JoinMatrixRoomMapping.csx +100 -0
- package/touch/Workflows/src/JoinUserToRoomMapping.csx +118 -0
- package/touch/Workflows/src/LoginForAddParticipantChatMapping.csx +102 -0
- package/touch/Workflows/src/LoginForRandevuStartChatMapping.csx +96 -0
- package/touch/Workflows/src/MergeRezervationUpdateMapping.csx +82 -0
- package/touch/Workflows/src/MergeTargetAdvisorForTransferMapping.csx +79 -0
- package/touch/Workflows/src/MergeUpdateBodyForRandevuUpdateMapping.csx +91 -0
- package/touch/Workflows/src/NoExistingPermanentRoomRule.csx +23 -0
- package/touch/Workflows/src/NotificationCompleteAlwaysRule.csx +14 -0
- package/touch/Workflows/src/NotificationCompleteFromPendingRule.csx +41 -0
- package/touch/Workflows/src/NotificationCompleteFromSmsRule.csx +36 -0
- package/touch/Workflows/src/NotificationPushFromPendingRule.csx +42 -0
- package/touch/Workflows/src/NotificationPushFromSmsRule.csx +36 -0
- package/touch/Workflows/src/NotificationSmsPendingRule.csx +32 -0
- package/touch/Workflows/src/PermanentDoneRule.csx +44 -0
- package/touch/Workflows/src/PermanentProcessNextRule.csx +44 -0
- package/touch/Workflows/src/RezChatRoomProcessNextRule.csx +44 -0
- package/touch/Workflows/src/RezChatRoomsDoneRule.csx +44 -0
- package/touch/Workflows/src/SendPushNotificationMapping.csx +146 -0
- package/touch/Workflows/src/SendSmsNotificationMapping.csx +138 -0
- package/touch/Workflows/src/SetChatRoomStatusActiveMapping.csx +22 -0
- package/touch/Workflows/src/SetChatRoomStatusDeactiveMapping.csx +22 -0
- package/touch/Workflows/src/SetPreviousAdvisorMapping.csx +28 -0
- package/touch/Workflows/src/SetUserFromHeadersForRezervationMapping.csx +24 -0
- package/touch/Workflows/src/SlotAvailableRule.csx +33 -0
- package/touch/Workflows/src/SlotUnavailableRule.csx +33 -0
- package/touch/Workflows/src/StartChatRoomForRezervationMapping.csx +100 -0
- package/touch/Workflows/src/StartGetChatTokenForRezervationMapping.csx +71 -0
- package/touch/Workflows/src/StartNotificationForAdvisorMapping.csx +117 -0
- package/touch/Workflows/src/StartNotificationForRezervationFromUserInfoMapping.csx +128 -0
- package/touch/Workflows/src/StartNotificationForUserMapping.csx +117 -0
- package/touch/Workflows/src/StartPermanentChatRoomMapping.csx +92 -0
- package/touch/Workflows/src/StartTransferFromAbsenceEntryMapping.csx +94 -0
- package/touch/Workflows/src/StartVideoCallCustomerSubFlowMapping.csx +37 -0
- package/touch/Workflows/src/StartVideoCallForInvitedParticipantMapping.csx +54 -0
- package/touch/Workflows/src/StartVideoCallForRandevuStartMapping.csx +70 -0
- package/touch/Workflows/src/StartVideoCallStaffSubFlowMapping.csx +37 -0
- package/touch/Workflows/src/StateActiveForUpdateRule.csx +14 -0
- package/touch/Workflows/src/StateActiveRule.csx +14 -0
- package/touch/Workflows/src/StateInMeetRule.csx +14 -0
- package/touch/Workflows/src/StateNotActiveForUpdateRule.csx +14 -0
- package/touch/Workflows/src/StateNotActiveOrInMeetRule.csx +14 -0
- package/touch/Workflows/src/StatusCustomerEnterRule.csx +25 -0
- package/touch/Workflows/src/StatusStaffEnterRule.csx +25 -0
- package/touch/Workflows/src/SyncWorkingHoursRule.csx +46 -0
- package/touch/Workflows/src/TokenSuccessRule.csx +24 -0
- package/touch/Workflows/src/TransferAllDoneRule.csx +50 -0
- package/touch/Workflows/src/TransferHasInvalidRule.csx +34 -0
- package/touch/Workflows/src/TransferProcessNextRule.csx +50 -0
- package/touch/Workflows/src/TriggerChatRoomDeactivateMapping.csx +77 -0
- package/touch/Workflows/src/TriggerChatRoomTransferMapping.csx +93 -0
- package/touch/Workflows/src/TriggerChatRoomUpdateMapping.csx +99 -0
- package/touch/Workflows/src/TriggerRezervationAddInvitedParticipantMapping.csx +77 -0
- package/touch/Workflows/src/TriggerRezervationApplyUpdateMapping.csx +66 -0
- package/touch/Workflows/src/TriggerRezervationToInMeetMapping.csx +69 -0
- package/touch/Workflows/src/TriggerRezervationVideoCallUpdateMapping.csx +67 -0
- package/touch/Workflows/src/ValidateDateForRezervationMapping.csx +60 -0
- package/touch/Workflows/src/ValidateSlotForRandevuUpdateMapping.csx +211 -0
- package/touch/Workflows/src/ValidateSlotForRezervationMapping.csx +246 -0
- package/touch/Workflows/src/ValidateTransferMapping.csx +243 -0
- package/touch/Workflows/src/VideoCallUrlUpdateMergeMapping.csx +141 -0
- package/touch/Workflows/start-chat.json +217 -0
- package/touch/Workflows/start-video-call.http +93 -0
- package/touch/Workflows/start-video-call.json +206 -0
- package/vnext.config.json +58 -0
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using System.Linq;
|
|
4
|
+
using System.Threading.Tasks;
|
|
5
|
+
using BBT.Workflow.Scripting;
|
|
6
|
+
using BBT.Workflow.Definitions;
|
|
7
|
+
|
|
8
|
+
/// <summary>
|
|
9
|
+
/// Mapping for enrich-rezervations-for-transfer task (DaprServiceTask - Type 3).
|
|
10
|
+
/// Queries ALL active reservations in the date range across all advisors.
|
|
11
|
+
/// OutputHandler enriches each source advisor's reservation with a list of advisors
|
|
12
|
+
/// that are available based on: reservation conflicts, working hours, public holidays,
|
|
13
|
+
/// and personal leaves (using absenceEntries from previous task).
|
|
14
|
+
/// </summary>
|
|
15
|
+
public class EnrichRezervationsForTransferMapping : ScriptBase, IMapping
|
|
16
|
+
{
|
|
17
|
+
public Task<ScriptResponse> InputHandler(WorkflowTask task, ScriptContext context)
|
|
18
|
+
{
|
|
19
|
+
var serviceTask = task as DaprServiceTask;
|
|
20
|
+
if (serviceTask == null)
|
|
21
|
+
throw new InvalidOperationException("Task must be a DaprServiceTask");
|
|
22
|
+
|
|
23
|
+
var appId = GetConfigValue("DAPR_APP_ID");
|
|
24
|
+
if (!string.IsNullOrEmpty(appId))
|
|
25
|
+
serviceTask.SetAppId(appId);
|
|
26
|
+
|
|
27
|
+
var data = context.Instance?.Data;
|
|
28
|
+
if (data == null)
|
|
29
|
+
throw new InvalidOperationException("Instance data is required");
|
|
30
|
+
|
|
31
|
+
var startDate = GetString(data, "startDate");
|
|
32
|
+
var endDate = GetString(data, "endDate");
|
|
33
|
+
|
|
34
|
+
if (string.IsNullOrEmpty(startDate))
|
|
35
|
+
throw new ArgumentException("startDate is required.", "startDate");
|
|
36
|
+
if (string.IsNullOrEmpty(endDate))
|
|
37
|
+
endDate = "2099-12-31";
|
|
38
|
+
|
|
39
|
+
var conditions = new List<string>
|
|
40
|
+
{
|
|
41
|
+
"{\"or\":[" +
|
|
42
|
+
"{\"currentState\":{\"eq\":\"active\"}}," +
|
|
43
|
+
"{\"currentState\":{\"eq\":\"in-meet\"}}" +
|
|
44
|
+
"]}",
|
|
45
|
+
"{\"status\":{\"eq\":\"A\"}}",
|
|
46
|
+
"{\"attributes\":{\"startDateTime\":{\"gte\":\"" + startDate + "\"}}}",
|
|
47
|
+
"{\"attributes\":{\"endDateTime\":{\"lte\":\"" + endDate + "\"}}}"
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
var filterJson = "{\"and\":[" + string.Join(",", conditions) + "]}";
|
|
51
|
+
var queryParams = new List<string>
|
|
52
|
+
{
|
|
53
|
+
"pageSize=100",
|
|
54
|
+
"filter=" + filterJson
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
serviceTask.SetQueryString(string.Join("&", queryParams));
|
|
58
|
+
return Task.FromResult(new ScriptResponse());
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public Task<ScriptResponse> OutputHandler(ScriptContext context)
|
|
62
|
+
{
|
|
63
|
+
try
|
|
64
|
+
{
|
|
65
|
+
var body = context.Body;
|
|
66
|
+
var data = context.Instance?.Data;
|
|
67
|
+
|
|
68
|
+
if (body != null && body.isSuccess == false)
|
|
69
|
+
{
|
|
70
|
+
var errorMessage = body.errorMessage?.ToString() ?? "Failed to fetch all reservations";
|
|
71
|
+
throw new Exception(errorMessage);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
var sourceAdvisorId = GetString(data, "sourceAdvisorId");
|
|
75
|
+
var sourceRezervations = data?.rezervations;
|
|
76
|
+
|
|
77
|
+
var responseData = body?.data;
|
|
78
|
+
var allItems = responseData?.items;
|
|
79
|
+
|
|
80
|
+
var publicHolidays = new List<dynamic>();
|
|
81
|
+
var advisorWorkHoursMap = new Dictionary<string, List<dynamic>>();
|
|
82
|
+
var companyWorkHours = new List<dynamic>();
|
|
83
|
+
var personalLeavesMap = new Dictionary<string, List<dynamic>>();
|
|
84
|
+
|
|
85
|
+
var absenceEntries = data?.absenceEntries;
|
|
86
|
+
if (absenceEntries != null)
|
|
87
|
+
{
|
|
88
|
+
foreach (var entry in absenceEntries)
|
|
89
|
+
{
|
|
90
|
+
if (entry == null) continue;
|
|
91
|
+
var attrs = entry?.attributes;
|
|
92
|
+
if (attrs == null) continue;
|
|
93
|
+
|
|
94
|
+
var absenceType = GetString(attrs, "absenceType");
|
|
95
|
+
var advisor = GetString(attrs, "advisor");
|
|
96
|
+
|
|
97
|
+
switch (absenceType)
|
|
98
|
+
{
|
|
99
|
+
case "public-holiday":
|
|
100
|
+
publicHolidays.Add(entry);
|
|
101
|
+
break;
|
|
102
|
+
case "working-hours-change":
|
|
103
|
+
if (!string.IsNullOrEmpty(advisor))
|
|
104
|
+
{
|
|
105
|
+
if (!advisorWorkHoursMap.ContainsKey(advisor))
|
|
106
|
+
advisorWorkHoursMap[advisor] = new List<dynamic>();
|
|
107
|
+
advisorWorkHoursMap[advisor].Add(entry);
|
|
108
|
+
}
|
|
109
|
+
else
|
|
110
|
+
{
|
|
111
|
+
companyWorkHours.Add(entry);
|
|
112
|
+
}
|
|
113
|
+
break;
|
|
114
|
+
case "personal-leave":
|
|
115
|
+
if (!string.IsNullOrEmpty(advisor))
|
|
116
|
+
{
|
|
117
|
+
if (!personalLeavesMap.ContainsKey(advisor))
|
|
118
|
+
personalLeavesMap[advisor] = new List<dynamic>();
|
|
119
|
+
personalLeavesMap[advisor].Add(entry);
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
var enriched = new List<object>();
|
|
127
|
+
|
|
128
|
+
if (sourceRezervations != null)
|
|
129
|
+
{
|
|
130
|
+
foreach (var rez in sourceRezervations)
|
|
131
|
+
{
|
|
132
|
+
if (rez == null) continue;
|
|
133
|
+
|
|
134
|
+
var rezStartStr = GetNestedString(rez, "attributes", "startDateTime")
|
|
135
|
+
?? GetString(rez, "startDateTime");
|
|
136
|
+
var rezEndStr = GetNestedString(rez, "attributes", "endDateTime")
|
|
137
|
+
?? GetString(rez, "endDateTime");
|
|
138
|
+
var rezKey = HasProperty(rez, "key") ? rez.key?.ToString() : "";
|
|
139
|
+
var rezUser = GetNestedString(rez, "attributes", "user")
|
|
140
|
+
?? GetString(rez, "user");
|
|
141
|
+
var rezAdvisor = GetNestedString(rez, "attributes", "advisor")
|
|
142
|
+
?? GetString(rez, "advisor");
|
|
143
|
+
|
|
144
|
+
var busyAdvisors = new HashSet<string>();
|
|
145
|
+
if (!string.IsNullOrEmpty(sourceAdvisorId))
|
|
146
|
+
busyAdvisors.Add(sourceAdvisorId);
|
|
147
|
+
|
|
148
|
+
DateTime rezStart = DateTime.MinValue;
|
|
149
|
+
DateTime rezEnd = DateTime.MinValue;
|
|
150
|
+
if (!string.IsNullOrEmpty(rezStartStr) && !string.IsNullOrEmpty(rezEndStr) &&
|
|
151
|
+
DateTime.TryParse(rezStartStr, out rezStart) && DateTime.TryParse(rezEndStr, out rezEnd) &&
|
|
152
|
+
allItems != null)
|
|
153
|
+
{
|
|
154
|
+
foreach (var item in allItems)
|
|
155
|
+
{
|
|
156
|
+
if (item == null) continue;
|
|
157
|
+
var itemAdvisor = GetNestedString(item, "attributes", "advisor")
|
|
158
|
+
?? GetString(item, "advisor");
|
|
159
|
+
var itemStartStr = GetNestedString(item, "attributes", "startDateTime")
|
|
160
|
+
?? GetString(item, "startDateTime");
|
|
161
|
+
var itemEndStr = GetNestedString(item, "attributes", "endDateTime")
|
|
162
|
+
?? GetString(item, "endDateTime");
|
|
163
|
+
|
|
164
|
+
if (string.IsNullOrEmpty(itemAdvisor) || string.IsNullOrEmpty(itemStartStr) || string.IsNullOrEmpty(itemEndStr))
|
|
165
|
+
continue;
|
|
166
|
+
|
|
167
|
+
DateTime itemStart = DateTime.MinValue;
|
|
168
|
+
DateTime itemEnd = DateTime.MinValue;
|
|
169
|
+
if (DateTime.TryParse(itemStartStr, out itemStart) && DateTime.TryParse(itemEndStr, out itemEnd))
|
|
170
|
+
{
|
|
171
|
+
if (itemStart < rezEnd && itemEnd > rezStart)
|
|
172
|
+
{
|
|
173
|
+
busyAdvisors.Add(itemAdvisor);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
var allAdvisors = new HashSet<string>();
|
|
180
|
+
var advisorKeys = data?.allAdvisorKeys;
|
|
181
|
+
if (advisorKeys != null)
|
|
182
|
+
{
|
|
183
|
+
foreach (var ak in advisorKeys)
|
|
184
|
+
{
|
|
185
|
+
if (ak == null) continue;
|
|
186
|
+
var key = ak?.ToString();
|
|
187
|
+
if (!string.IsNullOrEmpty(key))
|
|
188
|
+
allAdvisors.Add(key);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
var available = new List<string>();
|
|
193
|
+
foreach (var adv in allAdvisors)
|
|
194
|
+
{
|
|
195
|
+
if (busyAdvisors.Contains(adv))
|
|
196
|
+
continue;
|
|
197
|
+
|
|
198
|
+
if (rezStart != DateTime.MinValue && rezEnd != DateTime.MinValue)
|
|
199
|
+
{
|
|
200
|
+
if (!IsSlotAvailableForAdvisor(adv, rezStart, rezEnd,
|
|
201
|
+
publicHolidays, advisorWorkHoursMap, companyWorkHours, personalLeavesMap))
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
available.Add(adv);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
enriched.Add(new
|
|
209
|
+
{
|
|
210
|
+
key = rezKey,
|
|
211
|
+
startDateTime = rezStartStr,
|
|
212
|
+
endDateTime = rezEndStr,
|
|
213
|
+
user = rezUser,
|
|
214
|
+
advisor = rezAdvisor,
|
|
215
|
+
availableAdvisors = available
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
var result = new Dictionary<string, object>();
|
|
221
|
+
result["sourceAdvisorId"] = sourceAdvisorId;
|
|
222
|
+
result["advisorType"] = GetString(data, "advisorType");
|
|
223
|
+
result["startDate"] = GetString(data, "startDate");
|
|
224
|
+
result["endDate"] = GetString(data, "endDate");
|
|
225
|
+
result["transferType"] = GetString(data, "transferType");
|
|
226
|
+
result["enrichedRezervations"] = enriched;
|
|
227
|
+
result["rezervations"] = new List<object>();
|
|
228
|
+
result["absenceEntries"] = new List<object>();
|
|
229
|
+
result["allAdvisorKeys"] = new List<string>();
|
|
230
|
+
|
|
231
|
+
return Task.FromResult(new ScriptResponse
|
|
232
|
+
{
|
|
233
|
+
Data = result
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
catch (Exception ex)
|
|
237
|
+
{
|
|
238
|
+
return Task.FromResult(new ScriptResponse
|
|
239
|
+
{
|
|
240
|
+
Data = new
|
|
241
|
+
{
|
|
242
|
+
error = "Failed to enrich reservations",
|
|
243
|
+
errorDescription = ex.Message
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
#region Slot Availability
|
|
250
|
+
|
|
251
|
+
private bool IsSlotAvailableForAdvisor(string advisorKey, DateTime rezStart, DateTime rezEnd,
|
|
252
|
+
List<dynamic> publicHolidays,
|
|
253
|
+
Dictionary<string, List<dynamic>> advisorWorkHoursMap,
|
|
254
|
+
List<dynamic> companyWorkHours,
|
|
255
|
+
Dictionary<string, List<dynamic>> personalLeavesMap)
|
|
256
|
+
{
|
|
257
|
+
var rezDate = rezStart.Date;
|
|
258
|
+
var dayOfWeek = rezDate.DayOfWeek.ToString().ToLower();
|
|
259
|
+
var slotStart = rezStart.TimeOfDay;
|
|
260
|
+
var slotEnd = rezEnd.TimeOfDay;
|
|
261
|
+
|
|
262
|
+
var holidayRanges = GetHolidayRanges(publicHolidays, rezDate);
|
|
263
|
+
if (holidayRanges != null && holidayRanges.Count == 1
|
|
264
|
+
&& holidayRanges[0].Item1 == TimeSpan.Zero
|
|
265
|
+
&& holidayRanges[0].Item2 >= new TimeSpan(23, 59, 0))
|
|
266
|
+
return false;
|
|
267
|
+
|
|
268
|
+
List<dynamic> advWorkHours = null;
|
|
269
|
+
if (advisorWorkHoursMap.ContainsKey(advisorKey))
|
|
270
|
+
advWorkHours = advisorWorkHoursMap[advisorKey];
|
|
271
|
+
|
|
272
|
+
var workHours = GetWorkingHoursForDay(advWorkHours, dayOfWeek);
|
|
273
|
+
if (workHours == null || workHours.Count == 0)
|
|
274
|
+
workHours = GetWorkingHoursForDay(companyWorkHours, dayOfWeek);
|
|
275
|
+
|
|
276
|
+
if (workHours == null || workHours.Count == 0)
|
|
277
|
+
return false;
|
|
278
|
+
|
|
279
|
+
bool slotInWorkHours = false;
|
|
280
|
+
foreach (var wh in workHours)
|
|
281
|
+
{
|
|
282
|
+
dynamic whDyn = wh;
|
|
283
|
+
var startStr = whDyn?.start?.ToString();
|
|
284
|
+
var endStr = whDyn?.end?.ToString();
|
|
285
|
+
if (string.IsNullOrEmpty(startStr) || string.IsNullOrEmpty(endStr))
|
|
286
|
+
continue;
|
|
287
|
+
|
|
288
|
+
TimeSpan whStart = TimeSpan.MinValue;
|
|
289
|
+
TimeSpan whEnd = TimeSpan.MinValue;
|
|
290
|
+
if (!TimeSpan.TryParse(startStr, out whStart) || !TimeSpan.TryParse(endStr, out whEnd))
|
|
291
|
+
continue;
|
|
292
|
+
|
|
293
|
+
if (slotStart >= whStart && slotEnd <= whEnd)
|
|
294
|
+
{
|
|
295
|
+
slotInWorkHours = true;
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (!slotInWorkHours)
|
|
301
|
+
return false;
|
|
302
|
+
|
|
303
|
+
var unavailableRanges = new List<Tuple<TimeSpan, TimeSpan>>();
|
|
304
|
+
|
|
305
|
+
List<dynamic> advLeaves = null;
|
|
306
|
+
if (personalLeavesMap.ContainsKey(advisorKey))
|
|
307
|
+
advLeaves = personalLeavesMap[advisorKey];
|
|
308
|
+
if (advLeaves != null)
|
|
309
|
+
unavailableRanges.AddRange(GetUnavailableRanges(advLeaves, rezDate));
|
|
310
|
+
|
|
311
|
+
if (holidayRanges != null)
|
|
312
|
+
unavailableRanges.AddRange(holidayRanges);
|
|
313
|
+
|
|
314
|
+
foreach (var ur in unavailableRanges)
|
|
315
|
+
{
|
|
316
|
+
if (slotStart < ur.Item2 && slotEnd > ur.Item1)
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
private List<Tuple<TimeSpan, TimeSpan>> GetHolidayRanges(List<dynamic> holidays, DateTime date)
|
|
324
|
+
{
|
|
325
|
+
var ranges = new List<Tuple<TimeSpan, TimeSpan>>();
|
|
326
|
+
bool hasHoliday = false;
|
|
327
|
+
|
|
328
|
+
foreach (var holiday in holidays)
|
|
329
|
+
{
|
|
330
|
+
var holidayData = holiday?.attributes;
|
|
331
|
+
if (holidayData == null) continue;
|
|
332
|
+
|
|
333
|
+
string startDateTimeStr = GetString(holidayData, "startDateTime");
|
|
334
|
+
string endDateTimeStr = GetString(holidayData, "endDateTime");
|
|
335
|
+
|
|
336
|
+
if (string.IsNullOrEmpty(startDateTimeStr) || string.IsNullOrEmpty(endDateTimeStr))
|
|
337
|
+
continue;
|
|
338
|
+
|
|
339
|
+
DateTime startDateTime = DateTime.MinValue;
|
|
340
|
+
DateTime endDateTime = DateTime.MinValue;
|
|
341
|
+
if (!DateTime.TryParse(startDateTimeStr, out startDateTime) || !DateTime.TryParse(endDateTimeStr, out endDateTime))
|
|
342
|
+
continue;
|
|
343
|
+
|
|
344
|
+
if (date.Date < startDateTime.Date || date.Date > endDateTime.Date)
|
|
345
|
+
continue;
|
|
346
|
+
|
|
347
|
+
hasHoliday = true;
|
|
348
|
+
|
|
349
|
+
if (startDateTime.Date != endDateTime.Date)
|
|
350
|
+
{
|
|
351
|
+
if (date.Date == startDateTime.Date)
|
|
352
|
+
ranges.Add(Tuple.Create(startDateTime.TimeOfDay, new TimeSpan(23, 59, 59)));
|
|
353
|
+
else if (date.Date == endDateTime.Date)
|
|
354
|
+
ranges.Add(Tuple.Create(TimeSpan.Zero, endDateTime.TimeOfDay));
|
|
355
|
+
else
|
|
356
|
+
ranges.Add(Tuple.Create(TimeSpan.Zero, new TimeSpan(23, 59, 59)));
|
|
357
|
+
}
|
|
358
|
+
else
|
|
359
|
+
{
|
|
360
|
+
ranges.Add(Tuple.Create(startDateTime.TimeOfDay, endDateTime.TimeOfDay));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return hasHoliday ? ranges : null;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
private List<object> GetWorkingHoursForDay(List<dynamic> workingHoursChanges, string dayOfWeek)
|
|
368
|
+
{
|
|
369
|
+
if (workingHoursChanges == null) return null;
|
|
370
|
+
|
|
371
|
+
foreach (var change in workingHoursChanges)
|
|
372
|
+
{
|
|
373
|
+
var changeData = change?.attributes;
|
|
374
|
+
if (changeData == null) continue;
|
|
375
|
+
|
|
376
|
+
var customWH = changeData?.customWorkingHours;
|
|
377
|
+
if (customWH == null) continue;
|
|
378
|
+
|
|
379
|
+
var dayHours = GetDayHoursFromCustom(customWH, dayOfWeek);
|
|
380
|
+
if (dayHours != null) return dayHours;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
return null;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
private List<object> GetDayHoursFromCustom(dynamic customWH, string dayOfWeek)
|
|
387
|
+
{
|
|
388
|
+
dynamic dayHours = null;
|
|
389
|
+
switch (dayOfWeek)
|
|
390
|
+
{
|
|
391
|
+
case "monday": dayHours = customWH?.monday; break;
|
|
392
|
+
case "tuesday": dayHours = customWH?.tuesday; break;
|
|
393
|
+
case "wednesday": dayHours = customWH?.wednesday; break;
|
|
394
|
+
case "thursday": dayHours = customWH?.thursday; break;
|
|
395
|
+
case "friday": dayHours = customWH?.friday; break;
|
|
396
|
+
case "saturday": dayHours = customWH?.saturday; break;
|
|
397
|
+
case "sunday": dayHours = customWH?.sunday; break;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (dayHours == null) return null;
|
|
401
|
+
|
|
402
|
+
var result = new List<object>();
|
|
403
|
+
foreach (var range in dayHours)
|
|
404
|
+
{
|
|
405
|
+
var start = range?.start?.ToString();
|
|
406
|
+
var end = range?.end?.ToString();
|
|
407
|
+
if (!string.IsNullOrEmpty(start) && !string.IsNullOrEmpty(end))
|
|
408
|
+
{
|
|
409
|
+
result.Add(new { start, end });
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return result.Count > 0 ? result : null;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
private List<Tuple<TimeSpan, TimeSpan>> GetUnavailableRanges(List<dynamic> personalLeaves, DateTime date)
|
|
416
|
+
{
|
|
417
|
+
var ranges = new List<Tuple<TimeSpan, TimeSpan>>();
|
|
418
|
+
|
|
419
|
+
foreach (var leave in personalLeaves)
|
|
420
|
+
{
|
|
421
|
+
var leaveData = leave?.attributes;
|
|
422
|
+
if (leaveData == null) continue;
|
|
423
|
+
|
|
424
|
+
string startDateTimeStr = GetString(leaveData, "startDateTime");
|
|
425
|
+
string endDateTimeStr = GetString(leaveData, "endDateTime");
|
|
426
|
+
|
|
427
|
+
if (string.IsNullOrEmpty(startDateTimeStr) || string.IsNullOrEmpty(endDateTimeStr))
|
|
428
|
+
continue;
|
|
429
|
+
|
|
430
|
+
DateTime startDateTime = DateTime.MinValue;
|
|
431
|
+
DateTime endDateTime = DateTime.MinValue;
|
|
432
|
+
if (!DateTime.TryParse(startDateTimeStr, out startDateTime) || !DateTime.TryParse(endDateTimeStr, out endDateTime))
|
|
433
|
+
continue;
|
|
434
|
+
|
|
435
|
+
if (date.Date < startDateTime.Date || date.Date > endDateTime.Date)
|
|
436
|
+
continue;
|
|
437
|
+
|
|
438
|
+
if (startDateTime.Date != endDateTime.Date)
|
|
439
|
+
{
|
|
440
|
+
if (date.Date == startDateTime.Date)
|
|
441
|
+
ranges.Add(Tuple.Create(startDateTime.TimeOfDay, new TimeSpan(23, 59, 59)));
|
|
442
|
+
else if (date.Date == endDateTime.Date)
|
|
443
|
+
ranges.Add(Tuple.Create(TimeSpan.Zero, endDateTime.TimeOfDay));
|
|
444
|
+
else
|
|
445
|
+
ranges.Add(Tuple.Create(TimeSpan.Zero, new TimeSpan(23, 59, 59)));
|
|
446
|
+
}
|
|
447
|
+
else
|
|
448
|
+
{
|
|
449
|
+
ranges.Add(Tuple.Create(startDateTime.TimeOfDay, endDateTime.TimeOfDay));
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
return ranges;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
#endregion
|
|
457
|
+
|
|
458
|
+
#region Helpers
|
|
459
|
+
|
|
460
|
+
private string GetString(dynamic obj, string name)
|
|
461
|
+
{
|
|
462
|
+
if (obj == null) return null;
|
|
463
|
+
try
|
|
464
|
+
{
|
|
465
|
+
if (HasProperty(obj, name))
|
|
466
|
+
{
|
|
467
|
+
var v = GetPropertyValue(obj, name);
|
|
468
|
+
return v?.ToString();
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
catch { }
|
|
472
|
+
return null;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
private string GetNestedString(dynamic obj, string parent, string child)
|
|
476
|
+
{
|
|
477
|
+
if (obj == null) return null;
|
|
478
|
+
try
|
|
479
|
+
{
|
|
480
|
+
if (HasProperty(obj, parent))
|
|
481
|
+
{
|
|
482
|
+
var nested = GetPropertyValue(obj, parent);
|
|
483
|
+
if (nested != null && HasProperty(nested, child))
|
|
484
|
+
{
|
|
485
|
+
var v = GetPropertyValue(nested, child);
|
|
486
|
+
return v?.ToString();
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
catch { }
|
|
491
|
+
return null;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
#endregion
|
|
495
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using System.Linq;
|
|
4
|
+
using System.Threading.Tasks;
|
|
5
|
+
using BBT.Workflow.Scripting;
|
|
6
|
+
using BBT.Workflow.Definitions;
|
|
7
|
+
|
|
8
|
+
/// <summary>
|
|
9
|
+
/// Mapping for execute-permanent-chatroom-update DirectTriggerTask (Type 12).
|
|
10
|
+
/// Processes one permanent chat room at a time from permanentRoomPlan.
|
|
11
|
+
/// Termination (transferType == "termination") → triggers 'transfer' transition (old advisor out, new in).
|
|
12
|
+
/// Annual Leave (transferType == "annual-leave") → triggers 'update' transition (add new advisor, keep old).
|
|
13
|
+
/// </summary>
|
|
14
|
+
public class ExecutePermanentChatRoomUpdateMapping : ScriptBase, IMapping
|
|
15
|
+
{
|
|
16
|
+
public Task<ScriptResponse> InputHandler(WorkflowTask task, ScriptContext context)
|
|
17
|
+
{
|
|
18
|
+
var triggerTask = task as DirectTriggerTask;
|
|
19
|
+
if (triggerTask == null)
|
|
20
|
+
throw new InvalidOperationException("Task must be a DirectTriggerTask");
|
|
21
|
+
|
|
22
|
+
var data = context.Instance?.Data;
|
|
23
|
+
if (data == null)
|
|
24
|
+
throw new InvalidOperationException("Instance data is required");
|
|
25
|
+
|
|
26
|
+
var permanentRoomPlan = data.permanentRoomPlan;
|
|
27
|
+
if (permanentRoomPlan == null)
|
|
28
|
+
return Task.FromResult(new ScriptResponse { Data = new { skipped = true, reason = "no-permanentRoomPlan" } });
|
|
29
|
+
|
|
30
|
+
int processedIndex = 0;
|
|
31
|
+
if (HasProperty(data, "permanentProcessedIndex"))
|
|
32
|
+
int.TryParse(data.permanentProcessedIndex?.ToString() ?? "0", out processedIndex);
|
|
33
|
+
|
|
34
|
+
var items = permanentRoomPlan as IEnumerable<object>;
|
|
35
|
+
if (items == null)
|
|
36
|
+
return Task.FromResult(new ScriptResponse { Data = new { skipped = true } });
|
|
37
|
+
|
|
38
|
+
var itemsList = items.ToList();
|
|
39
|
+
if (processedIndex >= itemsList.Count)
|
|
40
|
+
return Task.FromResult(new ScriptResponse { Data = new { skipped = true } });
|
|
41
|
+
|
|
42
|
+
dynamic currentItem = itemsList[processedIndex];
|
|
43
|
+
var chatRoomKey = currentItem?.chatRoomKey?.ToString();
|
|
44
|
+
var targetAdvisor = currentItem?.targetAdvisor?.ToString();
|
|
45
|
+
|
|
46
|
+
if (string.IsNullOrEmpty(chatRoomKey) || string.IsNullOrEmpty(targetAdvisor))
|
|
47
|
+
return Task.FromResult(new ScriptResponse { Data = new { skipped = true } });
|
|
48
|
+
|
|
49
|
+
var transferType = GetString(data, "transferType");
|
|
50
|
+
|
|
51
|
+
triggerTask.SetDomain("touch");
|
|
52
|
+
triggerTask.SetFlow("chat-room");
|
|
53
|
+
triggerTask.SetKey(chatRoomKey);
|
|
54
|
+
|
|
55
|
+
if (transferType == "termination")
|
|
56
|
+
{
|
|
57
|
+
triggerTask.SetTransitionName("transfer");
|
|
58
|
+
triggerTask.SetBody(new { newAdvisorId = targetAdvisor });
|
|
59
|
+
}
|
|
60
|
+
else
|
|
61
|
+
{
|
|
62
|
+
triggerTask.SetTransitionName("update");
|
|
63
|
+
triggerTask.SetBody(new { newMemberId = targetAdvisor });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return Task.FromResult(new ScriptResponse());
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public Task<ScriptResponse> OutputHandler(ScriptContext context)
|
|
70
|
+
{
|
|
71
|
+
var data = context.Instance?.Data;
|
|
72
|
+
var success = context.Body?.isSuccess == true;
|
|
73
|
+
|
|
74
|
+
int processedIndex = 0;
|
|
75
|
+
if (data != null && HasProperty(data, "permanentProcessedIndex"))
|
|
76
|
+
int.TryParse(data.permanentProcessedIndex?.ToString() ?? "0", out processedIndex);
|
|
77
|
+
|
|
78
|
+
var result = new Dictionary<string, object>();
|
|
79
|
+
CopyIfPresent(result, data, "transferPlan");
|
|
80
|
+
CopyIfPresent(result, data, "validationResult");
|
|
81
|
+
CopyIfPresent(result, data, "sourceAdvisorId");
|
|
82
|
+
CopyIfPresent(result, data, "advisorType");
|
|
83
|
+
CopyIfPresent(result, data, "startDate");
|
|
84
|
+
CopyIfPresent(result, data, "endDate");
|
|
85
|
+
CopyIfPresent(result, data, "transferType");
|
|
86
|
+
CopyIfPresent(result, data, "enrichedRezervations");
|
|
87
|
+
CopyIfPresent(result, data, "rezChatRoomPlan");
|
|
88
|
+
CopyIfPresent(result, data, "permanentRoomPlan");
|
|
89
|
+
CopyIfPresent(result, data, "permanentChatRooms");
|
|
90
|
+
result["permanentProcessedIndex"] = processedIndex + 1;
|
|
91
|
+
result["lastPermanentChatRoomSuccess"] = success;
|
|
92
|
+
|
|
93
|
+
return Task.FromResult(new ScriptResponse { Data = result });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private string GetString(dynamic obj, string name)
|
|
97
|
+
{
|
|
98
|
+
if (obj == null) return null;
|
|
99
|
+
try
|
|
100
|
+
{
|
|
101
|
+
if (HasProperty(obj, name))
|
|
102
|
+
{
|
|
103
|
+
var v = GetPropertyValue(obj, name);
|
|
104
|
+
return v?.ToString();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch { }
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private void CopyIfPresent(Dictionary<string, object> target, dynamic source, string name)
|
|
112
|
+
{
|
|
113
|
+
if (source == null) return;
|
|
114
|
+
try
|
|
115
|
+
{
|
|
116
|
+
if (HasProperty(source, name))
|
|
117
|
+
{
|
|
118
|
+
var v = GetPropertyValue(source, name);
|
|
119
|
+
if (v != null) target[name] = v;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch { }
|
|
123
|
+
}
|
|
124
|
+
}
|