82 lines
2.3 KiB
Text
82 lines
2.3 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>
|
|
function apiAbort(obj) {
|
|
writeOutput(serializeJSON(obj));
|
|
abort;
|
|
}
|
|
|
|
function readJsonBody() {
|
|
raw = toString(getHttpRequestData().content);
|
|
if (isNull(raw) || len(trim(raw)) EQ 0) return {};
|
|
try {
|
|
parsed = deserializeJSON(raw);
|
|
} catch(any e) {
|
|
apiAbort({ OK=false, ERROR="bad_json", MESSAGE="Invalid JSON body" });
|
|
}
|
|
if (!isStruct(parsed)) return {};
|
|
return parsed;
|
|
}
|
|
|
|
data = readJsonBody();
|
|
|
|
if (!structKeyExists(request, "UserID") || !isNumeric(request.UserID) || request.UserID LTE 0) {
|
|
apiAbort({ OK=false, ERROR="not_logged_in" });
|
|
}
|
|
if (!structKeyExists(request, "BusinessID") || !isNumeric(request.BusinessID) || request.BusinessID LTE 0) {
|
|
apiAbort({ OK=false, ERROR="no_business_selected" });
|
|
}
|
|
|
|
onlyActive = true;
|
|
if (structKeyExists(data, "onlyActive")) {
|
|
if (isBoolean(data.onlyActive)) {
|
|
onlyActive = data.onlyActive;
|
|
} else if (isNumeric(data.onlyActive)) {
|
|
onlyActive = (int(data.onlyActive) EQ 1);
|
|
} else if (isSimpleValue(data.onlyActive)) {
|
|
onlyActive = (lcase(trim(toString(data.onlyActive))) EQ "true");
|
|
}
|
|
}
|
|
</cfscript>
|
|
|
|
<cfquery name="q" datasource="#application.datasource#">
|
|
SELECT
|
|
ServicePointID,
|
|
BusinessID,
|
|
ServicePointName,
|
|
ServicePointTypeID,
|
|
ServicePointCode,
|
|
Description,
|
|
SortOrder,
|
|
IsActive,
|
|
CreatedAt,
|
|
UpdatedAt
|
|
FROM ServicePoints
|
|
WHERE BusinessID = <cfqueryparam cfsqltype="cf_sql_integer" value="#request.BusinessID#">
|
|
<cfif onlyActive>
|
|
AND IsActive = 1
|
|
</cfif>
|
|
ORDER BY SortOrder, ServicePointName, ServicePointID
|
|
</cfquery>
|
|
|
|
<cfset sps = []>
|
|
<cfloop query="q">
|
|
<cfset arrayAppend(sps, {
|
|
"ServicePointID"=q.ServicePointID,
|
|
"BusinessID"=q.BusinessID,
|
|
"ServicePointName"=q.ServicePointName,
|
|
"ServicePointTypeID"=q.ServicePointTypeID,
|
|
"ServicePointCode"=q.ServicePointCode,
|
|
"Description"=q.Description,
|
|
"SortOrder"=q.SortOrder,
|
|
"IsActive"=q.IsActive,
|
|
"CreatedAt"=(q.CreatedAt & ""),
|
|
"UpdatedAt"=(q.UpdatedAt & "")
|
|
})>
|
|
</cfloop>
|
|
|
|
<cfoutput>#serializeJSON({ OK=true, ERROR="", BUSINESSID=(request.BusinessID & ""), COUNT=arrayLen(sps), SERVICEPOINTS=sps })#</cfoutput>
|