diff --git a/models/intermediate/resolutions/int_resolutions__incidents.sql b/models/intermediate/resolutions/int_resolutions__incidents.sql index 5555c05..99912bf 100644 --- a/models/intermediate/resolutions/int_resolutions__incidents.sql +++ b/models/intermediate/resolutions/int_resolutions__incidents.sql @@ -1,11 +1,28 @@ with stg_resolutions__incidents as ( select * from {{ ref("stg_resolutions__incidents") }} + ), + comments_timeline as ( + select + i.id_incident, + ( + select (comment ->> 'CreatedDate')::timestamp + from jsonb_array_elements(i.comment_logs::jsonb) comment + order by (comment ->> 'CreatedDate')::timestamp + limit 1 + ) as first_comment_date, + ( + select (comment ->> 'CreatedDate')::timestamp + from jsonb_array_elements(i.comment_logs::jsonb) comment + order by (comment ->> 'CreatedDate')::timestamp desc + limit 1 + ) as last_comment_date + from stg_resolutions__incidents i ) select -- Basic Incident Details - id_incident, + i.id_incident, id_user, id_verification, current_status_name, @@ -20,6 +37,10 @@ select updated_at_date, updated_date_date, + -- Resolution Details + first_comment_date, + last_comment_date, + -- Host Details id_user_host, host_user_claim_logs, @@ -69,7 +90,6 @@ select check_out_at_utc, check_out_date_utc, id_booking, - booking_status, id_reservation, booking_details, @@ -86,4 +106,19 @@ select has_confirmed_loss, damage_report_items, -from raw_incident + -- Calculator + protection_name, + was_overriden, + waiver_or_deposit_name, + guest_verification_status, + lower_protection_limit_usd, + upper_protection_limit_usd, + calculated_payout_amount_in_txn_currency, + calculated_payout_currency, + calculated_payout_amount_in_usd, + calculated_guest_charge_amount_in_txn_currency, + calculated_guest_charge_currency, + calculated_guest_charge_amount_in_usd + +from stg_resolutions__incidents i +left join comments_timeline ct on i.id_incident = ct.id_incident