feat(MED-86): user can see in Medusa BO if sending order to medipost succeeded

This commit is contained in:
2025-08-28 14:42:07 +03:00
parent b3505c1627
commit da7f574234
2 changed files with 25 additions and 0 deletions

View File

@@ -2118,6 +2118,15 @@ export type Database = {
success: boolean
}
}
get_latest_medipost_dispatch_state_for_order: {
Args: {
medusa_order_id: string
}
Returns: {
has_success: boolean
action_date: string
}
}
}
Enums: {
analysis_feedback_status: "STARTED" | "DRAFT" | "COMPLETED"

View File

@@ -0,0 +1,16 @@
CREATE OR REPLACE FUNCTION medreport.get_latest_medipost_dispatch_state_for_order(medusa_order_id text)
RETURNS TABLE(has_success boolean, action_date timestamp with time zone) AS $$
SELECT
CASE
WHEN ma.has_error = false THEN true
ELSE false
END as has_success,
ma.created_at as action_date
FROM medreport.medipost_actions ma
WHERE ma.medusa_order_id = $1
AND ma.action = 'send_order_to_medipost'
ORDER BY ma.created_at DESC
LIMIT 1;
$$ LANGUAGE sql STABLE;
grant execute on function medreport.get_latest_medipost_dispatch_state_for_order(text) to service_role;