From 7edf3a3ed19403836310538b461970d52bdd415e Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Mon, 29 Apr 2024 17:49:38 +0200 Subject: [PATCH] =?UTF-8?q?Pre-fill=20all=20guests=20with=20the=20holder?= =?UTF-8?q?=E2=80=99s=20address?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most will be families living at the same address. And, if they are not, it is far easier to replace the incorrect address with the actual, rather than write the same address to all family members under the same household. --- pkg/booking/checkin.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/pkg/booking/checkin.go b/pkg/booking/checkin.go index 0f6ce93..9b80d58 100644 --- a/pkg/booking/checkin.go +++ b/pkg/booking/checkin.go @@ -96,7 +96,7 @@ func (f *checkInForm) FillFromDatabase(ctx context.Context, conn *database.Conn, } defer rows.Close() for rows.Next() { - guest := newGuestFormWithOptions(documentTypes, sexes, countries, nil) + guest := newGuestFormWithOptions(documentTypes, sexes, countries, "", nil) if err := guest.FillFromRow(rows); err != nil { return err } @@ -104,14 +104,15 @@ func (f *checkInForm) FillFromDatabase(ctx context.Context, conn *database.Conn, } if len(f.Guests) == 0 { var numberGuests int + var address string var country []string - row := conn.QueryRow(ctx, "select number_adults + number_teenagers, array[coalesce(country_code, '')] from booking where slug = $1", f.Slug) - if err = row.Scan(&numberGuests, &country); err != nil { + row := conn.QueryRow(ctx, "select number_adults + number_teenagers, coalesce(address, ''), array[coalesce(country_code, '')] from booking where slug = $1", f.Slug) + if err = row.Scan(&numberGuests, &address, &country); err != nil { return err } guests := make([]*guestForm, 0, numberGuests) for i := 0; i < numberGuests; i++ { - guests = append(guests, newGuestFormWithOptions(documentTypes, sexes, countries, country)) + guests = append(guests, newGuestFormWithOptions(documentTypes, sexes, countries, address, country)) } f.Guests = guests } @@ -131,13 +132,13 @@ func (f *checkInForm) Parse(r *http.Request, user *auth.User, conn *database.Con sexes := mustGetSexOptions(r.Context(), conn, user.Locale) countries := form.MustGetCountryOptions(r.Context(), conn, user.Locale) - guest := newGuestFormWithOptions(documentTypes, sexes, countries, nil) + guest := newGuestFormWithOptions(documentTypes, sexes, countries, "", nil) count := guest.count(r) f.Guests = make([]*guestForm, 0, count) guest.FillValueIndex(r, 0) f.Guests = append(f.Guests, guest) for i := 1; i < count; i++ { - guest = newGuestFormWithOptions(documentTypes, sexes, countries, nil) + guest = newGuestFormWithOptions(documentTypes, sexes, countries, "", nil) guest.FillValueIndex(r, i) f.Guests = append(f.Guests, guest) } @@ -180,15 +181,16 @@ func newGuestForm(ctx context.Context, conn *database.Conn, l *locale.Locale, sl sexes := mustGetSexOptions(ctx, conn, l) countries := form.MustGetCountryOptions(ctx, conn, l) + var address string var country []string - row := conn.QueryRow(ctx, "select array[coalesce(country_code, '')] from booking where slug = $1", slug) - if err := row.Scan(&country); err != nil { + row := conn.QueryRow(ctx, "select coalesce(address, ''), array[coalesce(country_code, '')] from booking where slug = $1", slug) + if err := row.Scan(&address, &country); err != nil { return nil, err } - return newGuestFormWithOptions(documentTypes, sexes, countries, country), nil + return newGuestFormWithOptions(documentTypes, sexes, countries, address, country), nil } -func newGuestFormWithOptions(documentTypes []*form.Option, sexes []*form.Option, countries []*form.Option, selectedCountry []string) *guestForm { +func newGuestFormWithOptions(documentTypes []*form.Option, sexes []*form.Option, countries []*form.Option, address string, selectedCountry []string) *guestForm { return &guestForm{ IDDocumentType: &form.Select{ Name: "id_document_type", @@ -223,6 +225,7 @@ func newGuestFormWithOptions(documentTypes []*form.Option, sexes []*form.Option, }, Address: &form.Input{ Name: "address", + Val: address, }, Phone: &form.Input{ Name: "phone",