43 lines
1.6 KiB
Go
43 lines
1.6 KiB
Go
package models
|
|
|
|
import (
|
|
"GoMembership/internal/constants"
|
|
"gorm.io/gorm"
|
|
"time"
|
|
)
|
|
|
|
type User struct {
|
|
UpdatedAt time.Time
|
|
DateOfBirth time.Time `gorm:"not null" json:"date_of_birth"`
|
|
CreatedAt time.Time
|
|
Salt *string `json:"-"`
|
|
Phone *string `json:"phone"`
|
|
Notes *string `json:"notes"`
|
|
FirstName string `gorm:"not null" json:"first_name"`
|
|
Password string `json:"password"`
|
|
Email string `gorm:"unique;not null" json:"email"`
|
|
LastName string `gorm:"not null" json:"last_name"`
|
|
ProfilePicture string `json:"profile_picture"`
|
|
Address string `gorm:"not null" json:"address"`
|
|
ZipCode string `gorm:"not null" json:"zip_code"`
|
|
City string `form:"not null" json:"city"`
|
|
Consents []Consent `gorm:"constraint:OnUpdate:CASCADE"`
|
|
BankAccount BankAccount `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
|
Verification Verification `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
|
Membership Membership `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
|
ParentMemberID int64 `json:"parent_member_id"`
|
|
ID int64 `gorm:"primaryKey"`
|
|
PaymentStatus int8 `json:"payment_status"`
|
|
Status int8 `json:"status"`
|
|
RoleID int8 `json:"role_id"`
|
|
}
|
|
|
|
// BeforeCreate sets the default value for Status
|
|
func (u *User) BeforeCreate(tx *gorm.DB) (err error) {
|
|
if u.Status == 0 { // Assuming 0 is an unset value
|
|
u.Status = constants.UnverifiedStatus
|
|
u.PaymentStatus = constants.AwaitingPaymentStatus
|
|
}
|
|
return
|
|
}
|