<cfsetting showdebugoutput="false">
<cfcontent type="application/json; charset=utf-8">
<cfscript>
// Close all open chat tasks
try {
    result = queryExecute("
        UPDATE Tasks
        SET CompletedOn = NOW()
        WHERE TaskTypeID = 2
          AND CompletedOn IS NULL
    ", {}, { datasource: "payfrit" });

    affected = result.recordCount ?: 0;

    writeOutput(serializeJSON({
        "OK": true,
        "MESSAGE": "Closed all open chats",
        "AFFECTED": affected
    }));
} catch (any e) {
    writeOutput(serializeJSON({
        "OK": false,
        "ERROR": e.message
    }));
}
</cfscript>
