Add task details API endpoint
- New endpoint: api/tasks/getDetails.cfm - Returns task info, customer info, service point, order line items - Joins Tasks, Orders, Users, ServicePoints, OrderLineItems tables - Add getDetails.cfm to public endpoints allowlist in Application.cfm 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
d225133c68
commit
e9b44ec4be
3 changed files with 160 additions and 21 deletions
|
|
@ -32,10 +32,8 @@
|
|||
showdebugoutput="false"
|
||||
>
|
||||
|
||||
<!--- Stripe Configuration --->
|
||||
<cfset application.stripeSecretKey = "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">
|
||||
<cfset application.stripePublishableKey = "pk_live_Wqj4yGmtTghVJu7oufnWmU5H">
|
||||
<cfset application.stripeWebhookSecret = "whsec_8t6s9Lz0S5M1SYcEYvZ73qFP4zmtlG6h">
|
||||
<!--- Stripe Configuration (loads from config/stripe.cfm) --->
|
||||
<cfinclude template="config/stripe.cfm">
|
||||
|
||||
<cfscript>
|
||||
function apiAbort(payload) {
|
||||
|
|
@ -85,6 +83,7 @@ if (len(request._api_path)) {
|
|||
if (findNoCase("/api/tasks/accept.cfm", request._api_path)) request._api_isPublic = true;
|
||||
if (findNoCase("/api/tasks/listMine.cfm", request._api_path)) request._api_isPublic = true;
|
||||
if (findNoCase("/api/tasks/complete.cfm", request._api_path)) request._api_isPublic = true;
|
||||
if (findNoCase("/api/tasks/getDetails.cfm", request._api_path)) request._api_isPublic = true;
|
||||
|
||||
// Worker app endpoints
|
||||
if (findNoCase("/api/workers/myBusinesses.cfm", request._api_path)) request._api_isPublic = true;
|
||||
|
|
|
|||
|
|
@ -127,23 +127,7 @@ try {
|
|||
abort;
|
||||
}
|
||||
|
||||
// Save payment intent and fee info to order
|
||||
queryExecute("
|
||||
UPDATE Orders
|
||||
SET OrderStripePaymentIntentID = :paymentIntentID,
|
||||
OrderTipAmount = :tipAmount,
|
||||
OrderPayfritFee = :payfritFee,
|
||||
OrderCardFee = :cardFee,
|
||||
OrderTotalCharged = :totalCharged
|
||||
WHERE OrderID = :orderID
|
||||
", {
|
||||
paymentIntentID: piData.id,
|
||||
tipAmount: tip,
|
||||
payfritFee: payfritCustomerFee + payfritBusinessFee,
|
||||
cardFee: cardFee,
|
||||
totalCharged: totalCustomerPays,
|
||||
orderID: orderID
|
||||
}, { datasource: "payfrit" });
|
||||
// Fees are calculated dynamically, not stored in DB
|
||||
|
||||
response["OK"] = true;
|
||||
response["CLIENT_SECRET"] = piData.client_secret;
|
||||
|
|
|
|||
156
api/tasks/getDetails.cfm
Normal file
156
api/tasks/getDetails.cfm
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
<cfsetting showdebugoutput="false">
|
||||
<cfsetting enablecfoutputonly="true">
|
||||
|
||||
<cffunction name="apiAbort" access="public" returntype="void" output="true">
|
||||
<cfargument name="payload" type="struct" required="true">
|
||||
<cfcontent type="application/json; charset=utf-8">
|
||||
<cfoutput>#serializeJSON(arguments.payload)#</cfoutput>
|
||||
<cfabort>
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="readJsonBody" access="public" returntype="struct" output="false">
|
||||
<cfset var raw = getHttpRequestData().content>
|
||||
<cfif isNull(raw) OR len(trim(raw)) EQ 0>
|
||||
<cfreturn {}>
|
||||
</cfif>
|
||||
<cftry>
|
||||
<cfset var data = deserializeJSON(raw)>
|
||||
<cfif isStruct(data)>
|
||||
<cfreturn data>
|
||||
<cfelse>
|
||||
<cfreturn {}>
|
||||
</cfif>
|
||||
<cfcatch>
|
||||
<cfreturn {}>
|
||||
</cfcatch>
|
||||
</cftry>
|
||||
</cffunction>
|
||||
|
||||
<cfset data = readJsonBody()>
|
||||
<cfset TaskID = val( structKeyExists(data,"TaskID") ? data.TaskID : 0 )>
|
||||
|
||||
<cfif TaskID LTE 0>
|
||||
<cfset apiAbort({ "OK": false, "ERROR": "missing_params", "MESSAGE": "TaskID is required." })>
|
||||
</cfif>
|
||||
|
||||
<cftry>
|
||||
<!--- Get the task and linked order details --->
|
||||
<cfset qTask = queryExecute("
|
||||
SELECT
|
||||
t.TaskID,
|
||||
t.TaskBusinessID,
|
||||
t.TaskCategoryID,
|
||||
t.TaskOrderID,
|
||||
t.TaskTypeID,
|
||||
t.TaskAddedOn,
|
||||
t.TaskClaimedByUserID,
|
||||
tc.TaskCategoryName,
|
||||
tc.TaskCategoryColor,
|
||||
o.OrderID,
|
||||
o.OrderUUID,
|
||||
o.OrderUserID,
|
||||
o.OrderTypeID,
|
||||
o.OrderStatusID,
|
||||
o.OrderServicePointID,
|
||||
o.OrderRemarks,
|
||||
o.OrderSubmittedOn,
|
||||
sp.ServicePointName,
|
||||
sp.ServicePointTypeID,
|
||||
u.UserID as CustomerUserID,
|
||||
u.UserFirstName,
|
||||
u.UserLastName
|
||||
FROM Tasks t
|
||||
LEFT JOIN TaskCategories tc ON tc.TaskCategoryID = t.TaskCategoryID
|
||||
LEFT JOIN Orders o ON o.OrderID = t.TaskOrderID
|
||||
LEFT JOIN ServicePoints sp ON sp.ServicePointID = o.OrderServicePointID
|
||||
LEFT JOIN Users u ON u.UserID = o.OrderUserID
|
||||
WHERE t.TaskID = ?
|
||||
", [ { value = TaskID, cfsqltype = "cf_sql_integer" } ], { datasource = "payfrit" })>
|
||||
|
||||
<cfif qTask.recordCount EQ 0>
|
||||
<cfset apiAbort({ "OK": false, "ERROR": "not_found", "MESSAGE": "Task not found." })>
|
||||
</cfif>
|
||||
|
||||
<!--- Build basic task info --->
|
||||
<cfset taskTitle = "Task ##" & qTask.TaskID>
|
||||
<cfif qTask.TaskOrderID GT 0>
|
||||
<cfset taskTitle = "Order ##" & qTask.TaskOrderID>
|
||||
</cfif>
|
||||
|
||||
<cfset result = {
|
||||
"TaskID": qTask.TaskID,
|
||||
"TaskBusinessID": qTask.TaskBusinessID,
|
||||
"TaskCategoryID": qTask.TaskCategoryID,
|
||||
"TaskTitle": taskTitle,
|
||||
"TaskCreatedOn": dateFormat(qTask.TaskAddedOn, "yyyy-mm-dd") & "T" & timeFormat(qTask.TaskAddedOn, "HH:mm:ss"),
|
||||
"TaskStatusID": qTask.TaskClaimedByUserID GT 0 ? 1 : 0,
|
||||
"TaskCategoryName": len(trim(qTask.TaskCategoryName)) ? qTask.TaskCategoryName : "General",
|
||||
"TaskCategoryColor": len(trim(qTask.TaskCategoryColor)) ? qTask.TaskCategoryColor : "##888888",
|
||||
"OrderID": qTask.OrderID ?: 0,
|
||||
"OrderRemarks": qTask.OrderRemarks ?: "",
|
||||
"OrderSubmittedOn": isDate(qTask.OrderSubmittedOn) ? (dateFormat(qTask.OrderSubmittedOn, "yyyy-mm-dd") & "T" & timeFormat(qTask.OrderSubmittedOn, "HH:mm:ss")) : "",
|
||||
"ServicePointID": qTask.OrderServicePointID ?: 0,
|
||||
"ServicePointName": qTask.ServicePointName ?: "",
|
||||
"ServicePointTypeID": qTask.ServicePointTypeID ?: 0,
|
||||
"DeliveryAddress": "",
|
||||
"DeliveryLat": 0,
|
||||
"DeliveryLng": 0,
|
||||
"CustomerUserID": qTask.CustomerUserID ?: 0,
|
||||
"CustomerFirstName": qTask.UserFirstName ?: "",
|
||||
"CustomerLastName": qTask.UserLastName ?: "",
|
||||
"CustomerPhone": "",
|
||||
"CustomerPhotoUrl": qTask.CustomerUserID GT 0 ? "https://biz.payfrit.com/uploads/users/" & qTask.CustomerUserID & ".jpg" : "",
|
||||
"LineItems": []
|
||||
}>
|
||||
|
||||
<!--- Get order line items if there's an order --->
|
||||
<cfif qTask.OrderID GT 0>
|
||||
<cfset qLineItems = queryExecute("
|
||||
SELECT
|
||||
oli.OrderLineItemID,
|
||||
oli.OrderLineItemParentOrderLineItemID,
|
||||
oli.OrderLineItemItemID,
|
||||
oli.OrderLineItemPrice,
|
||||
oli.OrderLineItemQuantity,
|
||||
oli.OrderLineItemRemark,
|
||||
i.ItemID,
|
||||
i.ItemName,
|
||||
i.ItemParentItemID,
|
||||
i.ItemPrice,
|
||||
i.ItemIsCheckedByDefault
|
||||
FROM OrderLineItems oli
|
||||
INNER JOIN Items i ON i.ItemID = oli.OrderLineItemItemID
|
||||
WHERE oli.OrderLineItemOrderID = ?
|
||||
AND oli.OrderLineItemIsDeleted = b'0'
|
||||
ORDER BY oli.OrderLineItemID
|
||||
", [ { value = qTask.OrderID, cfsqltype = "cf_sql_integer" } ], { datasource = "payfrit" })>
|
||||
|
||||
<cfloop query="qLineItems">
|
||||
<cfset arrayAppend(result.LineItems, {
|
||||
"LineItemID": qLineItems.OrderLineItemID,
|
||||
"ParentLineItemID": qLineItems.OrderLineItemParentOrderLineItemID,
|
||||
"ItemID": qLineItems.OrderLineItemItemID,
|
||||
"ItemName": qLineItems.ItemName,
|
||||
"ItemPrice": qLineItems.OrderLineItemPrice,
|
||||
"Quantity": qLineItems.OrderLineItemQuantity,
|
||||
"Remark": qLineItems.OrderLineItemRemark,
|
||||
"IsModifier": qLineItems.ItemParentItemID GT 0
|
||||
})>
|
||||
</cfloop>
|
||||
</cfif>
|
||||
|
||||
<cfset apiAbort({
|
||||
"OK": true,
|
||||
"ERROR": "",
|
||||
"TASK": result
|
||||
})>
|
||||
|
||||
<cfcatch>
|
||||
<cfset apiAbort({
|
||||
"OK": false,
|
||||
"ERROR": "server_error",
|
||||
"MESSAGE": "Error loading task details",
|
||||
"DETAIL": cfcatch.message
|
||||
})>
|
||||
</cfcatch>
|
||||
</cftry>
|
||||
Loading…
Add table
Reference in a new issue