datastore

package
v0.0.0-...-53e80a7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CustomerStatusActive                    = 1
	CustomerStatusArchived                  = 2
	CustomerDeactivationReasonNotSpecified  = 0
	CustomerDeactivationReasonOther         = 1
	CustomerDeactivationReasonBlacklisted   = 2
	CustomerDeactivationReasonMoved         = 3
	CustomerDeactivationReasonDeceased      = 4
	CustomerDeactivationReasonDoNotConstact = 5
	CustomerTypeUnassigned                  = 1
	CustomerTypeResidential                 = 2
	CustomerTypeCommercial                  = 3
	CustomerPhoneTypeLandline               = 1
	CustomerPhoneTypeMobile                 = 2
	CustomerPhoneTypeWork                   = 3
	CustomerOrganizationTypeUnknown         = 1
	CustomerOrganizationTypePrivate         = 2
	CustomerOrganizationTypeNonProfit       = 3
	CustomerOrganizationTypeGovernment      = 4
	CustomerGenderOther                     = 1
	CustomerGenderMan                       = 2
	CustomerGenderWoman                     = 3
	CustomerGenderTransgender               = 4
	CustomerGenderNonBinary                 = 5
	CustomerGenderTwoSpirit                 = 6
	CustomerGenderPreferNotToSay            = 7
	CustomerGenderDoNotKnow                 = 8
)
View Source
const (
	OrderAscending  = 1
	OrderDescending = -1
)

Variables

View Source
var CustomerGenderLabels = map[int8]string{
	CustomerGenderOther:          "Other",
	CustomerGenderMan:            "Man",
	CustomerGenderWoman:          "Women",
	CustomerGenderNonBinary:      "Non-Binary",
	CustomerGenderTwoSpirit:      "Two Spirit",
	CustomerGenderPreferNotToSay: "Prefer Not To Say",
	CustomerGenderDoNotKnow:      "Do Not Know",
}
View Source
var CustomerOrganizationTypeLabels = map[int8]string{
	1: "Unknown",
	2: "Private",
	3: "Non-Profit",
	4: "Government",
}
View Source
var CustomerStateLabels = map[int8]string{
	CustomerStatusActive:   "Active",
	CustomerStatusArchived: "Archived",
}
View Source
var CustomerTelephoneTypeLabels = map[int8]string{
	1: "Landline",
	2: "Mobile",
	3: "Work",
}
View Source
var CustomerTypeLabels = map[int8]string{
	CustomerTypeResidential: "Residential",
	CustomerTypeCommercial:  "Commercial",
	CustomerTypeUnassigned:  "Unassigned",
}

Functions

This section is empty.

Types

type Customer

type Customer struct {
	ID                                   primitive.ObjectID `bson:"_id" json:"id"`
	TenantID                             primitive.ObjectID `bson:"tenant_id" json:"tenant_id,omitempty"`
	FirstName                            string             `bson:"first_name" json:"first_name"`
	LastName                             string             `bson:"last_name" json:"last_name"`
	Name                                 string             `bson:"name" json:"name"`
	LexicalName                          string             `bson:"lexical_name" json:"lexical_name"`
	Email                                string             `bson:"email" json:"email"`
	IsOkToEmail                          bool               `bson:"is_ok_to_email" json:"is_ok_to_email"`
	Phone                                string             `bson:"phone" json:"phone,omitempty"`
	PhoneType                            int8               `bson:"phone_type" json:"phone_type"`
	PhoneExtension                       string             `bson:"phone_extension" json:"phone_extension"`
	IsOkToText                           bool               `bson:"is_ok_to_text" json:"is_ok_to_text"`
	FaxNumber                            string             `bson:"fax_number" json:"fax_number"`
	OtherPhone                           string             `bson:"other_phone" json:"other_phone"`
	OtherPhoneExtension                  string             `bson:"other_phone_extension" json:"other_phone_extension"`
	OtherPhoneType                       int8               `bson:"other_phone_type" json:"other_phone_type"`
	Country                              string             `bson:"country" json:"country,omitempty"`
	Region                               string             `bson:"region" json:"region,omitempty"`
	City                                 string             `bson:"city" json:"city,omitempty"`
	PostalCode                           string             `bson:"postal_code" json:"postal_code,omitempty"`
	AddressLine1                         string             `bson:"address_line1" json:"address_line1,omitempty"`
	AddressLine2                         string             `bson:"address_line2" json:"address_line2,omitempty"`
	PostOfficeBoxNumber                  string             `bson:"post_office_box_number" json:"post_office_box_number"`
	FullAddressWithoutPostalCode         string             `bson:"full_address_without_postal_code" json:"full_address_without_postal_code,omitempty"` // Compiled value
	FullAddressWithPostalCode            string             `bson:"full_address_with_postal_code" json:"full_address_with_postal_code,omitempty"`       // Compiled value
	FullAddressURL                       string             `bson:"full_address_url" json:"full_address_url,omitempty"`                                 // Compiled value
	HasShippingAddress                   bool               `bson:"has_shipping_address" json:"has_shipping_address,omitempty"`
	ShippingName                         string             `bson:"shipping_name" json:"shipping_name,omitempty"`
	ShippingPhone                        string             `bson:"shipping_phone" json:"shipping_phone,omitempty"`
	ShippingCountry                      string             `bson:"shipping_country" json:"shipping_country,omitempty"`
	ShippingRegion                       string             `bson:"shipping_region" json:"shipping_region,omitempty"`
	ShippingCity                         string             `bson:"shipping_city" json:"shipping_city,omitempty"`
	ShippingPostalCode                   string             `bson:"shipping_postal_code" json:"shipping_postal_code,omitempty"`
	ShippingAddressLine1                 string             `bson:"shipping_address_line1" json:"shipping_address_line1,omitempty"`
	ShippingAddressLine2                 string             `bson:"shipping_address_line2" json:"shipping_address_line2,omitempty"`
	ShippingPostOfficeBoxNumber          string             `bson:"shipping_post_office_box_number" json:"shipping_post_office_box_number"`
	ShippingFullAddressWithoutPostalCode string             `bson:"shipping_full_address_without_postal_code" json:"shipping_full_address_without_postal_code,omitempty"` // Compiled value
	ShippingFullAddressWithPostalCode    string             `bson:"shipping_full_address_with_postal_code" json:"shipping_full_address_with_postal_code,omitempty"`       // Compiled value
	ShippingFullAddressURL               string             `bson:"shipping_full_address_url" json:"shipping_full_address_url,omitempty"`                                 // Compiled value
	HowDidYouHearAboutUsID               primitive.ObjectID `bson:"how_did_you_hear_about_us_id" json:"how_did_you_hear_about_us_id,omitempty"`
	HowDidYouHearAboutUsText             string             `bson:"how_did_you_hear_about_us_text" json:"how_did_you_hear_about_us_text,omitempty"`
	IsHowDidYouHearAboutUsOther          bool               `bson:"is_how_did_you_hear_about_us_other" json:"is_how_did_you_hear_about_us_other,omitempty"`
	HowDidYouHearAboutUsOther            string             `bson:"how_did_you_hear_about_us_other" json:"how_did_you_hear_about_us_other,omitempty"`
	AgreeTOS                             bool               `bson:"agree_tos" json:"agree_tos,omitempty"`
	CreatedAt                            time.Time          `bson:"created_at" json:"created_at,omitempty"`
	CreatedByUserID                      primitive.ObjectID `bson:"created_by_user_id" json:"created_by_user_id"`
	CreatedByUserName                    string             `bson:"created_by_user_name" json:"created_by_user_name"`
	CreatedFromIPAddress                 string             `bson:"created_from_ip_address" json:"created_from_ip_address"`
	ModifiedAt                           time.Time          `bson:"modified_at" json:"modified_at,omitempty"`
	ModifiedByUserID                     primitive.ObjectID `bson:"modified_by_user_id" json:"modified_by_user_id"`
	ModifiedByUserName                   string             `bson:"modified_by_user_name" json:"modified_by_user_name"`
	ModifiedFromIPAddress                string             `bson:"modified_from_ip_address" json:"modified_from_ip_address"`
	Status                               int8               `bson:"status" json:"status"`
	Salt                                 string             `bson:"salt" json:"salt,omitempty"`
	PrAccessCode                         string             `bson:"pr_access_code" json:"pr_access_code,omitempty"`
	PrExpiryTime                         time.Time          `bson:"pr_expiry_time" json:"pr_expiry_time,omitempty"`
	Timezone                             string             `bson:"timezone" json:"timezone,omitempty"`
	UserID                               primitive.ObjectID `bson:"user_id" json:"user_id,omitempty"`
	Type                                 int8               `bson:"type" json:"type"`
	IsBusiness                           bool               `bson:"is_business" json:"is_business"`
	IsSenior                             bool               `bson:"is_senior" json:"is_senior"`
	IsSupport                            bool               `bson:"is_support" json:"is_support"`
	JobInfoRead                          string             `bson:"job_info_read" json:"job_info_read"`
	DeactivationReason                   int8               `bson:"deactivation_reason" json:"deactivation_reason"`
	DeactivationReasonOther              string             `bson:"deactivation_reason_other" json:"deactivation_reason_other"`
	Description                          string             `bson:"description" json:"description"`
	AvatarObjectExpiry                   time.Time          `bson:"avatar_object_expiry" json:"avatar_object_expiry"`
	AvatarObjectURL                      string             `bson:"avatar_object_url" json:"avatar_object_url"`
	AvatarObjectKey                      string             `bson:"avatar_object_key" json:"avatar_object_key"`
	AvatarFileType                       string             `bson:"avatar_file_type" json:"avatar_file_type"`
	AvatarFileName                       string             `bson:"avatar_file_name" json:"avatar_file_name"`
	BirthDate                            time.Time          `bson:"birth_date" json:"birth_date"`
	JoinDate                             time.Time          `bson:"join_date" json:"join_date"`
	Nationality                          string             `bson:"nationality" json:"nationality"`
	Gender                               int8               `bson:"gender" json:"gender"`
	GenderOther                          string             `bson:"gender_other" json:"gender_other"`
	TaxId                                string             `bson:"tax_id" json:"tax_id"`
	Elevation                            float64            `bson:"elevation" json:"elevation"`
	Latitude                             float64            `bson:"latitude" json:"latitude"`
	Longitude                            float64            `bson:"longitude" json:"longitude"`
	AreaServed                           string             `bson:"area_served" json:"area_served"`
	AvailableLanguage                    string             `bson:"available_language" json:"available_language"`
	ContactType                          string             `bson:"contact_type" json:"contact_type"`
	OrganizationName                     string             `bson:"organization_name" json:"organization_name"`
	OrganizationType                     int8               `bson:"organization_type" json:"organization_type"`
	LimitSpecial                         string             `bson:"limit_special" json:"limit_special"`
	PreferredLanguage                    string             `bson:"preferred_language" json:"preferred_language"`
	PublicID                             uint64             `bson:"public_id" json:"public_id,omitempty"`
	Comments                             []*CustomerComment `bson:"comments" json:"comments"`
	Tags                                 []*CustomerTag     `bson:"tags" json:"tags"`
	IdentifyAs                           []int8             `bson:"identify_as" json:"identify_as,omitempty"`
	IsBanned                             bool               `bson:"is_banned" json:"is_banned"`
	BannedAt                             time.Time          `bson:"banned_at" json:"banned_at"`
	BanningReason                        int8               `bson:"banning_reason" json:"banning_reason"`
	BanningReasonOther                   string             `bson:"banning_reason_other" json:"banning_reason_other"`

	// OTPEnabled controls whether we force 2FA or not during login for this customer.
	OTPEnabled bool `bson:"otp_enabled" json:"otp_enabled"`
}

type CustomerAsSelectOption

type CustomerAsSelectOption struct {
	Value primitive.ObjectID `bson:"_id" json:"value"` // Extract from the database `_id` field and output through API as `value`.
	Label string             `bson:"name" json:"label"`
}

type CustomerComment

type CustomerComment struct {
	ID                    primitive.ObjectID `bson:"_id" json:"id"`
	TenantID              primitive.ObjectID `bson:"tenant_id" json:"tenant_id"`
	CreatedAt             time.Time          `bson:"created_at,omitempty" json:"created_at,omitempty"`
	CreatedByUserID       primitive.ObjectID `bson:"created_by_user_id" json:"created_by_user_id"`
	CreatedByUserName     string             `bson:"created_by_user_name" json:"created_by_user_name"`
	CreatedFromIPAddress  string             `bson:"created_from_ip_address" json:"created_from_ip_address"`
	ModifiedAt            time.Time          `bson:"modified_at,omitempty" json:"modified_at,omitempty"`
	ModifiedByUserID      primitive.ObjectID `bson:"modified_by_user_id" json:"modified_by_user_id"`
	ModifiedByUserName    string             `bson:"modified_by_user_name" json:"modified_by_user_name"`
	ModifiedFromIPAddress string             `bson:"modified_from_ip_address" json:"modified_from_ip_address"`
	Content               string             `bson:"content" json:"content"`
	Status                int8               `bson:"status" json:"status"`
	PublicID              uint64             `bson:"public_id" json:"public_id"`
}

type CustomerListFilter

type CustomerListFilter struct {
	// Pagination related.
	Cursor    primitive.ObjectID
	PageSize  int64
	SortField string
	SortOrder int8 // 1=ascending | -1=descending

	// Filter related.
	TenantID         primitive.ObjectID
	Type             int8
	Role             int8
	Status           int8
	UUIDs            []string
	SearchText       string
	FirstName        string
	LastName         string
	Email            string
	Phone            string
	OrganizationName string
	CreatedAtGTE     time.Time

	// IDs filter is used if you know the `ID` values of all the
	// customers you want to retrieve.
	IDs []primitive.ObjectID
}

type CustomerListResult

type CustomerListResult struct {
	Results     []*Customer        `json:"results"`
	NextCursor  primitive.ObjectID `json:"next_cursor"`
	HasNextPage bool               `json:"has_next_page"`
}

type CustomerLite

type CustomerLite struct {
	ID                  primitive.ObjectID `bson:"_id" json:"id"`
	FirstName           string             `bson:"first_name" json:"first_name"`
	LastName            string             `bson:"last_name" json:"last_name"`
	Name                string             `bson:"name" json:"name"`
	LexicalName         string             `bson:"lexical_name" json:"lexical_name"`
	Email               string             `bson:"email" json:"email"`
	Phone               string             `bson:"phone" json:"phone,omitempty"`
	PhoneType           int8               `bson:"phone_type" json:"phone_type"`
	PhoneExtension      string             `bson:"phone_extension" json:"phone_extension"`
	OtherPhone          string             `bson:"other_phone" json:"other_phone"`
	OtherPhoneExtension string             `bson:"other_phone_extension" json:"other_phone_extension"`
	OtherPhoneType      int8               `bson:"other_phone_type" json:"other_phone_type"`
	Status              int8               `bson:"status" json:"status"`
	Type                int8               `bson:"type" json:"type"`
	AvatarObjectKey     string             `bson:"avatar_object_key" json:"avatar_object_key"`
	AvatarFileType      string             `bson:"avatar_file_type" json:"avatar_file_type"`
	AvatarFileName      string             `bson:"avatar_file_name" json:"avatar_file_name"`
	Birthdate           time.Time          `bson:"birthdate" json:"birthdate"`
	JoinDate            time.Time          `bson:"join_date" json:"join_date"`
	Nationality         string             `bson:"nationality" json:"nationality"`
	Gender              int8               `bson:"gender" json:"gender"`
	GenderOther         string             `bson:"gender_other" json:"gender_other"`
	OrganizationName    string             `bson:"organization_name" json:"organization_name"`
	OrganizationType    int8               `bson:"organization_type" json:"organization_type"`
	Country             string             `bson:"country" json:"country,omitempty"`
	Region              string             `bson:"region" json:"region,omitempty"`
	City                string             `bson:"city" json:"city,omitempty"`
	PostalCode          string             `bson:"postal_code" json:"postal_code,omitempty"`
	AddressLine1        string             `bson:"address_line1" json:"address_line1,omitempty"`
	AddressLine2        string             `bson:"address_line2" json:"address_line2,omitempty"`
	IsBanned            bool               `bson:"is_banned" json:"is_banned"`
}

CustomerLite represents the limited detail of a customer which is to be displayed in a list view.

type CustomerPaginationListAndCountResult

type CustomerPaginationListAndCountResult struct {
	Results     []*Customer `json:"results"`
	NextCursor  string      `json:"next_cursor"`
	HasNextPage bool        `json:"has_next_page"`
	Count       int64       `json:"count"`
}

CustomerPaginationListResult represents the paginated list results for the customer records (meaning limited).

type CustomerPaginationListFilter

type CustomerPaginationListFilter struct {
	// Pagination related.
	Cursor    string
	PageSize  int64
	SortField string
	SortOrder int8 // 1=ascending | -1=descending

	// Filter related.
	TenantID               primitive.ObjectID
	HowDidYouHearAboutUsID primitive.ObjectID
	Type                   int8
	Role                   int8
	Status                 int8
	UUIDs                  []string
	SearchText             string
	FirstName              string
	LastName               string
	Email                  string
	Phone                  string
	OrganizationName       string
	CreatedAtGTE           time.Time

	// InTagIDs filter is used if you want to find one or more tag
	// ids inside the customer.
	InTagIDs []primitive.ObjectID

	// AllTagIDs filter is used if you want to find all tag ids for
	// the customer.
	AllTagIDs []primitive.ObjectID

	IsOkToEmail int8 // 0=All, 1=Yes, 2=No

	JoinDateGT  time.Time
	JoinDateGTE time.Time
	JoinDateLT  time.Time
	JoinDateLTE time.Time

	// IDs filter is used if you know the `ID` values of all the
	// customers you want to retrieve.
	IDs []primitive.ObjectID
}

type CustomerPaginationListResult

type CustomerPaginationListResult struct {
	Results     []*Customer `json:"results"`
	NextCursor  string      `json:"next_cursor"`
	HasNextPage bool        `json:"has_next_page"`
}

CustomerPaginationListResult represents the paginated list results for the customer records (meaning limited).

type CustomerPaginationLiteListAndCountResult

type CustomerPaginationLiteListAndCountResult struct {
	Results     []*CustomerLite `json:"results"`
	NextCursor  string          `json:"next_cursor"`
	HasNextPage bool            `json:"has_next_page"`
	Count       int64           `json:"count"`
}

CustomerPaginationLiteListResult represents the paginated list results for the customer lite records (meaning limited).

type CustomerPaginationLiteListResult

type CustomerPaginationLiteListResult struct {
	Results     []*CustomerLite `json:"results"`
	NextCursor  string          `json:"next_cursor"`
	HasNextPage bool            `json:"has_next_page"`
}

CustomerPaginationLiteListResult represents the paginated list results for the customer lite records (meaning limited).

type CustomerStorer

type CustomerStorer interface {
	Create(ctx context.Context, m *Customer) error
	GetByID(ctx context.Context, id primitive.ObjectID) (*Customer, error)
	GetByPublicID(ctx context.Context, oldID uint64) (*Customer, error)
	GetByEmail(ctx context.Context, email string) (*Customer, error)
	GetByVerificationCode(ctx context.Context, verificationCode string) (*Customer, error)
	GetLatestByTenantID(ctx context.Context, tenantID primitive.ObjectID) (*Customer, error)
	GetByUserID(ctx context.Context, userID primitive.ObjectID) (*Customer, error)
	CheckIfExistsByEmail(ctx context.Context, email string) (bool, error)
	UpdateByID(ctx context.Context, m *Customer) error
	UpsertByID(ctx context.Context, user *Customer) error
	ListByFilter(ctx context.Context, f *CustomerPaginationListFilter) (*CustomerPaginationListResult, error)
	ListAsSelectOptionByFilter(ctx context.Context, f *CustomerListFilter) ([]*CustomerAsSelectOption, error)
	LiteListByFilter(ctx context.Context, f *CustomerPaginationListFilter) (*CustomerPaginationLiteListResult, error)
	ListByHowDidYouHearAboutUsID(ctx context.Context, howDidYouHearAboutUsID primitive.ObjectID) (*CustomerPaginationListResult, error)
	CountByFilter(ctx context.Context, f *CustomerPaginationListFilter) (int64, error)
	ListAndCountByFilter(ctx context.Context, f *CustomerPaginationListFilter) (*CustomerPaginationListAndCountResult, error)
	LiteListAndCountByFilter(ctx context.Context, f *CustomerPaginationListFilter) (*CustomerPaginationLiteListAndCountResult, error)
	DeleteByID(ctx context.Context, id primitive.ObjectID) error
}

CustomerStorer Interface for user.

func NewDatastore

func NewDatastore(appCfg *c.Conf, loggerp *slog.Logger, client *mongo.Client) CustomerStorer

type CustomerStorerImpl

type CustomerStorerImpl struct {
	Logger     *slog.Logger
	DbClient   *mongo.Client
	Collection *mongo.Collection
}

func (CustomerStorerImpl) CheckIfExistsByEmail

func (impl CustomerStorerImpl) CheckIfExistsByEmail(ctx context.Context, email string) (bool, error)

func (CustomerStorerImpl) CountByFilter

func (CustomerStorerImpl) Create

func (impl CustomerStorerImpl) Create(ctx context.Context, u *Customer) error

func (CustomerStorerImpl) DeleteByID

func (impl CustomerStorerImpl) DeleteByID(ctx context.Context, id primitive.ObjectID) error

func (CustomerStorerImpl) GetByEmail

func (impl CustomerStorerImpl) GetByEmail(ctx context.Context, email string) (*Customer, error)

func (CustomerStorerImpl) GetByID

func (CustomerStorerImpl) GetByPublicID

func (impl CustomerStorerImpl) GetByPublicID(ctx context.Context, oldID uint64) (*Customer, error)

func (CustomerStorerImpl) GetByUserID

func (impl CustomerStorerImpl) GetByUserID(ctx context.Context, userID primitive.ObjectID) (*Customer, error)

func (CustomerStorerImpl) GetByVerificationCode

func (impl CustomerStorerImpl) GetByVerificationCode(ctx context.Context, verificationCode string) (*Customer, error)

func (CustomerStorerImpl) GetLatestByTenantID

func (impl CustomerStorerImpl) GetLatestByTenantID(ctx context.Context, tenantID primitive.ObjectID) (*Customer, error)

func (CustomerStorerImpl) ListAsSelectOptionByFilter

func (impl CustomerStorerImpl) ListAsSelectOptionByFilter(ctx context.Context, f *CustomerListFilter) ([]*CustomerAsSelectOption, error)

func (CustomerStorerImpl) ListByFilter

func (CustomerStorerImpl) ListByHowDidYouHearAboutUsID

func (impl CustomerStorerImpl) ListByHowDidYouHearAboutUsID(ctx context.Context, howDidYouHearAboutUsID primitive.ObjectID) (*CustomerPaginationListResult, error)

func (CustomerStorerImpl) LiteListByFilter

func (CustomerStorerImpl) UpdateByID

func (impl CustomerStorerImpl) UpdateByID(ctx context.Context, m *Customer) error

func (CustomerStorerImpl) UpsertByID

func (impl CustomerStorerImpl) UpsertByID(ctx context.Context, user *Customer) error

type CustomerTag

type CustomerTag struct {
	ID          primitive.ObjectID `bson:"_id" json:"id"`
	Text        string             `bson:"text" json:"text"`
	Description string             `bson:"description" json:"description"`
	Status      int8               `bson:"status" json:"status"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL