fix(calendar): add type guards and debug logging for get_events SQL error
- Added debug prints to log params type in get_events - Added type guard in backward compat path (reject non-string end_date) - Added type guard for start_date/end_date before passing to SQL
This commit is contained in:
parent
d6e28d7b1f
commit
a202c5d079
|
|
@ -144,12 +144,24 @@ end
|
||||||
|
|
||||||
-- Get events within a date range (inclusive)
|
-- Get events within a date range (inclusive)
|
||||||
function M.get_events(params, end_date)
|
function M.get_events(params, end_date)
|
||||||
|
-- Debug: log what we received
|
||||||
|
print("get_events: params type=" .. type(params) .. ", end_date type=" .. type(end_date))
|
||||||
|
if type(params) == "table" then
|
||||||
|
for k, v in pairs(params) do
|
||||||
|
print(" params[" .. tostring(k) .. "] type=" .. type(v))
|
||||||
|
end
|
||||||
|
end
|
||||||
-- Backward compat: support positional (start, end) and table {start=, end=}
|
-- Backward compat: support positional (start, end) and table {start=, end=}
|
||||||
if type(params) == "string" then
|
if type(params) == "string" then
|
||||||
return M.get_events{ start_date = params, ["end"] = end_date or params }
|
print("get_events: backward compat path, end_date=" .. tostring(end_date))
|
||||||
|
local e = end_date
|
||||||
|
if type(e) ~= "string" then e = nil end
|
||||||
|
return M.get_events{ start_date = params, ["end"] = e or params }
|
||||||
end
|
end
|
||||||
local start_date = params.start_date or params.start
|
local start_date = params.start_date or params.start
|
||||||
|
if type(start_date) ~= "string" then print("WARN get_events start_date not string: " .. type(start_date)); start_date = tostring(start_date) end
|
||||||
local end_date = params["end"] or params.end_date or params.end_date
|
local end_date = params["end"] or params.end_date or params.end_date
|
||||||
|
if type(end_date) ~= "string" then print("WARN get_events end_date not string: " .. type(end_date)); end_date = start_date end
|
||||||
if not start_date then error("start_date required") end
|
if not start_date then error("start_date required") end
|
||||||
if not end_date then end_date = start_date end
|
if not end_date then end_date = start_date end
|
||||||
return verstak.db.query(
|
return verstak.db.query(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue