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();
|
data = readJsonBody();
|
||||||
|
|
||||||
// Required fields
|
// Required fields
|
||||||
typeId = val(data.TypeID ?: 0);
|
|
||||||
line1 = trim(data.Line1 ?: "");
|
line1 = trim(data.Line1 ?: "");
|
||||||
city = trim(data.City ?: "");
|
city = trim(data.City ?: "");
|
||||||
stateId = val(data.StateID ?: 0);
|
stateId = val(data.StateID ?: 0);
|
||||||
|
|
@ -39,15 +38,17 @@ try {
|
||||||
|
|
||||||
// Optional fields
|
// Optional fields
|
||||||
line2 = trim(data.Line2 ?: "");
|
line2 = trim(data.Line2 ?: "");
|
||||||
label = trim(data.Label ?: "");
|
|
||||||
setAsDefault = (data.SetAsDefault ?: false) == true;
|
setAsDefault = (data.SetAsDefault ?: false) == true;
|
||||||
|
|
||||||
|
// Hardcoded to delivery address type
|
||||||
|
typeId = 2;
|
||||||
|
|
||||||
// Validation
|
// 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({
|
writeOutput(serializeJSON({
|
||||||
"OK": false,
|
"OK": false,
|
||||||
"ERROR": "missing_fields",
|
"ERROR": "missing_fields",
|
||||||
"MESSAGE": "TypeID, Line1, City, StateID, and ZIPCode are required"
|
"MESSAGE": "Line1, City, StateID, and ZIPCode are required"
|
||||||
}));
|
}));
|
||||||
abort;
|
abort;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,12 +46,10 @@ if (userId <= 0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get user's addresses
|
// Get user's delivery addresses
|
||||||
qAddresses = queryExecute("
|
qAddresses = queryExecute("
|
||||||
SELECT
|
SELECT
|
||||||
a.AddressID,
|
a.AddressID,
|
||||||
a.AddressLabel,
|
|
||||||
a.AddressTypeID,
|
|
||||||
a.AddressIsDefaultDelivery,
|
a.AddressIsDefaultDelivery,
|
||||||
a.AddressLine1,
|
a.AddressLine1,
|
||||||
a.AddressLine2,
|
a.AddressLine2,
|
||||||
|
|
@ -64,6 +62,7 @@ try {
|
||||||
LEFT JOIN tt_States s ON a.AddressStateID = s.tt_StateID
|
LEFT JOIN tt_States s ON a.AddressStateID = s.tt_StateID
|
||||||
WHERE a.AddressUserID = :userId
|
WHERE a.AddressUserID = :userId
|
||||||
AND (a.AddressBusinessID = 0 OR a.AddressBusinessID IS NULL)
|
AND (a.AddressBusinessID = 0 OR a.AddressBusinessID IS NULL)
|
||||||
|
AND a.AddressTypeID = 2
|
||||||
AND a.AddressIsDeleted = 0
|
AND a.AddressIsDeleted = 0
|
||||||
ORDER BY a.AddressIsDefaultDelivery DESC, a.AddressID DESC
|
ORDER BY a.AddressIsDefaultDelivery DESC, a.AddressID DESC
|
||||||
", {
|
", {
|
||||||
|
|
@ -74,15 +73,12 @@ try {
|
||||||
for (row in qAddresses) {
|
for (row in qAddresses) {
|
||||||
arrayAppend(addresses, {
|
arrayAppend(addresses, {
|
||||||
"AddressID": row.AddressID,
|
"AddressID": row.AddressID,
|
||||||
"TypeID": val(row.AddressTypeID),
|
|
||||||
"Label": len(row.AddressLabel) ? row.AddressLabel : "Address",
|
|
||||||
"IsDefault": row.AddressIsDefaultDelivery == 1,
|
"IsDefault": row.AddressIsDefaultDelivery == 1,
|
||||||
"Line1": row.AddressLine1,
|
"Line1": row.AddressLine1,
|
||||||
"Line2": row.AddressLine2 ?: "",
|
"Line2": row.AddressLine2 ?: "",
|
||||||
"City": row.AddressCity,
|
"City": row.AddressCity,
|
||||||
"StateID": row.AddressStateID,
|
"StateID": row.AddressStateID,
|
||||||
"StateAbbr": row.StateAbbreviation ?: "",
|
"StateAbbr": row.StateAbbreviation ?: "",
|
||||||
"StateName": row.StateName ?: "",
|
|
||||||
"ZIPCode": row.AddressZIPCode,
|
"ZIPCode": row.AddressZIPCode,
|
||||||
"DisplayText": row.AddressLine1 & (len(row.AddressLine2) ? ", " & row.AddressLine2 : "") & ", " & row.AddressCity & ", " & (row.StateAbbreviation ?: "") & " " & row.AddressZIPCode
|
"DisplayText": row.AddressLine1 & (len(row.AddressLine2) ? ", " & row.AddressLine2 : "") & ", " & row.AddressCity & ", " & (row.StateAbbreviation ?: "") & " " & row.AddressZIPCode
|
||||||
});
|
});
|
||||||
|
|
@ -97,8 +93,7 @@ try {
|
||||||
apiAbort({
|
apiAbort({
|
||||||
"OK": false,
|
"OK": false,
|
||||||
"ERROR": "server_error",
|
"ERROR": "server_error",
|
||||||
"MESSAGE": e.message,
|
"MESSAGE": e.message
|
||||||
"LINE": e.tagContext[1].line ?: 0
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
</cfscript>
|
</cfscript>
|
||||||
|
|
|
||||||
Reference in a new issue