Merged PR 3827: S&P models update

# Description

Added the missing field `is_protected` to the S&P models that comes from the `apim_users` table
I also modified the `apim_users` so the json field is actually stored as a json

# Checklist

- [x] The edited models and dependants run properly with production data.
- [x] The edited models are sufficiently documented.
- [x] The edited models contain PK tests, and I've ran and passed them.
- [x] I have checked for DRY opportunities with other models and docs.
- [ ] I've picked the right materialization for the affected models.

# Other

- [ ] Check if a full-refresh is required after this PR is merged.

Related work items: #25243
This commit is contained in:
Joaquin Ossa 2024-12-11 15:59:11 +00:00
commit 8052581a3d
6 changed files with 75 additions and 46 deletions

View file

@ -1,50 +1,64 @@
{% set api_name = "SCREENANDPROTECTAPI" %}
with
stg_screen_and_protect__verification_requests as (
select * from {{ ref("stg_screen_and_protect__verification_requests") }}
)
),
stg_core__apim_user as (select * from {{ ref("stg_core__apim_user") }}),
stg_core__apim_user_type as (select * from {{ ref("stg_core__apim_user_type") }})
select
-- note that these ids are not the same as the ones found in Core DWH
-- they are completely unrelated
id_verification,
id_booking,
id_user_partner,
id_accommodation,
protection_type,
protection_starting_level,
protection_basic_amount,
protection_extended_amount,
pet_protection,
verification_status,
verification_status_reason,
email_flag,
phone_flag,
watch_list,
channel,
checkin_date_utc,
checkout_date_utc,
checkout_date_utc - checkin_date_utc as number_of_nights,
is_cancelled,
cancelled_at_utc,
cancelled_date_utc,
user_email,
guest_email,
guest_last_name,
guest_first_name,
guest_telephone,
company_name,
property_manager_name,
property_manager_email,
listing_name,
listing_address,
listing_town,
listing_country,
listing_postcode,
pets_allowed,
status_updated_at_utc,
status_updated_date_utc,
updated_at_utc,
updated_date_utc,
cosmos_creation_at_utc,
cosmos_creation_date_utc,
created_date_utc
from stg_screen_and_protect__verification_requests
vr.id_verification,
vr.id_booking,
vr.id_user_partner,
vr.id_accommodation,
case
when (au.json_document_user_data ->> 'FlaggedNotProtected') = 'false'
then true
else false
end as is_protected,
vr.protection_type,
vr.protection_starting_level,
vr.protection_basic_amount,
vr.protection_extended_amount,
vr.pet_protection,
vr.verification_status,
vr.verification_status_reason,
vr.email_flag,
vr.phone_flag,
vr.watch_list,
vr.channel,
vr.checkin_date_utc,
vr.checkout_date_utc,
vr.checkout_date_utc - checkin_date_utc as number_of_nights,
vr.is_cancelled,
vr.cancelled_at_utc,
vr.cancelled_date_utc,
vr.user_email,
vr.guest_email,
vr.guest_last_name,
vr.guest_first_name,
vr.guest_telephone,
vr.company_name,
vr.property_manager_name,
vr.property_manager_email,
vr.listing_name,
vr.listing_address,
vr.listing_town,
vr.listing_country,
vr.listing_postcode,
vr.pets_allowed,
vr.status_updated_at_utc,
vr.status_updated_date_utc,
vr.updated_at_utc,
vr.updated_date_utc,
vr.cosmos_creation_at_utc,
vr.cosmos_creation_date_utc,
vr.created_date_utc
from stg_screen_and_protect__verification_requests vr
inner join stg_core__apim_user au on vr.id_user_partner = au.id_apim_user
inner join
stg_core__apim_user_type aut
on au.id_apim_user_type = aut.id_apim_user_type
and upper(aut.user_type_name) = '{{ api_name }}'

View file

@ -30,6 +30,13 @@ models:
data_type: text
description: Identifier for the accommodation related to the booking.
- name: is_protected
data_type: boolean
description: |
Indicates if the booking is protected or not.
tests:
- not_null
- name: protection_type
data_type: text
description: Specific protection type for the request.

View file

@ -30,6 +30,13 @@ models:
data_type: text
description: Identifier for the accommodation related to the booking.
- name: is_protected
data_type: boolean
description: |
Indicates if the booking is protected or not.
tests:
- not_null
- name: protection_type
data_type: text
description: Specific protection type for the request.

View file

@ -9,6 +9,7 @@ select
id_booking as id_booking,
id_user_partner as id_user_partner,
id_accommodation as id_accommodation,
is_protected as is_protected,
protection_type as protection_type,
protection_starting_level as protection_starting_level,
protection_basic_amount as protection_basic_amount,

View file

@ -1381,7 +1381,7 @@ models:
- not_null
- name: json_document_user_data
data_type: character varying
data_type: jsonb
description: |
"The json document that contains the user information"

View file

@ -4,7 +4,7 @@ with
select
{{ adapter.quote("UserId") }} as id_apim_user,
{{ adapter.quote("ApimUserTypeId") }} as id_apim_user_type,
{{ adapter.quote("Json") }} as json_document_user_data,
{{ adapter.quote("Json") }}::jsonb as json_document_user_data,
{{ adapter.quote("CreatedDate") }} as created_at_utc,
cast({{ adapter.quote("CreatedDate") }} as date) as created_date_utc,
{{ adapter.quote("UpdatedDate") }} as updated_at_utc,