Fix chat task creation and listing
- createChat: Look up business-specific Chat task type instead of hardcoded ID 2 - listPending: Filter by CompletedOn IS NULL to exclude completed tasks Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
a998ff890a
commit
e60601d9f1
2 changed files with 15 additions and 6 deletions
|
|
@ -35,11 +35,18 @@ try {
|
|||
apiAbort({ "OK": false, "ERROR": "missing_params", "MESSAGE": "BusinessID is required" });
|
||||
}
|
||||
|
||||
// Look up "Chat With Staff" task type for this business
|
||||
ttQuery = queryTimed("
|
||||
SELECT ID FROM tt_TaskTypes
|
||||
WHERE BusinessID = :businessID AND Name LIKE '%Chat%'
|
||||
LIMIT 1
|
||||
", { businessID: { value: businessID, cfsqltype: "cf_sql_integer" } }, { datasource: "payfrit" });
|
||||
chatTaskTypeID = ttQuery.recordCount > 0 ? ttQuery.ID : 0;
|
||||
|
||||
// ServicePointID = 0 is allowed for remote chats (non-dine-in users)
|
||||
// In that case, we use userID to match existing chats
|
||||
|
||||
// Check for existing open chat at this service point
|
||||
// An open chat is one where TaskTypeID=2 (Chat) and CompletedOn IS NULL
|
||||
forceNew = structKeyExists(data, "ForceNew") && data.ForceNew == true;
|
||||
|
||||
if (!forceNew) {
|
||||
|
|
@ -51,7 +58,7 @@ try {
|
|||
FROM Tasks t
|
||||
LEFT JOIN ChatMessages cm2 ON cm2.TaskID = t.ID AND cm2.SenderUserID = :userID
|
||||
WHERE t.BusinessID = :businessID
|
||||
AND t.TaskTypeID = 2
|
||||
AND (t.TaskTypeID = :chatTypeID OR t.Title LIKE 'Chat%')
|
||||
AND t.CompletedOn IS NULL
|
||||
AND (
|
||||
(t.OrderID = :orderID AND :orderID > 0)
|
||||
|
|
@ -63,6 +70,7 @@ try {
|
|||
LIMIT 1
|
||||
", {
|
||||
businessID: { value: businessID, cfsqltype: "cf_sql_integer" },
|
||||
chatTypeID: { value: chatTaskTypeID, cfsqltype: "cf_sql_integer" },
|
||||
servicePointID: { value: servicePointID, cfsqltype: "cf_sql_integer" },
|
||||
orderID: { value: orderID, cfsqltype: "cf_sql_integer" },
|
||||
userID: { value: userID, cfsqltype: "cf_sql_integer" }
|
||||
|
|
@ -164,7 +172,7 @@ try {
|
|||
sourceID = userID;
|
||||
}
|
||||
|
||||
// Insert task with TaskTypeID = 2 (Chat)
|
||||
// Insert task with business-specific Chat task type
|
||||
queryTimed("
|
||||
INSERT INTO Tasks (
|
||||
BusinessID,
|
||||
|
|
@ -181,7 +189,7 @@ try {
|
|||
:businessID,
|
||||
:categoryID,
|
||||
:orderID,
|
||||
2,
|
||||
:taskTypeID,
|
||||
:title,
|
||||
:details,
|
||||
0,
|
||||
|
|
@ -193,6 +201,7 @@ try {
|
|||
businessID: { value: businessID, cfsqltype: "cf_sql_integer" },
|
||||
categoryID: { value: categoryID, cfsqltype: "cf_sql_integer" },
|
||||
orderID: { value: orderID > 0 ? orderID : javaCast("null", ""), cfsqltype: "cf_sql_integer", null: orderID == 0 },
|
||||
taskTypeID: { value: chatTaskTypeID, cfsqltype: "cf_sql_integer", null: chatTaskTypeID == 0 },
|
||||
title: { value: taskTitle, cfsqltype: "cf_sql_varchar" },
|
||||
details: { value: taskDetails, cfsqltype: "cf_sql_varchar" },
|
||||
sourceType: { value: sourceType, cfsqltype: "cf_sql_varchar" },
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@
|
|||
<cfset businessName = qBusiness.recordCount GT 0 ? qBusiness.Name : "">
|
||||
|
||||
|
||||
<!--- Build WHERE clause - unclaimed tasks only --->
|
||||
<cfset whereClauses = ["t.BusinessID = ?", "t.ClaimedByUserID = 0"]>
|
||||
<!--- Build WHERE clause - unclaimed and incomplete tasks only --->
|
||||
<cfset whereClauses = ["t.BusinessID = ?", "t.ClaimedByUserID = 0", "t.CompletedOn IS NULL"]>
|
||||
<cfset params = [ { value = BusinessID, cfsqltype = "cf_sql_integer" } ]>
|
||||
|
||||
<!--- Filter by category if provided --->
|
||||
|
|
|
|||
Reference in a new issue