diff --git a/demo/demo.sql b/demo/demo.sql index c6a8412..a401164 100644 --- a/demo/demo.sql +++ b/demo/demo.sql @@ -127,11 +127,11 @@ select translate_services_carousel_slide(63, 'en', 'Safari Tents'); select translate_services_carousel_slide(63, 'es', 'Tiendas Safari'); alter table campsite_type alter column campsite_type_id restart with 72; -select add_campsite_type(52, 62, 'Parceŀles', '
Ubicats al costat muntanya del càmping i amb vista a la natura que ens envolta.
Parcel·les amples amb serveis a prop d’on ets per fer allò que vols.
', '* Tovalloles: preu extra
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '15 h a 21 h', '12 h', 6, true, true, true); -select add_campsite_type(52, 63, 'Safari Tents', 'Un luxe de tendes per viure aventures.
Dues tendes amb terra de fusta, llits, cuina i tot de comoditats per gaudir de les teves vacances.
', '* Tovalloles: preu extra
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '16 h a 21 h', '10 h', 6, false, false, false); -select add_campsite_type(52, 64, 'Bungalous', 'Ubicats al costat muntanya del càmping i amb vista a la natura que ens envolta.
Dues cabanes de fusta massissa de dues plantes i amb porxo cobert per gaudir entre arbres.
', '* Tovalloles: preu extra
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '15 h a 21 h', '12 h', 5, false, false, false); -select add_campsite_type(52, 65, 'Bungalous prèmium', 'Ubicats al costat muntanya del càmping i amb vista a la natura que ens envolta.
Dues cabanes de fusta massissa de dues plantes i amb porxo cobert per gaudir entre arbres.
', '* Tovalloles: preu extra
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '15 h a 21 h', '12 h', 5, false, false, false); -select add_campsite_type(52, 66, 'Cabanes de fusta', 'Ubicats al costat muntanya del càmping i amb vista a la natura que ens envolta.
Dues cabanes de fusta massissa de dues plantes i amb porxo cobert per gaudir entre arbres.
', '* Tovalloles: preu extra
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '15 h a 21 h', '12 h', 5, false, false, false); +select add_campsite_type(52, 62, 'Parceŀles', 'Ubicats al costat muntanya del càmping i amb vista a la natura que ens envolta.
Parcel·les amples amb serveis a prop d’on ets per fer allò que vols.
', '* Tovalloles: preu extra
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '15 h a 21 h', '12 h', 6, '[1, 7]', true, true, true); +select add_campsite_type(52, 63, 'Safari Tents', 'Un luxe de tendes per viure aventures.
Dues tendes amb terra de fusta, llits, cuina i tot de comoditats per gaudir de les teves vacances.
', '* Tovalloles: preu extra
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '16 h a 21 h', '10 h', 6, '[2, 7]', false, false, false); +select add_campsite_type(52, 64, 'Bungalous', 'Ubicats al costat muntanya del càmping i amb vista a la natura que ens envolta.
Dues cabanes de fusta massissa de dues plantes i amb porxo cobert per gaudir entre arbres.
', '* Tovalloles: preu extra
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '15 h a 21 h', '12 h', 5, '[2, 7]', false, false, false); +select add_campsite_type(52, 65, 'Bungalous prèmium', 'Ubicats al costat muntanya del càmping i amb vista a la natura que ens envolta.
Dues cabanes de fusta massissa de dues plantes i amb porxo cobert per gaudir entre arbres.
', '* Tovalloles: preu extra
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '15 h a 21 h', '12 h', 5, '[2, 7]', false, false, false); +select add_campsite_type(52, 66, 'Cabanes de fusta', 'Ubicats al costat muntanya del càmping i amb vista a la natura que ens envolta.
Dues cabanes de fusta massissa de dues plantes i amb porxo cobert per gaudir entre arbres.
', '* Tovalloles: preu extra
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '15 h a 21 h', '12 h', 5, '[2, 7]', false, false, false); insert into campsite_type_i18n (campsite_type_id, lang_tag, name, spiel, info, facilities, description, additional_info, check_in, check_out) values (72, 'en', 'Plots', 'Located on the campground’s mountain-side and overlooking the nature that surrounds us.
Large plots with serivces close to where you are to do what you want.
', '* Towels: extra cost
', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
', '', '3 p.m. to 9 p.m.', '12 a.m.') @@ -1231,23 +1231,21 @@ select set_season_range(94, '[2023-09-24, 2023-09-28]'); select set_season_range(93, '[2023-09-29, 2023-09-30]'); select set_season_range(94, '[2023-10-01, 2023-10-12]'); -insert into campsite_type_cost (campsite_type_id, season_id, cost_per_night, min_nights) -values (72, 92, 20000, 1) - , (72, 93, 16500, 1) - , (72, 94, 12500, 1) - , (73, 92, 20000, 2) - , (73, 93, 16500, 2) - , (73, 94, 12500, 2) - , (74, 92, 20000, 2) - , (74, 93, 16500, 2) - , (74, 94, 12500, 2) - , (75, 92, 20000, 2) - , (75, 93, 16500, 2) - , (75, 94, 12500, 2) - , (76, 92, 20000, 2) - , (76, 93, 16500, 2) - , (76, 94, 12500, 2) -; +select set_campsite_type_cost (slug, 92, '20.00') from campsite_type where campsite_type_id = 72; +select set_campsite_type_cost (slug, 93, '16.50') from campsite_type where campsite_type_id = 72; +select set_campsite_type_cost (slug, 94, '12.50') from campsite_type where campsite_type_id = 72; +select set_campsite_type_cost (slug, 92, '20.00') from campsite_type where campsite_type_id = 73; +select set_campsite_type_cost (slug, 93, '16.50') from campsite_type where campsite_type_id = 73; +select set_campsite_type_cost (slug, 94, '12.50') from campsite_type where campsite_type_id = 73; +select set_campsite_type_cost (slug, 92, '20.00') from campsite_type where campsite_type_id = 74; +select set_campsite_type_cost (slug, 93, '16.50') from campsite_type where campsite_type_id = 74; +select set_campsite_type_cost (slug, 94, '12.50') from campsite_type where campsite_type_id = 74; +select set_campsite_type_cost (slug, 92, '20.00') from campsite_type where campsite_type_id = 75; +select set_campsite_type_cost (slug, 93, '16.50') from campsite_type where campsite_type_id = 75; +select set_campsite_type_cost (slug, 94, '12.50') from campsite_type where campsite_type_id = 75; +select set_campsite_type_cost (slug, 92, '20.00') from campsite_type where campsite_type_id = 76; +select set_campsite_type_cost (slug, 93, '16.50') from campsite_type where campsite_type_id = 76; +select set_campsite_type_cost (slug, 94, '12.50') from campsite_type where campsite_type_id = 76; alter table campsite_type_option alter column campsite_type_option_id restart with 102; insert into campsite_type_option (campsite_type_id, name, range) diff --git a/deploy/add_campsite_type.sql b/deploy/add_campsite_type.sql index 5130991..b7bf62a 100644 --- a/deploy/add_campsite_type.sql +++ b/deploy/add_campsite_type.sql @@ -11,18 +11,18 @@ begin; set search_path to camper, public; -drop function if exists add_campsite_type(integer, integer, text, text, text, text, text, text, text, text, integer, boolean); +drop function if exists add_campsite_type(integer, integer, text, text, text, text, text, text, text, text, integer, boolean, boolean, boolean); -create or replace function add_campsite_type(company integer, media_id integer, name text, spiel text, info text, facilities text, description text, additional_info text, check_in text, check_out text, max_campers integer, dogs_allowed boolean, overflow_allowed boolean, ask_zone_preferences boolean) returns uuid as +create or replace function add_campsite_type(company integer, media_id integer, name text, spiel text, info text, facilities text, description text, additional_info text, check_in text, check_out text, max_campers integer, bookable_nights int4range, dogs_allowed boolean, overflow_allowed boolean, ask_zone_preferences boolean) returns uuid as $$ - insert into campsite_type (company_id, media_id, name, spiel, info, facilities, description, additional_info, check_in, check_out, max_campers, dogs_allowed, overflow_allowed, ask_zone_preferences) - values (company, media_id, name, xmlparse(content spiel), xmlparse(content info), xmlparse(content facilities), xmlparse(content description), xmlparse(content additional_info), check_in, check_out, max_campers, dogs_allowed, overflow_allowed, ask_zone_preferences) + insert into campsite_type (company_id, media_id, name, spiel, info, facilities, description, additional_info, check_in, check_out, max_campers, bookable_nights, dogs_allowed, overflow_allowed, ask_zone_preferences) + values (company, media_id, name, xmlparse(content spiel), xmlparse(content info), xmlparse(content facilities), xmlparse(content description), xmlparse(content additional_info), check_in, check_out, max_campers, bookable_nights, dogs_allowed, overflow_allowed, ask_zone_preferences) returning slug; $$ language sql ; -revoke execute on function add_campsite_type(integer, integer, text, text, text, text, text, text, text, text, integer, boolean, boolean, boolean) from public; -grant execute on function add_campsite_type(integer, integer, text, text, text, text, text, text, text, text, integer, boolean, boolean, boolean) to admin; +revoke execute on function add_campsite_type(integer, integer, text, text, text, text, text, text, text, text, integer, int4range, boolean, boolean, boolean) from public; +grant execute on function add_campsite_type(integer, integer, text, text, text, text, text, text, text, text, integer, int4range, boolean, boolean, boolean) to admin; commit; diff --git a/deploy/add_campsite_type@v3.sql b/deploy/add_campsite_type@v3.sql new file mode 100644 index 0000000..5130991 --- /dev/null +++ b/deploy/add_campsite_type@v3.sql @@ -0,0 +1,28 @@ +-- Deploy camper:add_campsite_type to pg +-- requires: roles +-- requires: schema_camper +-- requires: campsite_type +-- requires: company +-- requires: campsite_type__check_in_out +-- requires: campsite_type__overflow_allowed +-- requires: campsite_type__ask_zone_preferences + +begin; + +set search_path to camper, public; + +drop function if exists add_campsite_type(integer, integer, text, text, text, text, text, text, text, text, integer, boolean); + +create or replace function add_campsite_type(company integer, media_id integer, name text, spiel text, info text, facilities text, description text, additional_info text, check_in text, check_out text, max_campers integer, dogs_allowed boolean, overflow_allowed boolean, ask_zone_preferences boolean) returns uuid as +$$ + insert into campsite_type (company_id, media_id, name, spiel, info, facilities, description, additional_info, check_in, check_out, max_campers, dogs_allowed, overflow_allowed, ask_zone_preferences) + values (company, media_id, name, xmlparse(content spiel), xmlparse(content info), xmlparse(content facilities), xmlparse(content description), xmlparse(content additional_info), check_in, check_out, max_campers, dogs_allowed, overflow_allowed, ask_zone_preferences) + returning slug; +$$ + language sql +; + +revoke execute on function add_campsite_type(integer, integer, text, text, text, text, text, text, text, text, integer, boolean, boolean, boolean) from public; +grant execute on function add_campsite_type(integer, integer, text, text, text, text, text, text, text, text, integer, boolean, boolean, boolean) to admin; + +commit; diff --git a/deploy/campsite_type__bookable_nights.sql b/deploy/campsite_type__bookable_nights.sql new file mode 100644 index 0000000..33c1e0c --- /dev/null +++ b/deploy/campsite_type__bookable_nights.sql @@ -0,0 +1,27 @@ +-- Deploy camper:campsite_type__bookable_nights to pg +-- requires: campsite_type +-- requires: campsite_type_cost + +begin; + +set search_path to camper, public; + +alter table campsite_type +add column bookable_nights int4range not null default '[1, 8)' constraint at_least_one_night check (not isempty(bookable_nights) and lower(bookable_nights) > 0) +; + +update campsite_type +set bookable_nights = int4range(min_nights, 8) +from campsite_type_cost +where campsite_type_cost.campsite_type_id = campsite_type.campsite_type_id +; + +--alter table campsite_type_cost +--drop column if exists min_nights +--; + +alter table campsite_type +alter column bookable_nights drop default +; + +commit; diff --git a/deploy/campsite_type_cost__-min_nights.sql b/deploy/campsite_type_cost__-min_nights.sql new file mode 100644 index 0000000..b51a9d6 --- /dev/null +++ b/deploy/campsite_type_cost__-min_nights.sql @@ -0,0 +1,11 @@ +-- Deploy camper:campsite_type_cost__-min_nights to pg +-- requires: campsite_type__bookable_nights +-- requires: set_campsite_type_cost@HEAD + +begin; + +alter table camper.campsite_type_cost +drop column if exists min_nights +; + +commit; diff --git a/deploy/edit_campsite_type.sql b/deploy/edit_campsite_type.sql index 81efa25..ceb28d7 100644 --- a/deploy/edit_campsite_type.sql +++ b/deploy/edit_campsite_type.sql @@ -11,9 +11,9 @@ begin; set search_path to camper, public; -drop function if exists edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, boolean, boolean); +drop function if exists edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, boolean, boolean, boolean, boolean); -create or replace function edit_campsite_type(slug uuid, media_id integer, name text, spiel text, info text, facilities text, description text, additional_info text, check_in text, check_out text, max_campers integer, dogs_allowed boolean, overflow_allowed boolean, ask_zone_preferences boolean, active boolean) returns uuid as +create or replace function edit_campsite_type(slug uuid, media_id integer, name text, spiel text, info text, facilities text, description text, additional_info text, check_in text, check_out text, max_campers integer, bookable_nights int4range, dogs_allowed boolean, overflow_allowed boolean, ask_zone_preferences boolean, active boolean) returns uuid as $$ update campsite_type set name = edit_campsite_type.name @@ -26,6 +26,7 @@ $$ , facilities = xmlparse(content edit_campsite_type.facilities) , media_id = coalesce(edit_campsite_type.media_id, campsite_type.media_id) , max_campers = edit_campsite_type.max_campers + , bookable_nights = edit_campsite_type.bookable_nights , dogs_allowed = edit_campsite_type.dogs_allowed , overflow_allowed = edit_campsite_type.overflow_allowed , ask_zone_preferences = edit_campsite_type.ask_zone_preferences @@ -36,7 +37,7 @@ $$ language sql ; -revoke execute on function edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, boolean, boolean, boolean, boolean) from public; -grant execute on function edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, boolean, boolean, boolean, boolean) to admin; +revoke execute on function edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, int4range, boolean, boolean, boolean, boolean) from public; +grant execute on function edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, int4range, boolean, boolean, boolean, boolean) to admin; commit; diff --git a/deploy/edit_campsite_type@v3.sql b/deploy/edit_campsite_type@v3.sql new file mode 100644 index 0000000..81efa25 --- /dev/null +++ b/deploy/edit_campsite_type@v3.sql @@ -0,0 +1,42 @@ +-- Deploy camper:edit_campsite_type to pg +-- requires: roles +-- requires: schema_camper +-- requires: campsite_type +-- requires: company +-- requires: campsite_type__check_in_out +-- requires: campsite_type__overflow_allowed +-- requires: campsite_type__ask_zone_preferences + +begin; + +set search_path to camper, public; + +drop function if exists edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, boolean, boolean); + +create or replace function edit_campsite_type(slug uuid, media_id integer, name text, spiel text, info text, facilities text, description text, additional_info text, check_in text, check_out text, max_campers integer, dogs_allowed boolean, overflow_allowed boolean, ask_zone_preferences boolean, active boolean) returns uuid as +$$ + update campsite_type + set name = edit_campsite_type.name + , spiel = xmlparse(content edit_campsite_type.spiel) + , description = xmlparse(content edit_campsite_type.description) + , info = xmlparse(content edit_campsite_type.info) + , additional_info = xmlparse(content edit_campsite_type.additional_info) + , check_in = edit_campsite_type.check_in + , check_out = edit_campsite_type.check_out + , facilities = xmlparse(content edit_campsite_type.facilities) + , media_id = coalesce(edit_campsite_type.media_id, campsite_type.media_id) + , max_campers = edit_campsite_type.max_campers + , dogs_allowed = edit_campsite_type.dogs_allowed + , overflow_allowed = edit_campsite_type.overflow_allowed + , ask_zone_preferences = edit_campsite_type.ask_zone_preferences + , active = edit_campsite_type.active + where slug = edit_campsite_type.slug + returning slug; +$$ +language sql +; + +revoke execute on function edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, boolean, boolean, boolean, boolean) from public; +grant execute on function edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, boolean, boolean, boolean, boolean) to admin; + +commit; diff --git a/deploy/set_campsite_type_cost.sql b/deploy/set_campsite_type_cost.sql index 8322f0f..5a53c7b 100644 --- a/deploy/set_campsite_type_cost.sql +++ b/deploy/set_campsite_type_cost.sql @@ -8,21 +8,22 @@ begin; set search_path to camper, public; -create or replace function set_campsite_type_cost(slug uuid, season_id integer, min_nights integer, cost_per_night text, decimal_places integer default 2) returns void as +drop function if exists set_campsite_type_cost(uuid, integer, integer, text, integer); + +create or replace function set_campsite_type_cost(slug uuid, season_id integer, cost_per_night text, decimal_places integer default 2) returns void as $$ - insert into campsite_type_cost (campsite_type_id, season_id, min_nights, cost_per_night) - select campsite_type_id, season_id, min_nights, parse_price(cost_per_night, decimal_places) + insert into campsite_type_cost (campsite_type_id, season_id, cost_per_night) + select campsite_type_id, season_id, parse_price(cost_per_night, decimal_places) from campsite_type where campsite_type.slug = set_campsite_type_cost.slug on conflict (campsite_type_id, season_id) do update - set min_nights = excluded.min_nights - , cost_per_night = excluded.cost_per_night + set cost_per_night = excluded.cost_per_night ; $$ language sql ; -revoke execute on function set_campsite_type_cost(uuid, integer, integer, text, integer) from public; -grant execute on function set_campsite_type_cost(uuid, integer, integer, text, integer) to admin; +revoke execute on function set_campsite_type_cost(uuid, integer, text, integer) from public; +grant execute on function set_campsite_type_cost(uuid, integer, text, integer) to admin; commit; diff --git a/deploy/set_campsite_type_cost@v3.sql b/deploy/set_campsite_type_cost@v3.sql new file mode 100644 index 0000000..8322f0f --- /dev/null +++ b/deploy/set_campsite_type_cost@v3.sql @@ -0,0 +1,28 @@ +-- Deploy camper:set_campsite_type_cost to pg +-- requires: roles +-- requires: schema_camper +-- requires: campsite_type_cost +-- requires: parse_price + +begin; + +set search_path to camper, public; + +create or replace function set_campsite_type_cost(slug uuid, season_id integer, min_nights integer, cost_per_night text, decimal_places integer default 2) returns void as +$$ + insert into campsite_type_cost (campsite_type_id, season_id, min_nights, cost_per_night) + select campsite_type_id, season_id, min_nights, parse_price(cost_per_night, decimal_places) + from campsite_type + where campsite_type.slug = set_campsite_type_cost.slug + on conflict (campsite_type_id, season_id) do update + set min_nights = excluded.min_nights + , cost_per_night = excluded.cost_per_night + ; +$$ + language sql +; + +revoke execute on function set_campsite_type_cost(uuid, integer, integer, text, integer) from public; +grant execute on function set_campsite_type_cost(uuid, integer, integer, text, integer) to admin; + +commit; diff --git a/pkg/build/version.go b/pkg/build/version.go index d132957..71687b3 100644 --- a/pkg/build/version.go +++ b/pkg/build/version.go @@ -1,3 +1,3 @@ package build -const Version = "1.2~git" +const Version = "1.3~git" diff --git a/pkg/campsite/types/admin.go b/pkg/campsite/types/admin.go index 2ded84a..1baf919 100644 --- a/pkg/campsite/types/admin.go +++ b/pkg/campsite/types/admin.go @@ -167,7 +167,7 @@ func addType(w http.ResponseWriter, r *http.Request, user *auth.User, company *a } processTypeForm(w, r, user, company, conn, f, func(ctx context.Context, tx *database.Tx) error { var err error - f.Slug, err = tx.AddCampsiteType(ctx, company.ID, f.Media.Int(), f.Name[f.DefaultLang].Val, f.Spiel[f.DefaultLang].Val, f.Info[f.DefaultLang].Val, f.Facilities[f.DefaultLang].Val, f.Description[f.DefaultLang].Val, f.AdditionalInfo[f.DefaultLang].Val, f.CheckIn[f.DefaultLang].Val, f.CheckOut[f.DefaultLang].Val, f.MaxCampers.Int(), f.DogsAllowed.Checked, f.OverflowAllowed.Checked, f.AskZonePreferences.Checked) + f.Slug, err = tx.AddCampsiteType(ctx, company.ID, f.Media.Int(), f.Name[f.DefaultLang].Val, f.Spiel[f.DefaultLang].Val, f.Info[f.DefaultLang].Val, f.Facilities[f.DefaultLang].Val, f.Description[f.DefaultLang].Val, f.AdditionalInfo[f.DefaultLang].Val, f.CheckIn[f.DefaultLang].Val, f.CheckOut[f.DefaultLang].Val, f.MaxCampers.Int(), f.MinNights.Int(), f.MaxNights.Int(), f.DogsAllowed.Checked, f.OverflowAllowed.Checked, f.AskZonePreferences.Checked) if err != nil { return err } @@ -193,7 +193,7 @@ func translateTypes(ctx context.Context, tx *database.Tx, company *auth.Company, func setTypePrices(ctx context.Context, tx *database.Tx, slug string, prices map[int]*typePriceForm) error { for seasonID, p := range prices { - if err := tx.SetCampsiteTypeCost(ctx, slug, seasonID, p.MinNights.Int(), p.PricePerNight.Val); err != nil { + if err := tx.SetCampsiteTypeCost(ctx, slug, seasonID, p.PricePerNight.Val); err != nil { return err } } @@ -202,7 +202,7 @@ func setTypePrices(ctx context.Context, tx *database.Tx, slug string, prices map func editType(w http.ResponseWriter, r *http.Request, user *auth.User, company *auth.Company, conn *database.Conn, f *typeForm) { processTypeForm(w, r, user, company, conn, f, func(ctx context.Context, tx *database.Tx) error { - if _, err := tx.EditCampsiteType(ctx, f.Slug, f.Media.Int(), f.Name[f.DefaultLang].Val, f.Spiel[f.DefaultLang].Val, f.Info[f.DefaultLang].Val, f.Facilities[f.DefaultLang].Val, f.Description[f.DefaultLang].Val, f.AdditionalInfo[f.DefaultLang].Val, f.CheckIn[f.DefaultLang].Val, f.CheckOut[f.DefaultLang].Val, f.MaxCampers.Int(), f.DogsAllowed.Checked, f.OverflowAllowed.Checked, f.AskZonePreferences.Checked, f.Active.Checked); err != nil { + if _, err := tx.EditCampsiteType(ctx, f.Slug, f.Media.Int(), f.Name[f.DefaultLang].Val, f.Spiel[f.DefaultLang].Val, f.Info[f.DefaultLang].Val, f.Facilities[f.DefaultLang].Val, f.Description[f.DefaultLang].Val, f.AdditionalInfo[f.DefaultLang].Val, f.CheckIn[f.DefaultLang].Val, f.CheckOut[f.DefaultLang].Val, f.MaxCampers.Int(), f.MinNights.Int(), f.MaxNights.Int(), f.DogsAllowed.Checked, f.OverflowAllowed.Checked, f.AskZonePreferences.Checked, f.Active.Checked); err != nil { return err } if err := translateTypes(ctx, tx, company, f); err != nil { @@ -276,6 +276,8 @@ type typeForm struct { Media *form.Media Name form.I18nInput MaxCampers *form.Input + MinNights *form.Input + MaxNights *form.Input DogsAllowed *form.Checkbox OverflowAllowed *form.Checkbox AskZonePreferences *form.Checkbox @@ -292,7 +294,6 @@ type typeForm struct { type typePriceForm struct { SeasonName string PricePerNight *form.Input - MinNights *form.Input } func newTypeForm(ctx context.Context, company *auth.Company, conn *database.Conn) (*typeForm, error) { @@ -313,6 +314,14 @@ func newTypeForm(ctx context.Context, company *auth.Company, conn *database.Conn MaxCampers: &form.Input{ Name: "max_campers", }, + MinNights: &form.Input{ + Name: "min_nights", + Val: "1", + }, + MaxNights: &form.Input{ + Name: "max_nights", + Val: "7", + }, DogsAllowed: &form.Checkbox{ Name: "dogs_allowed", }, @@ -350,10 +359,6 @@ func newTypeForm(ctx context.Context, company *auth.Company, conn *database.Conn Name: fmt.Sprintf("season.%d.price_per_night", id), Val: "0", }, - MinNights: &form.Input{ - Name: fmt.Sprintf("season.%d.min_nights", id), - Val: "1", - }, } } @@ -381,6 +386,8 @@ func (f *typeForm) FillFromDatabase(ctx context.Context, conn *database.Conn, sl , campsite_type.check_out::text , media_id::text , max_campers::text + , lower(bookable_nights)::text + , (upper(bookable_nights) - 1)::text , dogs_allowed , overflow_allowed , ask_zone_preferences @@ -406,12 +413,38 @@ func (f *typeForm) FillFromDatabase(ctx context.Context, conn *database.Conn, sl , campsite_type.check_out , media_id::text , max_campers::text + , bookable_nights , dogs_allowed , overflow_allowed , ask_zone_preferences , active `, pgx.QueryResultFormats{pgx.BinaryFormatCode}, slug) - if err := row.Scan(&f.Name[f.DefaultLang].Val, &f.Spiel[f.DefaultLang].Val, &f.Info[f.DefaultLang].Val, &f.Facilities[f.DefaultLang].Val, &f.Description[f.DefaultLang].Val, &f.AdditionalInfo[f.DefaultLang].Val, &f.CheckIn[f.DefaultLang].Val, &f.CheckOut[f.DefaultLang].Val, &f.Media.Val, &f.MaxCampers.Val, &f.DogsAllowed.Checked, &f.OverflowAllowed.Checked, &f.AskZonePreferences.Checked, &f.Active.Checked, &name, &spiel, &info, &facilities, &description, &additionalInfo, &checkIn, &checkOut); err != nil { + if err := row.Scan( + &f.Name[f.DefaultLang].Val, + &f.Spiel[f.DefaultLang].Val, + &f.Info[f.DefaultLang].Val, + &f.Facilities[f.DefaultLang].Val, + &f.Description[f.DefaultLang].Val, + &f.AdditionalInfo[f.DefaultLang].Val, + &f.CheckIn[f.DefaultLang].Val, + &f.CheckOut[f.DefaultLang].Val, + &f.Media.Val, + &f.MaxCampers.Val, + &f.MinNights.Val, + &f.MaxNights.Val, + &f.DogsAllowed.Checked, + &f.OverflowAllowed.Checked, + &f.AskZonePreferences.Checked, + &f.Active.Checked, + &name, + &spiel, + &info, + &facilities, + &description, + &additionalInfo, + &checkIn, + &checkOut, + ); err != nil { return err } if err := f.Name.FillArray(name); err != nil { @@ -441,7 +474,6 @@ func (f *typeForm) FillFromDatabase(ctx context.Context, conn *database.Conn, sl rows, err := conn.Query(ctx, ` select season_id - , min_nights::text , to_price(cost_per_night) from campsite_type join campsite_type_cost using (campsite_type_id) @@ -454,13 +486,11 @@ func (f *typeForm) FillFromDatabase(ctx context.Context, conn *database.Conn, sl for rows.Next() { var seasonID int - var minNights string var pricePerNight string - if err := rows.Scan(&seasonID, &minNights, &pricePerNight); err != nil { + if err = rows.Scan(&seasonID, &pricePerNight); err != nil { return err } if p, ok := f.Prices[seasonID]; ok { - p.MinNights.Val = minNights p.PricePerNight.Val = pricePerNight } } @@ -474,6 +504,8 @@ func (f *typeForm) Parse(r *http.Request) error { f.Active.FillValue(r) f.Name.FillValue(r) f.MaxCampers.FillValue(r) + f.MinNights.FillValue(r) + f.MaxNights.FillValue(r) f.DogsAllowed.FillValue(r) f.OverflowAllowed.FillValue(r) f.AskZonePreferences.FillValue(r) @@ -487,7 +519,6 @@ func (f *typeForm) Parse(r *http.Request) error { f.Media.FillValue(r) for _, p := range f.Prices { p.PricePerNight.FillValue(r) - p.MinNights.FillValue(r) } return nil } @@ -509,17 +540,22 @@ func (f *typeForm) Valid(ctx context.Context, conn *database.Conn, l *locale.Loc v.CheckMinInteger(f.MaxCampers, 1, l.GettextNoop("Maximum number of campers must be one or greater.")) } } + if v.CheckRequired(f.MinNights, l.GettextNoop("Minimum number of nights can not be empty.")) { + if v.CheckValidInteger(f.MinNights, l.GettextNoop("Minimum number of nights must be an integer.")) { + v.CheckMinInteger(f.MinNights, 1, l.GettextNoop("Minimum number of nights must be one or greater.")) + } + } + if v.CheckRequired(f.MaxNights, l.GettextNoop("Maximum number of nights can not be empty.")) { + if v.CheckValidInteger(f.MaxNights, l.GettextNoop("Maximum number of nights must be an integer.")) && f.MinNights.Error == nil { + v.CheckMinInteger(f.MaxNights, f.MinNights.Int(), l.GettextNoop("Maximum number of nights must be equal or greater than the minimum.")) + } + } for _, p := range f.Prices { if v.CheckRequired(p.PricePerNight, l.GettextNoop("Price per night can not be empty.")) { if v.CheckValidDecimal(p.PricePerNight, l.GettextNoop("Price per night must be a decimal number.")) { v.CheckMinDecimal(p.PricePerNight, 0.0, l.GettextNoop("Price per night must be zero or greater.")) } } - if v.CheckRequired(p.MinNights, l.GettextNoop("Minimum number of nights can not be empty.")) { - if v.CheckValidInteger(p.MinNights, l.GettextNoop("Minimum number of nights must be an integer.")) { - v.CheckMinInteger(p.MinNights, 0, l.GettextNoop("Minimum number of nights must be one or greater.")) - } - } } return v.AllOK, nil } diff --git a/pkg/campsite/types/public.go b/pkg/campsite/types/public.go index 96e0b92..78b122b 100644 --- a/pkg/campsite/types/public.go +++ b/pkg/campsite/types/public.go @@ -78,12 +78,13 @@ type publicPage struct { AdditionalInfo gotemplate.HTML CheckIn string CheckOut string + MinNights int + MaxNights int } type typePrice struct { SeasonName string SeasonColor string - MinNights int PricePerNight string Options []*optionPrice } @@ -129,6 +130,8 @@ func newPublicPage(ctx context.Context, company *auth.Company, conn *database.Co , coalesce(i18n.additional_info, campsite_type.additional_info)::text as l10n_description , coalesce(i18n.check_in, campsite_type.check_in)::text as l10n_check_in , coalesce(i18n.check_out, campsite_type.check_out)::text as l10n_check_out + , lower(bookable_nights) + , upper(bookable_nights) - 1 , dogs_allowed , '3.50' as dogs_prices from campsite_type @@ -136,7 +139,20 @@ func newPublicPage(ctx context.Context, company *auth.Company, conn *database.Co where slug = $2 and active `, loc.Language, slug) - if err := row.Scan(&page.Name, &page.Spiel, &page.Info, &page.Facilities, &page.Description, &page.AdditionalInfo, &page.CheckIn, &page.CheckOut, &page.DogsAllowed, &page.DogsPrice); err != nil { + if err = row.Scan( + &page.Name, + &page.Spiel, + &page.Info, + &page.Facilities, + &page.Description, + &page.AdditionalInfo, + &page.CheckIn, + &page.CheckOut, + &page.MinNights, + &page.MaxNights, + &page.DogsAllowed, + &page.DogsPrice, + ); err != nil { return nil, err } if err := conn.QueryRow(ctx, "select to_price(tourist_tax, $1) from company where company_id = $2", company.DecimalDigits, company.ID).Scan(&page.TouristTax); err != nil { @@ -150,7 +166,6 @@ func collectPrices(ctx context.Context, conn *database.Conn, language language.T rows, err := conn.Query(ctx, ` select coalesce(i18n.name, season.name) as l10n_name , to_color(season.color)::text - , coalesce(cost.min_nights, 1) , to_price(coalesce(cost.cost_per_night, 0)) , array_agg((coalesce(option_i18n.name, option.name), to_price(coalesce(option_cost.cost_per_night, 0))) order by option.position) filter (where option.campsite_type_option_id is not null) from season @@ -169,7 +184,6 @@ func collectPrices(ctx context.Context, conn *database.Conn, language language.T group by i18n.name , season.name , season.color - , cost.min_nights , cost.cost_per_night , season.position order by season.position, l10n_name @@ -182,7 +196,12 @@ func collectPrices(ctx context.Context, conn *database.Conn, language language.T for rows.Next() { price := &typePrice{} var options database.RecordArray - if err := rows.Scan(&price.SeasonName, &price.SeasonColor, &price.MinNights, &price.PricePerNight, &options); err != nil { + if err = rows.Scan( + &price.SeasonName, + &price.SeasonColor, + &price.PricePerNight, + &options, + ); err != nil { return nil, err } for _, el := range options.Elements { diff --git a/pkg/database/funcs.go b/pkg/database/funcs.go index 512cad3..913a253 100644 --- a/pkg/database/funcs.go +++ b/pkg/database/funcs.go @@ -130,12 +130,12 @@ func (c *Conn) RemoveCampsiteFeature(ctx context.Context, id int) error { return err } -func (tx *Tx) AddCampsiteType(ctx context.Context, companyID int, mediaID int, name string, spiel string, info string, facilities string, description string, additionalInfo string, checkIn string, checkOut string, maxCampers int, dogsAllowed bool, overflowAllowed bool, askZonePreferences bool) (string, error) { - return tx.GetText(ctx, "select add_campsite_type($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)", companyID, mediaID, name, spiel, info, facilities, description, additionalInfo, checkIn, checkOut, maxCampers, dogsAllowed, overflowAllowed, askZonePreferences) +func (tx *Tx) AddCampsiteType(ctx context.Context, companyID int, mediaID int, name string, spiel string, info string, facilities string, description string, additionalInfo string, checkIn string, checkOut string, maxCampers int, minNights int, maxNights int, dogsAllowed bool, overflowAllowed bool, askZonePreferences bool) (string, error) { + return tx.GetText(ctx, "select add_campsite_type($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, int4range($12, $13), $14, $15, $16)", companyID, mediaID, name, spiel, info, facilities, description, additionalInfo, checkIn, checkOut, maxCampers, minNights, maxNights+1, dogsAllowed, overflowAllowed, askZonePreferences) } -func (tx *Tx) EditCampsiteType(ctx context.Context, slug string, mediaID int, name string, spiel string, info string, facilities string, description string, additionalInfo string, checkIn string, checkOut string, maxCampers int, dogsAllowed bool, overflowAllowed bool, askZonePreferences bool, active bool) (string, error) { - return tx.GetText(ctx, "select edit_campsite_type($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)", slug, mediaID, name, spiel, info, facilities, description, additionalInfo, checkIn, checkOut, maxCampers, dogsAllowed, overflowAllowed, askZonePreferences, active) +func (tx *Tx) EditCampsiteType(ctx context.Context, slug string, mediaID int, name string, spiel string, info string, facilities string, description string, additionalInfo string, checkIn string, checkOut string, maxCampers int, minNights int, maxNights int, dogsAllowed bool, overflowAllowed bool, askZonePreferences bool, active bool) (string, error) { + return tx.GetText(ctx, "select edit_campsite_type($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, int4range($12, $13), $14, $15, $16, $17)", slug, mediaID, name, spiel, info, facilities, description, additionalInfo, checkIn, checkOut, maxCampers, minNights, maxNights+1, dogsAllowed, overflowAllowed, askZonePreferences, active) } func (c *Conn) OrderCampsiteTypes(ctx context.Context, slugs []string) error { @@ -147,8 +147,8 @@ func (tx *Tx) TranslateCampsiteType(ctx context.Context, slug string, langTag la _, err := tx.Exec(ctx, "select translate_campsite_type($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", slug, langTag, name, spiel, info, facilities, description, additionalInfo, checkIn, checkOut) return err } -func (tx *Tx) SetCampsiteTypeCost(ctx context.Context, slug string, seasonID int, minNights int, costPerNight string) error { - _, err := tx.Exec(ctx, "select set_campsite_type_cost($1, $2, $3, $4)", slug, seasonID, minNights, costPerNight) +func (tx *Tx) SetCampsiteTypeCost(ctx context.Context, slug string, seasonID int, costPerNight string) error { + _, err := tx.Exec(ctx, "select set_campsite_type_cost($1, $2, $3)", slug, seasonID, costPerNight) return err } diff --git a/po/ca.po b/po/ca.po index 3894727..70922be 100644 --- a/po/ca.po +++ b/po/ca.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: camper\n" "Report-Msgid-Bugs-To: jordi@tandem.blog\n" -"POT-Creation-Date: 2024-01-31 15:05+0100\n" +"POT-Creation-Date: 2024-01-31 22:40+0100\n" "PO-Revision-Date: 2023-07-22 23:45+0200\n" "Last-Translator: jordi fita masA
', 5, false, true) - , (11, 2, 4, 'Type A', 'A
', 5, false, true) +insert into campsite_type (campsite_type_id, company_id, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) +values (10, 1, 3, 'Type A', 'A
', 5, '[1, 7]', false, true) + , (11, 2, 4, 'Type A', 'A
', 5, '[2, 5]', false, true) ; insert into campsite (campsite_id, company_id, label, campsite_type_id) diff --git a/test/add_campsite_feature.sql b/test/add_campsite_feature.sql index f057db2..1d63ef0 100644 --- a/test/add_campsite_feature.sql +++ b/test/add_campsite_feature.sql @@ -43,9 +43,9 @@ insert into media (media_id, company_id, original_filename, content_hash) values (3, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, dogs_allowed, max_campers) -values (4, 1, 3, 'Type A', 'A
', true, false, 4) - , (5, 1, 3, 'Type B', 'B
', true, false, 5) +insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, dogs_allowed, max_campers, bookable_nights) +values (4, 1, 3, 'Type A', 'A
', true, false, 4, '[1, 7]') + , (5, 1, 3, 'Type B', 'B
', true, false, 5, '[2, 5]') ; insert into campsite (campsite_id, company_id, label, campsite_type_id) diff --git a/test/add_campsite_type.sql b/test/add_campsite_type.sql index 9d2e798..1304273 100644 --- a/test/add_campsite_type.sql +++ b/test/add_campsite_type.sql @@ -9,15 +9,15 @@ set search_path to camper, public; select plan(13); -select has_function('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'boolean', 'boolean', 'boolean']); -select function_lang_is('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'boolean', 'boolean', 'boolean'], 'sql'); -select function_returns('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'boolean', 'boolean', 'boolean'], 'uuid'); -select isnt_definer('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'boolean', 'boolean', 'boolean']); -select volatility_is('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'boolean', 'boolean', 'boolean'], 'volatile'); -select function_privs_are('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'boolean', 'boolean', 'boolean'], 'guest', array[]::text[]); -select function_privs_are('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'boolean', 'boolean', 'boolean'], 'employee', array[]::text[]); -select function_privs_are('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'boolean', 'boolean', 'boolean'], 'admin', array['EXECUTE']); -select function_privs_are('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'boolean', 'boolean', 'boolean'], 'authenticator', array[]::text[]); +select has_function('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean']); +select function_lang_is('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean'], 'sql'); +select function_returns('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean'], 'uuid'); +select isnt_definer('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean']); +select volatility_is('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean'], 'volatile'); +select function_privs_are('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean'], 'guest', array[]::text[]); +select function_privs_are('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean'], 'employee', array[]::text[]); +select function_privs_are('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean'], 'admin', array['EXECUTE']); +select function_privs_are('camper', 'add_campsite_type', array ['integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean'], 'authenticator', array[]::text[]); set client_min_messages to warning; @@ -44,19 +44,19 @@ values (3, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a ; select lives_ok( - $$ select add_campsite_type(1, 3, 'Type A', '', 'Features
', '', 'Dunno
', '', 'After 4 p.m.', '12 a.m.', 5, true, false, true) $$, + $$ select add_campsite_type(1, 3, 'Type A', '', 'Features
', '', 'Dunno
', '', 'After 4 p.m.', '12 a.m.', 5, '[1, 7]', true, false, true) $$, 'Should be able to add a campsite type to the first company' ); select lives_ok( - $$ select add_campsite_type(2, 4, 'Type B', 'One
Two
', '', 'Pricing
', '', 'More
', 'After 9 p.m.', '9 a.m.', 2, false, true, false) $$, + $$ select add_campsite_type(2, 4, 'Type B', 'One
Two
', '', 'Pricing
', '', 'More
', 'After 9 p.m.', '9 a.m.', 2, '(1, 7)', false, true, false) $$, 'Should be able to add a campsite type to the second company' ); select bag_eq( - $$ select company_id, media_id, name, spiel::text, info::text, facilities::text, description::text, additional_info::text, check_in, check_out, active, max_campers, dogs_allowed, overflow_allowed, ask_zone_preferences from campsite_type $$, - $$ values (1, 3, 'Type A', '', 'Features
', '', 'Dunno
', '', 'After 4 p.m.', '12 a.m.', true, 5, true, false, true) - , (2, 4, 'Type B', 'One
Two
', '', 'Pricing
', '', 'More
', 'After 9 p.m.', '9 a.m.', true, 2, false, true, false) + $$ select company_id, media_id, name, spiel::text, info::text, facilities::text, description::text, additional_info::text, check_in, check_out, active, max_campers, bookable_nights, dogs_allowed, overflow_allowed, ask_zone_preferences from campsite_type $$, + $$ values (1, 3, 'Type A', '', 'Features
', '', 'Dunno
', '', 'After 4 p.m.', '12 a.m.', true, 5, int4range(1, 8), true, false, true) + , (2, 4, 'Type B', 'One
Two
', '', 'Pricing
', '', 'More
', 'After 9 p.m.', '9 a.m.', true, 2, int4range(2, 7), false, true, false) $$, 'Should have added all two campsite type' ); diff --git a/test/add_campsite_type_carousel_slide.sql b/test/add_campsite_type_carousel_slide.sql index 86633ac..8cf3d94 100644 --- a/test/add_campsite_type_carousel_slide.sql +++ b/test/add_campsite_type_carousel_slide.sql @@ -50,9 +50,9 @@ values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (6, 1, 'image.svg', sha256('')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, dogs_allowed, active) -values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, false, true) - , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, true, false) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) +values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, '[1, 7]', false, true) + , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, '[2, 6]', true, false) ; insert into campsite_type_carousel (campsite_type_id, media_id, caption) diff --git a/test/add_campsite_type_feature.sql b/test/add_campsite_type_feature.sql index 4efffe0..754c947 100644 --- a/test/add_campsite_type_feature.sql +++ b/test/add_campsite_type_feature.sql @@ -42,9 +42,9 @@ insert into media (media_id, company_id, original_filename, content_hash) values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, active, dogs_allowed, max_campers) -values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', true, false, 4) - , (4, 1, '9ae5cf87-cd69-4541-b5a5-75f937cc9e58', 2, 'Type B', 'B
', true, false, 5) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, active, dogs_allowed, max_campers, bookable_nights) +values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', true, false, 4, '[1, 7]') + , (4, 1, '9ae5cf87-cd69-4541-b5a5-75f937cc9e58', 2, 'Type B', 'B
', true, false, 5, '[2, 6]') ; select lives_ok( diff --git a/test/add_campsite_type_option.sql b/test/add_campsite_type_option.sql index 93829f3..592e765 100644 --- a/test/add_campsite_type_option.sql +++ b/test/add_campsite_type_option.sql @@ -42,9 +42,9 @@ insert into media (media_id, company_id, original_filename, content_hash) values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, active, dogs_allowed, max_campers) -values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', true, false, 4) - , (4, 1, '9ae5cf87-cd69-4541-b5a5-75f937cc9e58', 2, 'Type B', 'B
', true, false, 5) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, active, dogs_allowed, max_campers, bookable_nights) +values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', true, false, 4, '[1, 7]') + , (4, 1, '9ae5cf87-cd69-4541-b5a5-75f937cc9e58', 2, 'Type B', 'B
', true, false, 5, '[1, 6]') ; select lives_ok( diff --git a/test/booking.sql b/test/booking.sql index 9ebcb31..6330d0e 100644 --- a/test/booking.sql +++ b/test/booking.sql @@ -125,9 +125,9 @@ values (6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (8, 4, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers) -values (10, 2, 'Wooden lodge', 6, false, 7) - , (12, 4, 'Bungalow', 8, false, 6) +insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) +values (10, 2, 'Wooden lodge', 6, false, 7, '[1, 7]') + , (12, 4, 'Bungalow', 8, false, 6, '[2, 6]') ; insert into booking (company_id, campsite_type_id, holder_name, arrival_date, departure_date, number_dogs, acsi_card) diff --git a/test/campsite.sql b/test/campsite.sql index 59b52d2..850efb1 100644 --- a/test/campsite.sql +++ b/test/campsite.sql @@ -102,9 +102,9 @@ values (6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (8, 4, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, dogs_allowed, max_campers) -values (22, 2, 6, 'Wooden lodge', true, 5) - , (44, 4, 8, 'Bungalow', false, 4) +insert into campsite_type (campsite_type_id, company_id, media_id, name, dogs_allowed, max_campers, bookable_nights) +values (22, 2, 6, 'Wooden lodge', true, 5, '[1, 7]') + , (44, 4, 8, 'Bungalow', false, 4, '[2, 6]') ; insert into campsite (company_id, campsite_type_id, label) diff --git a/test/campsite_carousel.sql b/test/campsite_carousel.sql index 5461461..54c3594 100644 --- a/test/campsite_carousel.sql +++ b/test/campsite_carousel.sql @@ -93,9 +93,9 @@ values ( 6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff"," , (11, 4, 'text5.txt', sha256('content5')) ; -insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers) -values (21, 2, 'Wooden lodge', 6, false, 7) - , (22, 4, 'Bungalow', 9, false, 6) +insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) +values (21, 2, 'Wooden lodge', 6, false, 7, '[1, 7]') + , (22, 4, 'Bungalow', 9, false, 6, '[2, 6]') ; insert into campsite (campsite_id, company_id, label, campsite_type_id) diff --git a/test/campsite_feature.sql b/test/campsite_feature.sql index 0395330..6ad978c 100644 --- a/test/campsite_feature.sql +++ b/test/campsite_feature.sql @@ -89,9 +89,9 @@ values (6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (8, 4, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers) -values (16, 2, 'Wooden lodge', 6, false, 7) - , (18, 4, 'Bungalow', 8, false, 6) +insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) +values (16, 2, 'Wooden lodge', 6, false, 7, '[1, 7]') + , (18, 4, 'Bungalow', 8, false, 6, '[2, 6]') ; insert into campsite (campsite_id, company_id, label, campsite_type_id) diff --git a/test/campsite_type.sql b/test/campsite_type.sql index 11f6294..550fe0f 100644 --- a/test/campsite_type.sql +++ b/test/campsite_type.sql @@ -5,7 +5,7 @@ reset client_min_messages; begin; -select plan(106); +select plan(112); set search_path to camper, public; @@ -112,6 +112,11 @@ select col_not_null('campsite_type', 'check_out'); select col_has_default('campsite_type', 'check_out'); select col_default_is('campsite_type', 'check_out', ''); +select has_column('campsite_type', 'bookable_nights'); +select col_type_is('campsite_type', 'bookable_nights', 'int4range'); +select col_not_null('campsite_type', 'bookable_nights'); +select col_hasnt_default('campsite_type', 'bookable_nights'); + select has_column('campsite_type', 'active'); select col_type_is('campsite_type', 'active', 'boolean'); select col_not_null('campsite_type', 'active'); @@ -164,9 +169,9 @@ values (6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (8, 4, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (company_id, name, media_id, dogs_allowed, max_campers) -values (2, 'Wooden lodge', 6, false, 7) - , (4, 'Bungalow', 8, false, 6) +insert into campsite_type (company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) +values (2, 'Wooden lodge', 6, false, 7, '[1, 7]') + , (4, 'Bungalow', 8, false, 6, '[2, 6]') ; prepare campsite_type_data as @@ -187,7 +192,7 @@ reset role; select set_cookie('44facbb30d8a419dfd4bfbc44a4b5539d4970148dfc84bed0e/demo@tandem.blog', 'co2'); select lives_ok( - $$ insert into campsite_type(company_id, name, media_id, dogs_allowed, max_campers) values (2, 'Another type', 6, true, 7) $$, + $$ insert into campsite_type(company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) values (2, 'Another type', 6, true, 7, '[1, 7]') $$, 'Admin from company 2 should be able to insert a new campsite type to that company.' ); @@ -228,7 +233,7 @@ select bag_eq( ); select throws_ok( - $$ insert into campsite_type (company_id, name, media_id, dogs_allowed, max_campers) values (4, 'Another type', 6, true, 6) $$, + $$ insert into campsite_type (company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) values (4, 'Another type', 6, true, 6, '[1, 7]') $$, '42501', 'new row violates row-level security policy for table "campsite_type"', 'Admin from company 2 should NOT be able to insert new campsite types to company 4.' ); @@ -266,17 +271,29 @@ select bag_eq( ); select throws_ok( - $$ insert into campsite_type (company_id, name, media_id, dogs_allowed, max_campers) values (2, ' ', 6, false, 5) $$, + $$ insert into campsite_type (company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) values (2, ' ', 6, false, 5, '[1, 7]') $$, '23514', 'new row for relation "campsite_type" violates check constraint "name_not_empty"', 'Should not be able to insert campsite types with a blank name.' ); select throws_ok( - $$ insert into campsite_type (company_id, name, media_id, dogs_allowed, max_campers) values (2, 'Name', 6, false, 0) $$, + $$ insert into campsite_type (company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) values (2, 'Name', 6, false, 0, '[1, 7]') $$, '23514', 'new row for relation "campsite_type" violates check constraint "at_least_one_camper"', 'Should not be able to insert campsite types with no campers allowed.' ); +select throws_ok( + $$ insert into campsite_type (company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) values (2, 'Name', 6, false, 1, '[0, 7]') $$, + '23514', 'new row for relation "campsite_type" violates check constraint "at_least_one_night"', + 'Should not be able to insert campsite types that allows to book zero nights.' +); + +select throws_ok( + $$ insert into campsite_type (company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) values (2, 'Name', 6, false, 1, '[1, 1)') $$, + '23514', 'new row for relation "campsite_type" violates check constraint "at_least_one_night"', + 'Should not be able to insert campsite types with no bookable nights.' +); + reset role; diff --git a/test/campsite_type_carousel.sql b/test/campsite_type_carousel.sql index 787c649..82c6d2a 100644 --- a/test/campsite_type_carousel.sql +++ b/test/campsite_type_carousel.sql @@ -92,9 +92,9 @@ values ( 6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff"," , (11, 4, 'text5.txt', sha256('content5')) ; -insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers) -values (21, 2, 'Wooden lodge', 6, false, 7) - , (22, 4, 'Bungalow', 9, false, 6) +insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) +values (21, 2, 'Wooden lodge', 6, false, 7, '[1, 7]') + , (22, 4, 'Bungalow', 9, false, 6, '[2, 6]') ; insert into campsite_type_carousel (campsite_type_id, media_id, caption) diff --git a/test/campsite_type_cost.sql b/test/campsite_type_cost.sql index bbe91d8..72a53ac 100644 --- a/test/campsite_type_cost.sql +++ b/test/campsite_type_cost.sql @@ -5,7 +5,7 @@ reset client_min_messages; begin; -select plan(47); +select plan(42); set search_path to camper, public; @@ -36,11 +36,6 @@ select col_type_is('campsite_type_cost', 'cost_per_night', 'integer'); select col_not_null('campsite_type_cost', 'cost_per_night'); select col_hasnt_default('campsite_type_cost', 'cost_per_night'); -select has_column('campsite_type_cost', 'min_nights'); -select col_type_is('campsite_type_cost', 'min_nights', 'integer'); -select col_not_null('campsite_type_cost', 'min_nights'); -select col_hasnt_default('campsite_type_cost', 'min_nights'); - set client_min_messages to warning; truncate campsite_type_cost cascade; @@ -83,9 +78,9 @@ values (6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (8, 4, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers) -values (16, 2, 'Wooden lodge', 6, false, 7) - , (18, 4, 'Bungalow', 8, false, 6) +insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) +values (16, 2, 'Wooden lodge', 6, false, 7, '[1, 7]') + , (18, 4, 'Bungalow', 8, false, 6, '[2, 6]') ; insert into season (season_id, company_id, name) @@ -95,9 +90,9 @@ values (26, 2, 'Low') , (29, 4, 'Mid') ; -insert into campsite_type_cost (campsite_type_id, season_id, cost_per_night, min_nights) -values (16, 26, 2, 2) - , (18, 28, 4, 4) +insert into campsite_type_cost (campsite_type_id, season_id, cost_per_night) +values (16, 26, 2) + , (18, 28, 4) ; prepare campsite_season_data as @@ -118,7 +113,7 @@ reset role; select set_cookie('44facbb30d8a419dfd4bfbc44a4b5539d4970148dfc84bed0e/demo@tandem.blog', 'co2'); select lives_ok( - $$ insert into campsite_type_cost(campsite_type_id, season_id, cost_per_night, min_nights) values (16, 27, 3, 3) $$, + $$ insert into campsite_type_cost(campsite_type_id, season_id, cost_per_night) values (16, 27, 3) $$, 'Admin from company 2 should be able to insert a new campsite type season to that company.' ); @@ -159,19 +154,19 @@ select bag_eq( ); select throws_ok( - $$ insert into campsite_type_cost (campsite_type_id, season_id, cost_per_night, min_nights) values (18, 29, 5, 5) $$, + $$ insert into campsite_type_cost (campsite_type_id, season_id, cost_per_night) values (18, 29, 5) $$, '42501', 'new row violates row-level security policy for table "campsite_type_cost"', 'Admin from company 2 should NOT be able to insert new campsite type costs to company 4.' ); select throws_ok( - $$ insert into campsite_type_cost (campsite_type_id, season_id, cost_per_night, min_nights) values (18, 27, 5, 5) $$, + $$ insert into campsite_type_cost (campsite_type_id, season_id, cost_per_night) values (18, 27, 5) $$, '42501', 'new row violates row-level security policy for table "campsite_type_cost"', 'Admin from company 2 should NOT be able to insert new row with a campsite type from company 4.' ); select throws_ok( - $$ insert into campsite_type_cost (campsite_type_id, season_id, cost_per_night, min_nights) values (16, 29, 5, 5) $$, + $$ insert into campsite_type_cost (campsite_type_id, season_id, cost_per_night) values (16, 29, 5) $$, '42501', 'new row violates row-level security policy for table "campsite_type_cost"', 'Admin from company 2 should NOT be able to insert new row with a season from company 4.' ); @@ -225,16 +220,11 @@ select bag_eq( ); select throws_ok( - $$ insert into campsite_type_cost (campsite_type_id, season_id, cost_per_night, min_nights) values (16, 27, -1, 1) $$, + $$ insert into campsite_type_cost (campsite_type_id, season_id, cost_per_night) values (16, 27, -1) $$, '23514', 'new row for relation "campsite_type_cost" violates check constraint "cost_not_negative"', 'Should not be able to insert campsite type costs with negative cost per night.' ); -select throws_ok( - $$ insert into campsite_type_cost (campsite_type_id, season_id, cost_per_night, min_nights) values (16, 27, 1, 0) $$, - '23514', 'new row for relation "campsite_type_cost" violates check constraint "at_least_one_night"', - 'Should not be able to insert campsite type costs with at a night stay.' -); reset role; diff --git a/test/campsite_type_feature.sql b/test/campsite_type_feature.sql index 10db86f..e11b38c 100644 --- a/test/campsite_type_feature.sql +++ b/test/campsite_type_feature.sql @@ -88,9 +88,9 @@ values (6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (8, 4, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers) -values (16, 2, 'Wooden lodge', 6, false, 7) - , (18, 4, 'Bungalow', 8, false, 6) +insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) +values (16, 2, 'Wooden lodge', 6, false, 7, '[1, 7]') + , (18, 4, 'Bungalow', 8, false, 6, '[2, 6]') ; insert into campsite_type_feature (campsite_type_id, icon_name, name) diff --git a/test/campsite_type_option.sql b/test/campsite_type_option.sql index 6ac2f9a..37840b8 100644 --- a/test/campsite_type_option.sql +++ b/test/campsite_type_option.sql @@ -86,9 +86,9 @@ values (6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (8, 4, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers) -values (16, 2, 'Wooden lodge', 6, false, 7) - , (18, 4, 'Bungalow', 8, false, 6) +insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) +values (16, 2, 'Wooden lodge', 6, false, 7, '[1, 7]') + , (18, 4, 'Bungalow', 8, false, 6, '[2, 6]') ; insert into campsite_type_option (campsite_type_id, name, range) diff --git a/test/campsite_type_option_cost.sql b/test/campsite_type_option_cost.sql index 6719ece..0c48e94 100644 --- a/test/campsite_type_option_cost.sql +++ b/test/campsite_type_option_cost.sql @@ -79,9 +79,9 @@ values (6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (8, 4, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers) -values (16, 2, 'Wooden lodge', 6, false, 7) - , (18, 4, 'Bungalow', 8, false, 6) +insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) +values (16, 2, 'Wooden lodge', 6, false, 7, '[1, 7]') + , (18, 4, 'Bungalow', 8, false, 6, '[2, 6]') ; insert into season (season_id, company_id, name) diff --git a/test/edit_campsite.sql b/test/edit_campsite.sql index e9d774b..d7d9f95 100644 --- a/test/edit_campsite.sql +++ b/test/edit_campsite.sql @@ -40,10 +40,10 @@ insert into media (media_id, company_id, original_filename, content_hash) values (3, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, dogs_allowed, max_campers) -values (11, 1, 3, 'Type A', false, 5) - , (12, 1, 3, 'Type B', false, 5) - , (13, 1, 3, 'Type C', false, 5) +insert into campsite_type (campsite_type_id, company_id, media_id, name, dogs_allowed, max_campers, bookable_nights) +values (11, 1, 3, 'Type A', false, 5, '[1, 7]') + , (12, 1, 3, 'Type B', false, 5, '[2, 6]') + , (13, 1, 3, 'Type C', false, 5, '[3, 5]') ; insert into campsite (campsite_id, company_id, campsite_type_id, label, info1, info2, active) diff --git a/test/edit_campsite_feature.sql b/test/edit_campsite_feature.sql index 838bf5a..0be57bc 100644 --- a/test/edit_campsite_feature.sql +++ b/test/edit_campsite_feature.sql @@ -42,8 +42,8 @@ insert into media (media_id, company_id, original_filename, content_hash) values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, dogs_allowed, max_campers) -values (3, 1, 2, 'Type A', 'A
', true, false, 4) +insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, dogs_allowed, max_campers, bookable_nights) +values (3, 1, 2, 'Type A', 'A
', true, false, 4, '[1, 7]') ; insert into campsite (campsite_id, company_id, label, campsite_type_id) diff --git a/test/edit_campsite_type.sql b/test/edit_campsite_type.sql index 79e7535..eb56572 100644 --- a/test/edit_campsite_type.sql +++ b/test/edit_campsite_type.sql @@ -9,15 +9,15 @@ set search_path to camper, public; select plan(12); -select has_function('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'boolean', 'boolean', 'boolean', 'boolean']); -select function_lang_is('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'boolean', 'boolean', 'boolean', 'boolean'], 'sql'); -select function_returns('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'boolean', 'boolean', 'boolean', 'boolean'], 'uuid'); -select isnt_definer('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'boolean', 'boolean', 'boolean', 'boolean']); -select volatility_is('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'boolean', 'boolean', 'boolean', 'boolean'], 'volatile'); -select function_privs_are('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'boolean', 'boolean', 'boolean', 'boolean'], 'guest', array[]::text[]); -select function_privs_are('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'boolean', 'boolean', 'boolean', 'boolean'], 'employee', array[]::text[]); -select function_privs_are('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'boolean', 'boolean', 'boolean', 'boolean'], 'admin', array['EXECUTE']); -select function_privs_are('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'boolean', 'boolean', 'boolean', 'boolean'], 'authenticator', array[]::text[]); +select has_function('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean', 'boolean']); +select function_lang_is('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean', 'boolean'], 'sql'); +select function_returns('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean', 'boolean'], 'uuid'); +select isnt_definer('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean', 'boolean']); +select volatility_is('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean', 'boolean'], 'volatile'); +select function_privs_are('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean', 'boolean'], 'guest', array[]::text[]); +select function_privs_are('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean', 'boolean'], 'employee', array[]::text[]); +select function_privs_are('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean', 'boolean'], 'admin', array['EXECUTE']); +select function_privs_are('camper', 'edit_campsite_type', array ['uuid', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'int4range', 'boolean', 'boolean', 'boolean', 'boolean'], 'authenticator', array[]::text[]); set client_min_messages to warning; truncate campsite_type cascade; @@ -43,25 +43,25 @@ values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (4, 1, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffff00","a"};')) ; -insert into campsite_type (company_id, slug, media_id, name, spiel, info, facilities, description, additional_info, check_in, check_out, max_campers, dogs_allowed, overflow_allowed, ask_zone_preferences, active) -values (1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'info 1
', 'facilities A
', 'A
', 'Additional A
', '', '', 5, false, true, false, true) - , (1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'info 2
', 'facilities B
', 'B
', 'Additional B
', '', '', 4, true, false, true, false) +insert into campsite_type (company_id, slug, media_id, name, spiel, info, facilities, description, additional_info, check_in, check_out, max_campers, bookable_nights, dogs_allowed, overflow_allowed, ask_zone_preferences, active) +values (1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'info 1
', 'facilities A
', 'A
', 'Additional A
', '', '', 5, '[1, 7]', false, true, false, true) + , (1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'info 2
', 'facilities B
', 'B
', 'Additional B
', '', '', 4, '[2, 6]', true, false, true, false) ; select lives_ok( - $$ select edit_campsite_type('87452b88-b48f-48d3-bb6c-0296de64164e', 4, 'Type 1', 'Features A
', 'Pricing 1
', '1
', 'Additional 1
', 'Check-in 1', 'Check-out 1', 2, true, false, true, false) $$, + $$ select edit_campsite_type('87452b88-b48f-48d3-bb6c-0296de64164e', 4, 'Type 1', 'Features A
', 'Pricing 1
', '1
', 'Additional 1
', 'Check-in 1', 'Check-out 1', 2, '(1, 7)', true, false, true, false) $$, 'Should be able to edit the first type' ); select lives_ok( - $$ select edit_campsite_type('9b6370f7-f941-46f2-bc6e-de455675bd0a', null, 'Type 2', 'Features B
', 'Pricing 2
', '2
', 'Additional 2
', 'Check-in 2', 'Check-out 2', 9, false, true, false, true) $$, + $$ select edit_campsite_type('9b6370f7-f941-46f2-bc6e-de455675bd0a', null, 'Type 2', 'Features B
', 'Pricing 2
', '2
', 'Additional 2
', 'Check-in 2', 'Check-out 2', 9, '(2, 6)', false, true, false, true) $$, 'Should be able to edit the second type' ); select bag_eq( - $$ select slug::text, media_id, name, spiel::text, info::text, facilities::text, description::text, additional_info::text, check_in, check_out, max_campers, dogs_allowed, overflow_allowed, ask_zone_preferences, active from campsite_type $$, - $$ values ('87452b88-b48f-48d3-bb6c-0296de64164e', 4, 'Type 1', 'Features A
', 'Pricing 1
', '1
', 'Additional 1
', 'Check-in 1', 'Check-out 1', 2, true, false, true, false) - , ('9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type 2', 'Features B
', 'Pricing 2
', '2
', 'Additional 2
', 'Check-in 2', 'Check-out 2', 9, false, true, false, true) + $$ select slug::text, media_id, name, spiel::text, info::text, facilities::text, description::text, additional_info::text, check_in, check_out, max_campers, bookable_nights, dogs_allowed, overflow_allowed, ask_zone_preferences, active from campsite_type $$, + $$ values ('87452b88-b48f-48d3-bb6c-0296de64164e', 4, 'Type 1', 'Features A
', 'Pricing 1
', '1
', 'Additional 1
', 'Check-in 1', 'Check-out 1', 2, int4range(2, 7), true, false, true, false) + , ('9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type 2', 'Features B
', 'Pricing 2
', '2
', 'Additional 2
', 'Check-in 2', 'Check-out 2', 9, int4range(3, 6), false, true, false, true) $$, 'Should have updated all campsite types.' ); diff --git a/test/edit_campsite_type_feature.sql b/test/edit_campsite_type_feature.sql index 457442c..148c65e 100644 --- a/test/edit_campsite_type_feature.sql +++ b/test/edit_campsite_type_feature.sql @@ -42,8 +42,8 @@ insert into media (media_id, company_id, original_filename, content_hash) values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, dogs_allowed, max_campers) -values (3, 1, 2, 'Type A', 'A
', true, false, 4) +insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, dogs_allowed, max_campers, bookable_nights) +values (3, 1, 2, 'Type A', 'A
', true, false, 4, '[1, 7]') ; insert into campsite_type_feature (campsite_type_feature_id, campsite_type_id, icon_name, name) diff --git a/test/edit_campsite_type_option.sql b/test/edit_campsite_type_option.sql index d410438..b25d57a 100644 --- a/test/edit_campsite_type_option.sql +++ b/test/edit_campsite_type_option.sql @@ -42,8 +42,8 @@ insert into media (media_id, company_id, original_filename, content_hash) values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, dogs_allowed, max_campers) -values (3, 1, 2, 'Type A', 'A
', true, false, 4) +insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, dogs_allowed, max_campers, bookable_nights) +values (3, 1, 2, 'Type A', 'A
', true, false, 4, '[1, 7]') ; insert into campsite_type_option (campsite_type_option_id, campsite_type_id, name, range) diff --git a/test/order_campsite_carousel.sql b/test/order_campsite_carousel.sql index 1bfff74..f27c033 100644 --- a/test/order_campsite_carousel.sql +++ b/test/order_campsite_carousel.sql @@ -56,9 +56,9 @@ values ( 3, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff"," , (12, 1, 'image.svg', sha256('')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, description, max_campers, dogs_allowed, active) -values (13, 1, 3, 'Type A', 'A
', 5, false, true) - , (14, 2, 8, 'Type B', 'B
', 4, true, false) +insert into campsite_type (campsite_type_id, company_id, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) +values (13, 1, 3, 'Type A', 'A
', 5, '[1, 7]', false, true) + , (14, 2, 8, 'Type B', 'B
', 4, '[2, 6]', true, false) ; insert into campsite (campsite_id, company_id, label, campsite_type_id) diff --git a/test/order_campsite_features.sql b/test/order_campsite_features.sql index 9ad0d3a..19645d3 100644 --- a/test/order_campsite_features.sql +++ b/test/order_campsite_features.sql @@ -42,8 +42,8 @@ insert into media (media_id, company_id, original_filename, content_hash) values (6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers) -values (16, 2, 'Wooden lodge', 6, false, 7) +insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) +values (16, 2, 'Wooden lodge', 6, false, 7, '[1, 7]') ; insert into campsite (campsite_id, company_id, label, campsite_type_id) diff --git a/test/order_campsite_type_carousel.sql b/test/order_campsite_type_carousel.sql index e81d6b8..15e9949 100644 --- a/test/order_campsite_type_carousel.sql +++ b/test/order_campsite_type_carousel.sql @@ -50,9 +50,9 @@ values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (6, 1, 'image.svg', sha256('')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, dogs_allowed, active) -values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, false, true) - , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, true, false) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) +values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, '[1, 7]', false, true) + , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, '[2, 6]', true, false) ; insert into campsite_type_carousel (campsite_type_id, media_id, caption) diff --git a/test/order_campsite_type_features.sql b/test/order_campsite_type_features.sql index 8b48a77..12c5e2e 100644 --- a/test/order_campsite_type_features.sql +++ b/test/order_campsite_type_features.sql @@ -56,8 +56,8 @@ insert into media (media_id, company_id, original_filename, content_hash) values (6, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers) -values (16, 2, 'Wooden lodge', 6, false, 7) +insert into campsite_type (campsite_type_id, company_id, name, media_id, dogs_allowed, max_campers, bookable_nights) +values (16, 2, 'Wooden lodge', 6, false, 7, '[1, 7]') ; insert into campsite_type_feature (campsite_type_feature_id, campsite_type_id, icon_name, name) diff --git a/test/order_campsite_type_options.sql b/test/order_campsite_type_options.sql index c1d7fa8..2192029 100644 --- a/test/order_campsite_type_options.sql +++ b/test/order_campsite_type_options.sql @@ -42,8 +42,8 @@ insert into media (media_id, company_id, original_filename, content_hash) values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, dogs_allowed, max_campers) -values (3, 1, 2, 'Type A', 'A
', true, false, 4) +insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, dogs_allowed, max_campers, bookable_nights) +values (3, 1, 2, 'Type A', 'A
', true, false, 4, '[1, 7]') ; insert into campsite_type_option (campsite_type_option_id, campsite_type_id, name, range) diff --git a/test/order_campsite_types.sql b/test/order_campsite_types.sql index 3c2411a..97ced20 100644 --- a/test/order_campsite_types.sql +++ b/test/order_campsite_types.sql @@ -40,12 +40,12 @@ insert into media (media_id, company_id, original_filename, content_hash) values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (company_id, slug, media_id, name, spiel, info, facilities, description, max_campers, dogs_allowed, active) -values (1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'A', '', '', '', '', 5, false, true) - , (1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 2, 'B', '', '', '', '', 5, false, true) - , (1, 'b33cfbc9-fbcc-4aac-8335-e5f94ea7e6b2', 2, 'C', '', '', '', '', 5, false, true) - , (1, '8c4465ec-a690-43d7-854b-7fcd35fccb1c', 2, 'D', '', '', '', '', 5, false, true) - , (1, 'd28c30fb-57ac-4243-a8c3-ad1a26637f5a', 2, 'E', '', '', '', '', 5, false, true) +insert into campsite_type (company_id, slug, media_id, name, spiel, info, facilities, description, max_campers, bookable_nights, dogs_allowed, active) +values (1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'A', '', '', '', '', 5, '[1, 7]', false, true) + , (1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 2, 'B', '', '', '', '', 5, '[2, 6]', false, true) + , (1, 'b33cfbc9-fbcc-4aac-8335-e5f94ea7e6b2', 2, 'C', '', '', '', '', 5, '[3, 5]', false, true) + , (1, '8c4465ec-a690-43d7-854b-7fcd35fccb1c', 2, 'D', '', '', '', '', 5, '[4, 8]', false, true) + , (1, 'd28c30fb-57ac-4243-a8c3-ad1a26637f5a', 2, 'E', '', '', '', '', 5, '[5, 9]', false, true) ; select lives_ok( diff --git a/test/remove_campsite_carousel_slide.sql b/test/remove_campsite_carousel_slide.sql index 8946f47..6f70df4 100644 --- a/test/remove_campsite_carousel_slide.sql +++ b/test/remove_campsite_carousel_slide.sql @@ -51,9 +51,9 @@ values (3, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (7, 2, 'image.svg', sha256('')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, description, max_campers, dogs_allowed, active) -values (10, 1, 3, 'Type A', 'A
', 5, false, true) - , (11, 2, 7, 'Type B', 'B
', 4, true, false) +insert into campsite_type (campsite_type_id, company_id, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) +values (10, 1, 3, 'Type A', 'A
', 5, '[1, 7]', false, true) + , (11, 2, 7, 'Type B', 'B
', 4, '[2, 6]', true, false) ; insert into campsite (campsite_id, label, company_id, campsite_type_id) diff --git a/test/remove_campsite_feature.sql b/test/remove_campsite_feature.sql index 77ff46c..f036da6 100644 --- a/test/remove_campsite_feature.sql +++ b/test/remove_campsite_feature.sql @@ -47,8 +47,8 @@ values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (3, 1, 'cover3.xpm', sha256('static char *s[]={"1 1 1 1","a c #ff00ff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, dogs_allowed, active) -values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, false, true) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) +values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, '[1, 7]', false, true) ; insert into campsite (campsite_id, company_id, label, campsite_type_id) diff --git a/test/remove_campsite_type_carousel_slide.sql b/test/remove_campsite_type_carousel_slide.sql index bfcd7ea..957028a 100644 --- a/test/remove_campsite_type_carousel_slide.sql +++ b/test/remove_campsite_type_carousel_slide.sql @@ -48,9 +48,9 @@ values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (6, 1, 'image.svg', sha256('')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, dogs_allowed, active) -values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, false, true) - , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, true, false) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) +values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, '[1, 7]', false, true) + , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, '[2, 6]', true, false) ; insert into campsite_type_carousel (campsite_type_id, media_id, caption) diff --git a/test/remove_campsite_type_feature.sql b/test/remove_campsite_type_feature.sql index 0f5b56a..8b950a3 100644 --- a/test/remove_campsite_type_feature.sql +++ b/test/remove_campsite_type_feature.sql @@ -46,9 +46,9 @@ values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (3, 1, 'cover3.xpm', sha256('static char *s[]={"1 1 1 1","a c #ff00ff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, dogs_allowed, active) -values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, false, true) - , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, true, false) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) +values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, '[1, 7]', false, true) + , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, '[2, 6]', true, false) ; insert into campsite_type_feature (campsite_type_feature_id, campsite_type_id, icon_name, name) diff --git a/test/remove_campsite_type_option.sql b/test/remove_campsite_type_option.sql index bc5cd65..4216c77 100644 --- a/test/remove_campsite_type_option.sql +++ b/test/remove_campsite_type_option.sql @@ -47,9 +47,9 @@ values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (3, 1, 'cover3.xpm', sha256('static char *s[]={"1 1 1 1","a c #ff00ff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, dogs_allowed, active) -values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, false, true) - , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, true, false) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) +values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, '[1, 7]', false, true) + , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, '[2, 6]', true, false) ; insert into campsite_type_option (campsite_type_option_id, campsite_type_id, name, range) diff --git a/test/set_campsite_type_cost.sql b/test/set_campsite_type_cost.sql index 1aa5598..a9f0bd8 100644 --- a/test/set_campsite_type_cost.sql +++ b/test/set_campsite_type_cost.sql @@ -9,15 +9,15 @@ select plan(13); set search_path to camper, public; -select has_function('camper', 'set_campsite_type_cost', array['uuid', 'integer', 'integer', 'text', 'integer']); -select function_lang_is('camper', 'set_campsite_type_cost', array['uuid', 'integer', 'integer', 'text', 'integer'], 'sql'); -select function_returns('camper', 'set_campsite_type_cost', array['uuid', 'integer', 'integer', 'text', 'integer'], 'void'); -select isnt_definer('camper', 'set_campsite_type_cost', array['uuid', 'integer', 'integer', 'text', 'integer']); -select volatility_is('camper', 'set_campsite_type_cost', array['uuid', 'integer', 'integer', 'text', 'integer'], 'volatile'); -select function_privs_are('camper', 'set_campsite_type_cost', array ['uuid', 'integer', 'integer', 'text', 'integer'], 'guest', array[]::text[]); -select function_privs_are('camper', 'set_campsite_type_cost', array ['uuid', 'integer', 'integer', 'text', 'integer'], 'employee', array[]::text[]); -select function_privs_are('camper', 'set_campsite_type_cost', array ['uuid', 'integer', 'integer', 'text', 'integer'], 'admin', array['EXECUTE']); -select function_privs_are('camper', 'set_campsite_type_cost', array ['uuid', 'integer', 'integer', 'text', 'integer'], 'authenticator', array[]::text[]); +select has_function('camper', 'set_campsite_type_cost', array['uuid', 'integer', 'text', 'integer']); +select function_lang_is('camper', 'set_campsite_type_cost', array['uuid', 'integer', 'text', 'integer'], 'sql'); +select function_returns('camper', 'set_campsite_type_cost', array['uuid', 'integer', 'text', 'integer'], 'void'); +select isnt_definer('camper', 'set_campsite_type_cost', array['uuid', 'integer', 'text', 'integer']); +select volatility_is('camper', 'set_campsite_type_cost', array['uuid', 'integer', 'text', 'integer'], 'volatile'); +select function_privs_are('camper', 'set_campsite_type_cost', array ['uuid', 'integer', 'text', 'integer'], 'guest', array[]::text[]); +select function_privs_are('camper', 'set_campsite_type_cost', array ['uuid', 'integer', 'text', 'integer'], 'employee', array[]::text[]); +select function_privs_are('camper', 'set_campsite_type_cost', array ['uuid', 'integer', 'text', 'integer'], 'admin', array['EXECUTE']); +select function_privs_are('camper', 'set_campsite_type_cost', array ['uuid', 'integer', 'text', 'integer'], 'authenticator', array[]::text[]); set client_min_messages to warning; truncate campsite_type_cost cascade; @@ -41,8 +41,8 @@ insert into media (media_id, company_id, original_filename, content_hash) values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, dogs_allowed, active) -values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', '', 5, false, true) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) +values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', '', 5, '[1, 7]', false, true) ; insert into season (season_id, company_id, name) @@ -51,31 +51,31 @@ values (4, 1, 'High') , (6, 1, 'Low') ; -insert into campsite_type_cost (campsite_type_id, season_id, cost_per_night, min_nights) -values (3, 4, 44, 4) - , (3, 5, 55, 5) +insert into campsite_type_cost (campsite_type_id, season_id, cost_per_night) +values (3, 4, 44) + , (3, 5, 55) ; select lives_ok( - $$ select set_campsite_type_cost('87452b88-b48f-48d3-bb6c-0296de64164e', 4, 2, '12.34') $$, + $$ select set_campsite_type_cost('87452b88-b48f-48d3-bb6c-0296de64164e', 4, '12.34') $$, 'Should be able to edit the cost for high season' ); select lives_ok( - $$ select set_campsite_type_cost('87452b88-b48f-48d3-bb6c-0296de64164e', 5, 6, '0.0') $$, + $$ select set_campsite_type_cost('87452b88-b48f-48d3-bb6c-0296de64164e', 5, '0.0') $$, 'Should be able to set the cost for mid season to zero' ); select lives_ok( - $$ select set_campsite_type_cost('87452b88-b48f-48d3-bb6c-0296de64164e', 6, 1, '3.21') $$, + $$ select set_campsite_type_cost('87452b88-b48f-48d3-bb6c-0296de64164e', 6, '3.21') $$, 'Should be able to set the cost for low season, adding it.' ); select bag_eq( - $$ select campsite_type_id, season_id, cost_per_night, min_nights from campsite_type_cost $$, - $$ values (3, 4, 1234, 2) - , (3, 5, 0, 6) - , (3, 6, 321, 1) + $$ select campsite_type_id, season_id, cost_per_night from campsite_type_cost $$, + $$ values (3, 4, 1234) + , (3, 5, 0) + , (3, 6, 321) $$, 'Should have updated all campsite type costs.' ); diff --git a/test/set_campsite_type_option_cost.sql b/test/set_campsite_type_option_cost.sql index f0d48f6..9b60047 100644 --- a/test/set_campsite_type_option_cost.sql +++ b/test/set_campsite_type_option_cost.sql @@ -43,8 +43,8 @@ insert into media (media_id, company_id, original_filename, content_hash) values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, dogs_allowed, active) -values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', '', 5, false, true) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) +values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', '', 5, '[1, 7]', false, true) ; insert into season (season_id, company_id, name) diff --git a/test/translate_campsite.sql b/test/translate_campsite.sql index 31e9d94..f6be704 100644 --- a/test/translate_campsite.sql +++ b/test/translate_campsite.sql @@ -42,8 +42,8 @@ insert into media (media_id, company_id, original_filename, content_hash) values (3, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, dogs_allowed, max_campers) -values (11, 1, 3, 'Type A', false, 5) +insert into campsite_type (campsite_type_id, company_id, media_id, name, dogs_allowed, max_campers, bookable_nights) +values (11, 1, 3, 'Type A', false, 5, '[1, 7]') ; insert into campsite (campsite_id, company_id, campsite_type_id, label, info1, info2, active) diff --git a/test/translate_campsite_carousel_slide.sql b/test/translate_campsite_carousel_slide.sql index 7879c97..f2d6451 100644 --- a/test/translate_campsite_carousel_slide.sql +++ b/test/translate_campsite_carousel_slide.sql @@ -51,9 +51,9 @@ values (3, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (7, 2, 'image.svg', sha256('')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, description, max_campers, dogs_allowed, active) -values (10, 1, 3, 'Type A', 'A
', 5, false, true) - , (11, 2, 7, 'Type B', 'B
', 7, true, false) +insert into campsite_type (campsite_type_id, company_id, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) +values (10, 1, 3, 'Type A', 'A
', 5, '[1, 7]', false, true) + , (11, 2, 7, 'Type B', 'B
', 7, '[2, 6]', true, false) ; insert into campsite (campsite_id, label, company_id, campsite_type_id) diff --git a/test/translate_campsite_feature.sql b/test/translate_campsite_feature.sql index 79beb11..b178a95 100644 --- a/test/translate_campsite_feature.sql +++ b/test/translate_campsite_feature.sql @@ -42,8 +42,8 @@ insert into media (media_id, company_id, original_filename, content_hash) values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, dogs_allowed, max_campers) -values (3, 1, 2, 'Type A', 'A
', true, false, 4) +insert into campsite_type (campsite_type_id, company_id, media_id, name, description, active, dogs_allowed, max_campers, bookable_nights) +values (3, 1, 2, 'Type A', 'A
', true, false, 4, '[1, 7]') ; insert into campsite (campsite_id, company_id, label, campsite_type_id) diff --git a/test/translate_campsite_type.sql b/test/translate_campsite_type.sql index 3b134fd..42c9f07 100644 --- a/test/translate_campsite_type.sql +++ b/test/translate_campsite_type.sql @@ -43,9 +43,9 @@ values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (4, 1, 'cover4.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffff00","a"};')) ; -insert into campsite_type (company_id, slug, media_id, name, spiel, info, facilities, description, additional_info, check_in, check_out, active, dogs_allowed, max_campers) -values (1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'Features A
', 'Pricing A
', 'A
', 'Additional A
', '', '', true, false, 4) - , (1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'Features B
', 'Pricing B
', 'B
', 'Additional B
', '', '', false, true, 5) +insert into campsite_type (company_id, slug, media_id, name, spiel, info, facilities, description, additional_info, check_in, check_out, active, dogs_allowed, max_campers, bookable_nights) +values (1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'Features A
', 'Pricing A
', 'A
', 'Additional A
', '', '', true, false, 4, '[1, 7]') + , (1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'Features B
', 'Pricing B
', 'B
', 'Additional B
', '', '', false, true, 5, '[2, 6]') ; insert into campsite_type_i18n (campsite_type_id, lang_tag, name, spiel, info, facilities, description, additional_info, check_in, check_out) diff --git a/test/translate_campsite_type_carousel_slide.sql b/test/translate_campsite_type_carousel_slide.sql index a6204eb..96c29d0 100644 --- a/test/translate_campsite_type_carousel_slide.sql +++ b/test/translate_campsite_type_carousel_slide.sql @@ -48,9 +48,9 @@ values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a , (6, 1, 'image.svg', sha256('')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, dogs_allowed, active) -values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, false, true) - , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, true, false) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, max_campers, bookable_nights, dogs_allowed, active) +values (10, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', 5, '[1, 7]', false, true) + , (11, 1, '9b6370f7-f941-46f2-bc6e-de455675bd0a', 3, 'Type B', 'B
', 4, '[2, 6]', true, false) ; insert into campsite_type_carousel (campsite_type_id, media_id, caption) diff --git a/test/translate_campsite_type_feature.sql b/test/translate_campsite_type_feature.sql index 6359b1c..d41412d 100644 --- a/test/translate_campsite_type_feature.sql +++ b/test/translate_campsite_type_feature.sql @@ -41,8 +41,8 @@ insert into media (media_id, company_id, original_filename, content_hash) values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, active, dogs_allowed, max_campers) -values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', true, false, 4) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, active, dogs_allowed, max_campers, bookable_nights) +values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', true, false, 4, '[1, 7]') ; insert into campsite_type_feature (campsite_type_feature_id, campsite_type_id, icon_name, name) diff --git a/test/translate_campsite_type_option.sql b/test/translate_campsite_type_option.sql index 5ff1358..c8186f5 100644 --- a/test/translate_campsite_type_option.sql +++ b/test/translate_campsite_type_option.sql @@ -41,8 +41,8 @@ insert into media (media_id, company_id, original_filename, content_hash) values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) ; -insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, active, dogs_allowed, max_campers) -values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', true, false, 4) +insert into campsite_type (campsite_type_id, company_id, slug, media_id, name, description, active, dogs_allowed, max_campers, bookable_nights) +values (3, 1, '87452b88-b48f-48d3-bb6c-0296de64164e', 2, 'Type A', 'A
', true, false, 4, '[1, 7]') ; insert into campsite_type_option (campsite_type_option_id, campsite_type_id, name, range) diff --git a/verify/add_campsite_type.sql b/verify/add_campsite_type.sql index 53e3e64..707916e 100644 --- a/verify/add_campsite_type.sql +++ b/verify/add_campsite_type.sql @@ -2,6 +2,6 @@ begin; -select has_function_privilege('camper.add_campsite_type(integer, integer, text, text, text, text, text, text, text, text, integer, boolean, boolean, boolean)', 'execute'); +select has_function_privilege('camper.add_campsite_type(integer, integer, text, text, text, text, text, text, text, text, integer, int4range, boolean, boolean, boolean)', 'execute'); rollback; diff --git a/verify/add_campsite_type@v3.sql b/verify/add_campsite_type@v3.sql new file mode 100644 index 0000000..53e3e64 --- /dev/null +++ b/verify/add_campsite_type@v3.sql @@ -0,0 +1,7 @@ +-- Verify camper:add_campsite_type on pg + +begin; + +select has_function_privilege('camper.add_campsite_type(integer, integer, text, text, text, text, text, text, text, text, integer, boolean, boolean, boolean)', 'execute'); + +rollback; diff --git a/verify/campsite_type__bookable_nights.sql b/verify/campsite_type__bookable_nights.sql new file mode 100644 index 0000000..eef996d --- /dev/null +++ b/verify/campsite_type__bookable_nights.sql @@ -0,0 +1,10 @@ +-- Verify camper:campsite_type__bookable_nights on pg + +begin; + +select bookable_nights +from camper.campsite_type +where false +; + +rollback; diff --git a/verify/campsite_type_cost__-min_nights.sql b/verify/campsite_type_cost__-min_nights.sql new file mode 100644 index 0000000..948308c --- /dev/null +++ b/verify/campsite_type_cost__-min_nights.sql @@ -0,0 +1,11 @@ +-- Verify camper:campsite_type_cost__-min_nights on pg + +begin; + +select 1 / (1 - count(*)) +from pg_attribute +where attrelid = 'camper.campsite_type_cost'::regclass + and attname = 'min_nights' +; + +rollback; diff --git a/verify/edit_campsite_type.sql b/verify/edit_campsite_type.sql index a2870bb..71bc5ba 100644 --- a/verify/edit_campsite_type.sql +++ b/verify/edit_campsite_type.sql @@ -2,6 +2,6 @@ begin; -select has_function_privilege('camper.edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, boolean, boolean, boolean, boolean)', 'execute'); +select has_function_privilege('camper.edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, int4range, boolean, boolean, boolean, boolean)', 'execute'); rollback; diff --git a/verify/edit_campsite_type@v3.sql b/verify/edit_campsite_type@v3.sql new file mode 100644 index 0000000..a2870bb --- /dev/null +++ b/verify/edit_campsite_type@v3.sql @@ -0,0 +1,7 @@ +-- Verify camper:edit_campsite_type on pg + +begin; + +select has_function_privilege('camper.edit_campsite_type(uuid, integer, text, text, text, text, text, text, text, text, integer, boolean, boolean, boolean, boolean)', 'execute'); + +rollback; diff --git a/verify/set_campsite_type_cost.sql b/verify/set_campsite_type_cost.sql index df882b3..f89f497 100644 --- a/verify/set_campsite_type_cost.sql +++ b/verify/set_campsite_type_cost.sql @@ -2,6 +2,6 @@ begin; -select has_function_privilege('camper.set_campsite_type_cost(uuid, integer, integer, text, integer)', 'execute'); +select has_function_privilege('camper.set_campsite_type_cost(uuid, integer, text, integer)', 'execute'); rollback; diff --git a/verify/set_campsite_type_cost@v3.sql b/verify/set_campsite_type_cost@v3.sql new file mode 100644 index 0000000..df882b3 --- /dev/null +++ b/verify/set_campsite_type_cost@v3.sql @@ -0,0 +1,7 @@ +-- Verify camper:set_campsite_type_cost on pg + +begin; + +select has_function_privilege('camper.set_campsite_type_cost(uuid, integer, integer, text, integer)', 'execute'); + +rollback; diff --git a/web/static/booking-dates.js b/web/static/booking-dates.js index 84f002d..4df951a 100644 --- a/web/static/booking-dates.js +++ b/web/static/booking-dates.js @@ -11,7 +11,8 @@ return; } - arrivalDate.setUTCDate(arrivalDate.getUTCDate() + 1); + const minNights = Math.max(1, parseInt(departureDateField.dataset.minNights, 10)); + arrivalDate.setUTCDate(arrivalDate.getUTCDate() + minNights); const minDate = formatDate(arrivalDate); departureDateField.setAttribute('min', minDate); @@ -20,11 +21,14 @@ departureDateField.value = minDate; } - arrivalDate.setUTCDate(arrivalDate.getUTCDate() + 6); - const maxDate = formatDate(arrivalDate); - departureDateField.setAttribute('max', maxDate); - if (!isNaN(departureDate) && departureDate >= arrivalDate) { - departureDateField.value = maxDate; + const maxNights = parseInt(departureDateField.dataset.maxNights, 10); + if (maxNights > 0) { + arrivalDate.setUTCDate(arrivalDate.getUTCDate() + maxNights - minNights); + const maxDate = formatDate(arrivalDate); + departureDateField.setAttribute('max', maxDate); + if (!isNaN(departureDate) && departureDate >= arrivalDate) { + departureDateField.value = maxDate; + } } } diff --git a/web/templates/admin/campsite/type/form.gohtml b/web/templates/admin/campsite/type/form.gohtml index 655c912..d7e3a46 100644 --- a/web/templates/admin/campsite/type/form.gohtml +++ b/web/templates/admin/campsite/type/form.gohtml @@ -88,6 +88,22 @@ {{ template "error-message" . }} {{- end }} + {{ with .MinNights -}} + + {{- end }} + {{ with .MaxNights -}} + + {{- end }} {{- end }} diff --git a/web/templates/public/campsite/type.gohtml b/web/templates/public/campsite/type.gohtml index d99ae92..19fa605 100644 --- a/web/templates/public/campsite/type.gohtml +++ b/web/templates/public/campsite/type.gohtml @@ -46,7 +46,9 @@ @@ -90,8 +92,8 @@ {{ range .Options }}