Simplify address API - delivery addresses only
- Remove TypeID/Label from list response - Hardcode TypeID=2 (delivery) in add endpoint - Filter to personal addresses only (BusinessID=0 or NULL) - Just IsDefault flag, no home/work labels Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
6d5620d513
commit
400df7624f
2 changed files with 8 additions and 12 deletions
|
|
@ -31,7 +31,6 @@ try {
|
|||
data = readJsonBody();
|
||||
|
||||
// Required fields
|
||||
typeId = val(data.TypeID ?: 0);
|
||||
line1 = trim(data.Line1 ?: "");
|
||||
city = trim(data.City ?: "");
|
||||
stateId = val(data.StateID ?: 0);
|
||||
|
|
@ -39,15 +38,17 @@ try {
|
|||
|
||||
// Optional fields
|
||||
line2 = trim(data.Line2 ?: "");
|
||||
label = trim(data.Label ?: "");
|
||||
setAsDefault = (data.SetAsDefault ?: false) == true;
|
||||
|
||||
// Hardcoded to delivery address type
|
||||
typeId = 2;
|
||||
|
||||
// Validation
|
||||
if (typeId <= 0 || len(line1) == 0 || len(city) == 0 || stateId <= 0 || len(zipCode) == 0) {
|
||||
if (len(line1) == 0 || len(city) == 0 || stateId <= 0 || len(zipCode) == 0) {
|
||||
writeOutput(serializeJSON({
|
||||
"OK": false,
|
||||
"ERROR": "missing_fields",
|
||||
"MESSAGE": "TypeID, Line1, City, StateID, and ZIPCode are required"
|
||||
"MESSAGE": "Line1, City, StateID, and ZIPCode are required"
|
||||
}));
|
||||
abort;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,12 +46,10 @@ if (userId <= 0) {
|
|||
}
|
||||
|
||||
try {
|
||||
// Get user's addresses
|
||||
// Get user's delivery addresses
|
||||
qAddresses = queryExecute("
|
||||
SELECT
|
||||
a.AddressID,
|
||||
a.AddressLabel,
|
||||
a.AddressTypeID,
|
||||
a.AddressIsDefaultDelivery,
|
||||
a.AddressLine1,
|
||||
a.AddressLine2,
|
||||
|
|
@ -64,6 +62,7 @@ try {
|
|||
LEFT JOIN tt_States s ON a.AddressStateID = s.tt_StateID
|
||||
WHERE a.AddressUserID = :userId
|
||||
AND (a.AddressBusinessID = 0 OR a.AddressBusinessID IS NULL)
|
||||
AND a.AddressTypeID = 2
|
||||
AND a.AddressIsDeleted = 0
|
||||
ORDER BY a.AddressIsDefaultDelivery DESC, a.AddressID DESC
|
||||
", {
|
||||
|
|
@ -74,15 +73,12 @@ try {
|
|||
for (row in qAddresses) {
|
||||
arrayAppend(addresses, {
|
||||
"AddressID": row.AddressID,
|
||||
"TypeID": val(row.AddressTypeID),
|
||||
"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
|
||||
});
|
||||
|
|
@ -97,8 +93,7 @@ try {
|
|||
apiAbort({
|
||||
"OK": false,
|
||||
"ERROR": "server_error",
|
||||
"MESSAGE": e.message,
|
||||
"LINE": e.tagContext[1].line ?: 0
|
||||
"MESSAGE": e.message
|
||||
});
|
||||
}
|
||||
</cfscript>
|
||||
|
|
|
|||
Reference in a new issue