diff --git a/deploy/campsite_type__operating_dates.sql b/deploy/campsite_type__operating_dates.sql new file mode 100644 index 0000000..6739da4 --- /dev/null +++ b/deploy/campsite_type__operating_dates.sql @@ -0,0 +1,12 @@ +-- Deploy camper:campsite_type__operating_dates to pg +-- requires: campsite_type + +begin; + +set search_path to camper, public; + +alter table campsite_type + add column operating_dates daterange not null default 'empty' +; + +commit; diff --git a/pkg/booking/public.go b/pkg/booking/public.go index 6d73ff2..d28b918 100644 --- a/pkg/booking/public.go +++ b/pkg/booking/public.go @@ -245,14 +245,14 @@ func NewDateFields(ctx context.Context, conn *database.Conn, campsiteType string row := conn.QueryRow(ctx, ` select lower(bookable_nights), upper(bookable_nights) - 1, - greatest(min(lower(season_range)), current_timestamp::date), - max(upper(season_range)) + greatest(min(lower(season_range)), lower(operating_dates), current_timestamp::date), + least(max(upper(season_range)), upper(operating_dates)) from campsite_type join campsite_type_cost using (campsite_type_id) join season_calendar using (season_id) where campsite_type.slug = $1 and season_range >> daterange(date_trunc('year', current_timestamp)::date, date_trunc('year', current_timestamp)::date + 1) - group by bookable_nights; + group by bookable_nights, operating_dates `, campsiteType) f := &DateFields{ ArrivalDate: &bookingDateInput{ diff --git a/revert/campsite_type__operating_dates.sql b/revert/campsite_type__operating_dates.sql new file mode 100644 index 0000000..c64268d --- /dev/null +++ b/revert/campsite_type__operating_dates.sql @@ -0,0 +1,9 @@ +-- Revert camper:campsite_type__operating_dates from pg + +begin; + +alter table camper.campsite_type + drop column if exists operating_dates +; + +commit; diff --git a/sqitch.plan b/sqitch.plan index 6101d68..999bb2e 100644 --- a/sqitch.plan +++ b/sqitch.plan @@ -333,3 +333,4 @@ booking_invoice [roles schema_camper booking invoice] 2024-04-28T19:45:05Z jordi marshal_payment [roles schema_camper payment payment_customer payment_option payment__acsi_card payment_customer__-acsi_card] 2024-04-29T17:11:59Z jordi fita mas # Add function to marshal a payment unmarshal_booking [roles schema_camper booking booking_option extension_pg_libphonenumber] 2024-04-29T17:20:38Z jordi fita mas # Add function to unmarshal a booking cancel_booking [roles schema_camper booking booking_campsite] 2024-05-03T14:27:31Z jordi fita mas # Add function to cancel a booking +campsite_type__operating_dates [campsite_type] 2024-07-15T21:27:19Z jordi fita mas # Add operating_dates field to campsite_type diff --git a/test/campsite_type.sql b/test/campsite_type.sql index 83ad93c..0293b08 100644 --- a/test/campsite_type.sql +++ b/test/campsite_type.sql @@ -5,7 +5,7 @@ reset client_min_messages; begin; -select plan(108); +select plan(113); set search_path to camper, public; @@ -118,6 +118,12 @@ select col_not_null('campsite_type', 'active'); select col_has_default('campsite_type', 'active'); select col_default_is('campsite_type', 'active', 'true'); +select has_column('campsite_type', 'operating_dates'); +select col_type_is('campsite_type', 'operating_dates', 'daterange'); +select col_not_null('campsite_type', 'operating_dates'); +select col_has_default('campsite_type', 'operating_dates'); +select col_default_is('campsite_type', 'operating_dates', 'empty'); + select has_column('campsite_type', 'position'); select col_type_is('campsite_type', 'position', 'integer'); select col_not_null('campsite_type', 'position'); diff --git a/verify/campsite_type__operating_dates.sql b/verify/campsite_type__operating_dates.sql new file mode 100644 index 0000000..427a4be --- /dev/null +++ b/verify/campsite_type__operating_dates.sql @@ -0,0 +1,10 @@ +-- Verify camper:campsite_type__operating_dates on pg + +begin; + +select operating_dates +from camper.campsite_type +where false +; + +rollback;