This repository has been archived on 2026-03-21. You can view files and clone it, but cannot push or open issues or pull requests.
payfrit-biz/api/businesses/get.cfm
John Mizerek 1210249f54 Normalize database column and table names across entire codebase
Update all SQL queries, query result references, and ColdFusion code to match
the renamed database schema. Tables use plural CamelCase, PKs are all `ID`,
column prefixes stripped (e.g. BusinessName→Name, UserFirstName→FirstName).

Key changes:
- Strip table-name prefixes from all column references (Businesses, Users,
  Addresses, Hours, Menus, Categories, Items, Stations, Orders,
  OrderLineItems, Tasks, TaskCategories, TaskRatings, QuickTaskTemplates,
  ScheduledTaskDefinitions, ChatMessages, Beacons, ServicePoints, Employees,
  VisitorTrackings, ApiPerfLogs, tt_States, tt_Days, tt_AddressTypes,
  tt_OrderTypes, tt_TaskTypes)
- Rename PK references from {TableName}ID to ID in all queries
- Rewrite 7 admin beacon files to use ServicePoints.BeaconID instead of
  dropped lt_Beacon_Businesses_ServicePoints link table
- Rewrite beacon assignment files (list, save, delete) for new schema
- Fix FK references incorrectly changed to ID (OrderLineItems.OrderID,
  Categories.MenuID, Tasks.CategoryID, ServicePoints.BeaconID)
- Update Addresses: AddressLat→Latitude, AddressLng→Longitude
- Update Users: UserPassword→Password, UserIsEmailVerified→IsEmailVerified,
  UserIsActive→IsActive, UserBalance→Balance, etc.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 15:39:12 -08:00

160 lines
5.1 KiB
Text

<cfsetting showdebugoutput="false">
<cfsetting enablecfoutputonly="true">
<cfcontent type="application/json; charset=utf-8" reset="true">
<cfheader name="Cache-Control" value="no-store">
<cfscript>
/**
* Get Business Details
* POST: { BusinessID: int }
* Returns: { OK: true, BUSINESS: {...} } or { OK: false, ERROR: string }
*/
response = { "OK": false };
try {
// Get request data
requestBody = toString(getHttpRequestData().content);
if (len(requestBody) == 0) {
response["ERROR"] = "Request body is required";
writeOutput(serializeJSON(response));
abort;
}
requestData = deserializeJSON(requestBody);
businessID = val(requestData.BusinessID ?: 0);
if (businessID == 0) {
response["ERROR"] = "BusinessID is required";
writeOutput(serializeJSON(response));
abort;
}
// Get business details
q = queryExecute("
SELECT
ID,
Name,
Phone,
StripeAccountID,
StripeOnboardingComplete,
IsHiring,
HeaderImageExtension,
TaxRate,
BrandColor
FROM Businesses
WHERE ID = :businessID
", { businessID: businessID }, { datasource: "payfrit" });
if (q.recordCount == 0) {
response["ERROR"] = "Business not found";
writeOutput(serializeJSON(response));
abort;
}
// Get address from Addresses table (either linked via BusinessID or via Businesses.AddressID)
qAddr = queryExecute("
SELECT a.Line1, a.Line2, a.City, a.ZIPCode, s.Abbreviation
FROM Addresses a
LEFT JOIN tt_States s ON s.ID = a.StateID
WHERE (a.BusinessID = :businessID OR a.ID = (SELECT AddressID FROM Businesses WHERE ID = :businessID))
AND a.IsDeleted = 0
LIMIT 1
", { businessID: businessID }, { datasource: "payfrit" });
addressStr = "";
addressLine1 = "";
addressCity = "";
addressState = "";
addressZip = "";
if (qAddr.recordCount > 0) {
addressLine1 = qAddr.Line1;
addressCity = qAddr.City;
addressState = qAddr.Abbreviation;
addressZip = qAddr.ZIPCode;
addressParts = [];
if (len(qAddr.Line1)) arrayAppend(addressParts, qAddr.Line1);
if (len(qAddr.Line2)) arrayAppend(addressParts, qAddr.Line2);
cityStateZip = [];
if (len(qAddr.City)) arrayAppend(cityStateZip, qAddr.City);
if (len(qAddr.Abbreviation)) arrayAppend(cityStateZip, qAddr.Abbreviation);
if (len(qAddr.ZIPCode)) arrayAppend(cityStateZip, qAddr.ZIPCode);
if (arrayLen(cityStateZip) > 0) arrayAppend(addressParts, arrayToList(cityStateZip, ", "));
addressStr = arrayToList(addressParts, ", ");
}
// Get hours from Hours table
qHours = queryExecute("
SELECT h.DayID, h.OpenTime, h.ClosingTime, d.Abbrev
FROM Hours h
JOIN tt_Days d ON d.ID = h.DayID
WHERE h.BusinessID = :businessID
ORDER BY h.DayID
", { businessID: businessID }, { datasource: "payfrit" });
hoursArr = [];
hoursStr = "";
if (qHours.recordCount > 0) {
for (h in qHours) {
arrayAppend(hoursArr, {
"day": h.Abbrev,
"dayId": h.DayID,
"open": timeFormat(h.OpenTime, "h:mm tt"),
"close": timeFormat(h.ClosingTime, "h:mm tt")
});
}
// Build readable hours string (group similar days)
// Mon-Thu: 11am-10pm, Fri-Sat: 11am-11pm, Sun: 11am-10pm
hourGroups = {};
for (h in hoursArr) {
key = h.open & "-" & h.close;
if (!structKeyExists(hourGroups, key)) {
hourGroups[key] = [];
}
arrayAppend(hourGroups[key], h.day);
}
hourStrParts = [];
for (key in hourGroups) {
days = hourGroups[key];
arrayAppend(hourStrParts, arrayToList(days, ",") & ": " & key);
}
hoursStr = arrayToList(hourStrParts, ", ");
}
// Build business object
taxRate = isNumeric(q.TaxRate) ? q.TaxRate : 0;
business = {
"BusinessID": q.ID,
"Name": q.Name,
"Address": addressStr,
"Line1": addressLine1,
"City": addressCity,
"AddressState": addressState,
"AddressZip": addressZip,
"Phone": q.Phone,
"Hours": hoursStr,
"HoursDetail": hoursArr,
"StripeConnected": (len(q.StripeAccountID) > 0 && q.StripeOnboardingComplete == 1),
"IsHiring": q.IsHiring == 1,
"TaxRate": taxRate,
"TaxRatePercent": taxRate * 100,
"BrandColor": len(q.BrandColor) ? (left(q.BrandColor, 1) == chr(35) ? q.BrandColor : chr(35) & q.BrandColor) : ""
};
// Add header image URL if extension exists
if (len(q.HeaderImageExtension)) {
business["HeaderImageURL"] = "https://biz.payfrit.com/uploads/headers/" & q.ID & "." & q.HeaderImageExtension;
}
response["OK"] = true;
response["BUSINESS"] = business;
} catch (any e) {
response["ERROR"] = e.message;
}
writeOutput(serializeJSON(response));
</cfscript>