payfrit-works/api/addresses/list.cfm
John Mizerek d8d7efe056 Add user account APIs and fix Lucee header handling
- Add avatar.cfm: GET/POST for user profile photos with multi-extension support
- Add profile.cfm: GET/POST for user profile (name, email, phone)
- Add history.cfm: Order history endpoint with pagination
- Add addresses/list.cfm and add.cfm: Delivery address management
- Add setOrderType.cfm: Set delivery/takeaway type on orders
- Add checkToken.cfm: Debug endpoint for token validation
- Fix headerValue() in Application.cfm to use servlet request object
  (Lucee CGI scope doesn't expose custom HTTP headers like X-User-Token)
- Update public allowlist for new endpoints
- Add privacy.html page

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-08 20:01:07 -08:00

73 lines
2.4 KiB
Text

<cfsetting showdebugoutput="false">
<cfsetting enablecfoutputonly="true">
<cfcontent type="application/json; charset=utf-8">
<!--- List delivery addresses for the authenticated user --->
<cfscript>
try {
// Get authenticated user ID from request context (set by Application.cfm)
userId = request.UserID ?: 0;
if (userId <= 0) {
writeOutput(serializeJSON({
"OK": false,
"ERROR": "unauthorized",
"MESSAGE": "Authentication required"
}));
abort;
}
// Get user's delivery addresses (AddressTypeID contains "2" for delivery, BusinessID is 0 or NULL for personal)
qAddresses = queryExecute("
SELECT
a.AddressID,
a.AddressLabel,
a.AddressIsDefaultDelivery,
a.AddressLine1,
a.AddressLine2,
a.AddressCity,
a.AddressStateID,
s.StateAbbreviation,
s.StateName,
a.AddressZIPCode
FROM Addresses a
LEFT JOIN States s ON a.AddressStateID = s.StateID
WHERE a.AddressUserID = :userId
AND (a.AddressBusinessID = 0 OR a.AddressBusinessID IS NULL)
AND a.AddressTypeID LIKE '%2%'
AND a.AddressIsDeleted = 0
ORDER BY a.AddressIsDefaultDelivery DESC, a.AddressID DESC
", {
userId: { value: userId, cfsqltype: "cf_sql_integer" }
}, { datasource: "payfrit" });
addresses = [];
for (row in qAddresses) {
arrayAppend(addresses, {
"AddressID": row.AddressID,
"Label": len(row.AddressLabel) ? row.AddressLabel : "Address",
"IsDefault": row.AddressIsDefaultDelivery == 1,
"Line1": row.AddressLine1,
"Line2": row.AddressLine2 ?: "",
"City": row.AddressCity,
"StateID": row.AddressStateID,
"StateAbbr": row.StateAbbreviation ?: "",
"StateName": row.StateName ?: "",
"ZIPCode": row.AddressZIPCode,
"DisplayText": row.AddressLine1 & (len(row.AddressLine2) ? ", " & row.AddressLine2 : "") & ", " & row.AddressCity & ", " & (row.StateAbbreviation ?: "") & " " & row.AddressZIPCode
});
}
writeOutput(serializeJSON({
"OK": true,
"ADDRESSES": addresses
}));
} catch (any e) {
writeOutput(serializeJSON({
"OK": false,
"ERROR": "server_error",
"MESSAGE": e.message
}));
}
</cfscript>