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/admin/debugUserByPhone.cfm
John Mizerek 78035e9cf6 Fix remaining prefixed DB column names across 17 API files
Hours: HoursBusinessID/HoursDayID/HoursOpenTime/HoursClosingTime -> BusinessID/DayID/OpenTime/ClosingTime
ServicePoints: ServicePointID/ServicePointName/ServicePointBusinessID -> ID/Name/BusinessID
Users: UserFirstName/UserLastName/UserEmailAddress/UserContactNumber -> FirstName/LastName/EmailAddress/ContactNumber
Orders: BusinessDeliveryMultiplier -> DeliveryMultiplier (column renamed in dev DB)
Businesses: BusinessParentBusinessID -> ParentBusinessID
tt_Days: tt_DayID/tt_DayName -> ID/Name

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

70 lines
1.8 KiB
Text

<cfsetting showdebugoutput="false">
<cfsetting enablecfoutputonly="true">
<cfcontent type="application/json; charset=utf-8" reset="true">
<cfscript>
data = {};
try {
requestBody = toString(getHttpRequestData().content);
if (len(requestBody)) data = deserializeJSON(requestBody);
} catch (any e) {}
phone = structKeyExists(data, "Phone") ? data.Phone : "";
// Strip non-digits
phone = reReplace(phone, "[^0-9]", "", "all");
if (len(phone) == 0) {
writeOutput(serializeJSON({ "OK": false, "ERROR": "missing_phone" }));
abort;
}
// Find user by phone
qUser = queryExecute("
SELECT ID, FirstName, LastName, EmailAddress, ContactNumber
FROM Users
WHERE REPLACE(REPLACE(REPLACE(ContactNumber, '-', ''), '(', ''), ')', '') LIKE ?
OR ContactNumber LIKE ?
", [
{ value: "%" & phone & "%", cfsqltype: "cf_sql_varchar" },
{ value: "%" & phone & "%", cfsqltype: "cf_sql_varchar" }
], { datasource: "payfrit" });
if (qUser.recordCount == 0) {
writeOutput(serializeJSON({ "OK": false, "ERROR": "user_not_found", "PHONE": phone }));
abort;
}
userId = qUser.ID;
// Get all employee records for this user
qEmployees = queryExecute("
SELECT e.ID, e.BusinessID, e.StatusID,
CAST(e.IsActive AS UNSIGNED) AS IsActive,
b.Name
FROM Employees e
JOIN Businesses b ON e.BusinessID = b.ID
WHERE e.UserID = ?
", [{ value: userId, cfsqltype: "cf_sql_integer" }], { datasource: "payfrit" });
employees = [];
for (row in qEmployees) {
arrayAppend(employees, {
"EmployeeID": row.ID,
"BusinessID": row.BusinessID,
"Name": row.Name,
"StatusID": row.StatusID,
"IsActive": row.IsActive
});
}
writeOutput(serializeJSON({
"OK": true,
"USER": {
"UserID": qUser.ID,
"Name": trim(qUser.FirstName & " " & qUser.LastName),
"Email": qUser.EmailAddress,
"Phone": qUser.ContactNumber
},
"EMPLOYEES": employees
}));
</cfscript>