fix: unique constraint data

This commit is contained in:
Lakhan Samani
2021-12-22 15:31:45 +05:30
parent 508c714932
commit 3ee79c3937
21 changed files with 206 additions and 192 deletions

View File

@@ -17,22 +17,22 @@ type User struct {
Key string `json:"_key,omitempty" bson:"_key"` // for arangodb
ID string `gorm:"primaryKey;type:char(36)" json:"_id" bson:"_id"`
Email string `gorm:"unique" json:"email" bson:"email"`
EmailVerifiedAt int64 `json:"email_verified_at" bson:"email_verified_at"`
Password string `gorm:"type:text" json:"password" bson:"password"`
SignupMethods string `json:"signup_methods" bson:"signup_methods"`
GivenName string `json:"given_name" bson:"given_name"`
FamilyName string `json:"family_name" bson:"family_name"`
MiddleName string `json:"middle_name" bson:"middle_name"`
Nickname string `json:"nickname" bson:"nickname"`
Gender string `json:"gender" bson:"gender"`
Birthdate string `json:"birthdate" bson:"birthdate"`
PhoneNumber string `gorm:"unique" json:"phone_number" bson:"phone_number"`
PhoneNumberVerifiedAt int64 `json:"phone_number_verified_at" bson:"phone_number_verified_at"`
Picture string `gorm:"type:text" json:"picture" bson:"picture"`
Roles string `json:"roles" bson:"roles"`
UpdatedAt int64 `gorm:"autoUpdateTime" json:"updated_at" bson:"updated_at"`
CreatedAt int64 `gorm:"autoCreateTime" json:"created_at" bson:"created_at"`
Email string `gorm:"unique" json:"email" bson:"email"`
EmailVerifiedAt int64 `json:"email_verified_at" bson:"email_verified_at"`
Password *string `gorm:"type:text" json:"password" bson:"password"`
SignupMethods string `json:"signup_methods" bson:"signup_methods"`
GivenName *string `json:"given_name" bson:"given_name"`
FamilyName *string `json:"family_name" bson:"family_name"`
MiddleName *string `json:"middle_name" bson:"middle_name"`
Nickname *string `json:"nickname" bson:"nickname"`
Gender *string `json:"gender" bson:"gender"`
Birthdate *string `json:"birthdate" bson:"birthdate"`
PhoneNumber *string `gorm:"unique" json:"phone_number" bson:"phone_number"`
PhoneNumberVerifiedAt *int64 `json:"phone_number_verified_at" bson:"phone_number_verified_at"`
Picture *string `gorm:"type:text" json:"picture" bson:"picture"`
Roles string `json:"roles" bson:"roles"`
UpdatedAt int64 `gorm:"autoUpdateTime" json:"updated_at" bson:"updated_at"`
CreatedAt int64 `gorm:"autoCreateTime" json:"created_at" bson:"created_at"`
}
// AddUser function to add user even with email conflict
@@ -44,7 +44,6 @@ func (mgr *manager) AddUser(user User) (User, error) {
if IsORMSupported {
// copy id as value for fields required for mongodb & arangodb
user.Key = user.ID
// user.ObjectID = user.ID
result := mgr.sqlDB.Clauses(
clause.OnConflict{
UpdateAll: true,
@@ -67,14 +66,13 @@ func (mgr *manager) AddUser(user User) (User, error) {
return user, err
}
user.Key = meta.Key
// user.ObjectID = meta.ID.String()
user.ID = meta.ID.String()
}
if IsMongoDB {
user.CreatedAt = time.Now().Unix()
user.UpdatedAt = time.Now().Unix()
user.Key = user.ID
// user.ObjectID = user.ID
userCollection := mgr.mongodb.Collection(Collections.User, options.Collection())
_, err := userCollection.InsertOne(nil, user)
if err != nil {
@@ -108,7 +106,7 @@ func (mgr *manager) UpdateUser(user User) (User, error) {
}
user.Key = meta.Key
// user.ObjectID = meta.ID.String()
user.ID = meta.ID.String()
}
if IsMongoDB {