Updated all remaining SQL queries to use correct prefixed column names for ServicePoints, Users, Businesses, Addresses, tt_States, tt_Days, and Hours tables across 23 admin/infrastructure API files. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
76 lines
2 KiB
Text
76 lines
2 KiB
Text
<cfsetting showdebugoutput="false">
|
|
<cfsetting enablecfoutputonly="true">
|
|
<cfcontent type="application/json; charset=utf-8">
|
|
|
|
<cffunction name="readJsonBody" access="public" returntype="struct" output="false">
|
|
<cfset var raw = getHttpRequestData().content>
|
|
<cfif isNull(raw) OR len(trim(raw)) EQ 0>
|
|
<cfreturn {}>
|
|
</cfif>
|
|
<cftry>
|
|
<cfset var data = deserializeJSON(raw)>
|
|
<cfif isStruct(data)>
|
|
<cfreturn data>
|
|
<cfelse>
|
|
<cfreturn {}>
|
|
</cfif>
|
|
<cfcatch>
|
|
<cfreturn {}>
|
|
</cfcatch>
|
|
</cftry>
|
|
</cffunction>
|
|
|
|
<cfset data = readJsonBody()>
|
|
<cfset UserID = val( structKeyExists(data,"UserID") ? data.UserID : 0 )>
|
|
|
|
<cftry>
|
|
<!--- Get raw employee records --- >
|
|
<cfset qEmployees = queryExecute("
|
|
SELECT e.*, b.BusinessName AS Name
|
|
FROM Employees e
|
|
INNER JOIN Businesses b ON b.BusinessID = e.BusinessID
|
|
WHERE e.UserID = ?
|
|
ORDER BY b.Name ASC
|
|
", [ { value = UserID, cfsqltype = "cf_sql_integer" } ], { datasource = "payfrit" })>
|
|
|
|
<cfset employees = []>
|
|
<cfloop query="qEmployees">
|
|
<cfset arrayAppend(employees, {
|
|
"EmployeeID": qEmployees.ID,
|
|
"UserID": qEmployees.UserID,
|
|
"BusinessID": qEmployees.BusinessID,
|
|
"Name": qEmployees.Name,
|
|
"IsActive": qEmployees.IsActive
|
|
})>
|
|
</cfloop>
|
|
|
|
<!--- Check for duplicate businesses --- >
|
|
<cfset qDuplicates = queryExecute("
|
|
SELECT BusinessName AS Name, COUNT(*) AS cnt
|
|
FROM Businesses
|
|
GROUP BY BusinessName
|
|
HAVING COUNT(*) > 1
|
|
", [], { datasource = "payfrit" })>
|
|
|
|
<cfset duplicates = []>
|
|
<cfloop query="qDuplicates">
|
|
<cfset arrayAppend(duplicates, {
|
|
"Name": qDuplicates.Name,
|
|
"Count": qDuplicates.cnt
|
|
})>
|
|
</cfloop>
|
|
|
|
<cfoutput>#serializeJSON({
|
|
"OK": true,
|
|
"EMPLOYEE_COUNT": arrayLen(employees),
|
|
"EMPLOYEES": employees,
|
|
"DUPLICATE_BUSINESSES": duplicates
|
|
})#</cfoutput>
|
|
|
|
<cfcatch>
|
|
<cfoutput>#serializeJSON({
|
|
"OK": false,
|
|
"ERROR": cfcatch.message
|
|
})#</cfoutput>
|
|
</cfcatch>
|
|
</cftry>
|