From 10f42d1146f022c9934d55994b2e23fa276cfd9b Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Fri, 20 Dec 2024 15:36:00 +0100 Subject: [PATCH] Check in Hero users table --- .../int_check_in_hero__checkins.sql | 18 ++--- models/intermediate/check_in_hero/schema.yml | 10 +++ .../core/int_core__check_in_hero_users.sql | 26 ++++++ models/intermediate/core/schema.yml | 80 +++++++++++++++++++ 4 files changed, 122 insertions(+), 12 deletions(-) create mode 100644 models/intermediate/core/int_core__check_in_hero_users.sql diff --git a/models/intermediate/check_in_hero/int_check_in_hero__checkins.sql b/models/intermediate/check_in_hero/int_check_in_hero__checkins.sql index 99a5dfb..e3f5cd3 100644 --- a/models/intermediate/check_in_hero/int_check_in_hero__checkins.sql +++ b/models/intermediate/check_in_hero/int_check_in_hero__checkins.sql @@ -1,18 +1,17 @@ -{% set api_name = "CHECKINHEROAPI" %} - with stg_check_in_hero__checkins as ( select * from {{ ref("stg_check_in_hero__checkins") }} ), - 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") }}), - stg_core__user as (select * from {{ ref("stg_core__user") }}) + int_core__check_in_hero_users as ( + select * from {{ ref("int_core__check_in_hero_users") }} + ) select c.id_record, c.id_user_partner, c.id_reservation, c.id_accommodation, + chu.id_currency, c.guest_last_name, c.guest_first_name, c.guest_email, @@ -31,7 +30,7 @@ select c.listing_town, c.listing_country, c.listing_postcode, - u.company_name, + chu.company_name, c.user_email, c.updated_at_utc, c.updated_date_utc, @@ -39,9 +38,4 @@ select c.cosmos_creation_date_utc, c.created_date_utc from stg_check_in_hero__checkins c -inner join stg_core__apim_user au on c.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 }}' -left join stg_core__user u on u.id_user = au.id_apim_user +inner join int_core__check_in_hero_users chu on c.id_user_partner = chu.id_apim_user diff --git a/models/intermediate/check_in_hero/schema.yml b/models/intermediate/check_in_hero/schema.yml index 0a16592..3337457 100644 --- a/models/intermediate/check_in_hero/schema.yml +++ b/models/intermediate/check_in_hero/schema.yml @@ -31,6 +31,16 @@ models: tests: - not_null + - name: id_currency + data_type: bigint + description: "Id of the currency, works as a foreign key to the + currency table" + tests: + - not_null + - relationships: + to: ref('stg_core__currency') + field: id_currency + - name: guest_last_name data_type: text description: Last name of the guest checking in. diff --git a/models/intermediate/core/int_core__check_in_hero_users.sql b/models/intermediate/core/int_core__check_in_hero_users.sql new file mode 100644 index 0000000..b0feaf0 --- /dev/null +++ b/models/intermediate/core/int_core__check_in_hero_users.sql @@ -0,0 +1,26 @@ +{% set api_name = "CHECKINHEROAPI" %} + +with + 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") }}), + stg_core__user as (select * from {{ ref("stg_core__user") }}) +select + au.id_apim_user, + au.id_apim_user_type, + u.id_account_currency as id_currency, + au.json_document_user_data ->> 'DealId' as id_deal, + au.json_document_user_data ->> 'AccountType' as account_type, + au.json_document_user_data ->> 'ClientMarkup' as client_markup, + (au.json_document_user_data ->> 'BookingFee')::decimal + as booking_fee_in_local_currency, + u.company_name, + au.created_at_utc, + au.created_date_utc, + au.updated_at_utc, + au.updated_date_utc +from stg_core__apim_user au +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 }}' +inner join stg_core__user u on au.id_apim_user = u.id_user diff --git a/models/intermediate/core/schema.yml b/models/intermediate/core/schema.yml index 6d24dbe..a42eca3 100644 --- a/models/intermediate/core/schema.yml +++ b/models/intermediate/core/schema.yml @@ -4719,3 +4719,83 @@ models: Date of when this user was last updated. tests: - not_null + + - name: int_core__check_in_hero_users + description: | + "Contains information about CheckIn Hero API users. + It includes all user details related with the service." + columns: + - name: id_apim_user + data_type: character varying + description: "Identifier of the User. Acts as primary + key for this table." + tests: + - not_null + - unique + + - name: id_apim_user_type + data_type: bigint + description: "Identifier of the type of user." + + - name: id_currency + data_type: bigint + description: "Id of the currency, works as a foreign key to the + currency table" + tests: + - not_null + - relationships: + to: ref('stg_core__currency') + field: id_currency + + - name: id_deal + data_type: text + description: "" + + - name: account_type + data_type: text + description: "" + + - name: client_markup + data_type: text + description: "" + + - name: booking_fee_in_local_currency + data_type: numeric + description: "Fee charged to the user for each booking in the local currency." + tests: + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + max_value: 1000 + strictly: true + + - name: company_name + data_type: text + description: Company name of partner user. + + - name: created_at_utc + data_type: timestamp + description: | + Timestamp of when this user was created. + tests: + - not_null + + - name: created_date_utc + data_type: date + description: | + Date of when this user was created. + tests: + - not_null + + - name: updated_at_utc + data_type: timestamp + description: | + Timestamp of when this user was last updated. + tests: + - not_null + + - name: updated_date_utc + data_type: date + description: | + Date of when this user was last updated. + tests: + - not_null