#!/usr/bin/env python3 # -*- coding: utf-8 -*- """List approval instances""" import json result = {'success': False, 'rows': [], 'total': 0} try: dbname = get_module_dbname('workflow_approval') ns = { 'page': int(params_kw.get('page', 1)), 'rows': int(params_kw.get('rows', 20)), 'sort': 'id' } sql = """ SELECT ai.id, ai.workflow_id, aw.name as workflow_name, ai.business_type as module_type, ai.business_id as module_record_id, ai.current_step as current_step_id, ai.status, ai.initiator_id, ai.org_id, ai.initiated_at as created_at, ai.completed_at FROM approval_instance ai LEFT JOIN approval_workflow aw ON ai.workflow_id = aw.id """ async with DBPools().sqlorContext(dbname) as sor: data = await sor.sqlExe(sql, ns) if isinstance(data, dict): result['total'] = data.get('total', 0) result['rows'] = [dict(r) for r in data.get('rows', [])] else: result['rows'] = [dict(r) for r in (data or [])] result['total'] = len(result['rows']) result['success'] = True except Exception as e: result['error'] = str(e) return json.dumps(result, ensure_ascii=False, default=str)