campingmontagut/pkg/auth/company.go
jordi fita mas e59e6a2a42 Move the locales parameter inside Company struct.
I realized that locales should be company-dependent: we could have two
companies that show pages in a different subset of the application
locales.  It is not the case now, because despite being a “multicompany
application”, it is intended for a single customer, but still makes
sense to include it in Company, even if the subset is the same set as
the application’s.
2023-08-07 10:53:42 +02:00

35 lines
657 B
Go

/*
* SPDX-FileCopyrightText: 2023 jordi fita mas <jfita@peritasoft.com>
* SPDX-License-Identifier: AGPL-3.0-only
*/
package auth
import (
"context"
"dev.tandem.ws/tandem/camper/pkg/database"
"dev.tandem.ws/tandem/camper/pkg/locale"
)
type Company struct {
ID int
Locales locale.Locales
}
func CompanyByHost(ctx context.Context, conn *database.Conn, host string, allLocales locale.Locales) (*Company, error) {
company := &Company{
Locales: allLocales,
}
if err := conn.QueryRow(ctx, `
select company_id
from company_host
where host = $1
`, host).Scan(
&company.ID,
); err != nil {
return nil, err
}
return company, nil
}