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/_scripts/debugEmployees.cfm
John 16a3b7c9a3 Replace queryExecute with queryTimed across all endpoints for perf tracking
Converts 200+ endpoint files to use queryTimed() wrapper which tracks
DB query count and execution time. Restores perf dashboard files that
were accidentally moved to _scripts/. Includes portal UI updates.
2026-02-02 00:28:37 -08:00

95 lines
2.6 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) {}
// If Phone provided, look up user and their employee records
if (structKeyExists(data, "Phone") && len(data.Phone)) {
phone = reReplace(data.Phone, "[^0-9]", "", "all");
qUser = queryTimed("
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;
qEmployees = queryTimed("
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
}));
abort;
}
// Original behavior - list employees by BusinessID
businessId = structKeyExists(data, "BusinessID") ? val(data.BusinessID) : 17;
q = queryTimed("
SELECT ID, UserID, StatusID, IsActive,
CAST(IsActive AS UNSIGNED) AS IsActiveInt
FROM Employees
WHERE BusinessID = ?
", [{ value: businessId, cfsqltype: "cf_sql_integer" }], { datasource: "payfrit" });
rows = [];
for (r in q) {
arrayAppend(rows, {
"EmployeeID": r.ID,
"UserID": r.UserID,
"StatusID": r.StatusID,
"RawIsActive": r.IsActive,
"CastIsActive": r.IsActiveInt,
"ValRaw": val(r.IsActive),
"ValCast": val(r.IsActiveInt),
"EqRaw1": r.IsActive == 1,
"EqCast1": r.IsActiveInt == 1
});
}
writeOutput(serializeJSON({
"OK": true,
"ROWS": rows
}));
</cfscript>