-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #176 from Tibz-Dankan/feat/admin
Feat/admin
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package models | ||
|
||
import ( | ||
"github.com/google/uuid" | ||
"gorm.io/gorm" | ||
) | ||
|
||
func (u *OTP) BeforeCreate(tx *gorm.DB) error { | ||
|
||
uuid := uuid.New().String() | ||
OTP := "should be Random six digit number" | ||
|
||
tx.Statement.SetColumn("ID", uuid) | ||
tx.Statement.SetColumn("OPT", OTP) | ||
return nil | ||
} | ||
|
||
func (u *OTP) Create(opt OTP) (string, error) { | ||
|
||
// Expire all other existing user opts | ||
result := db.Create(&opt) | ||
|
||
if result.Error != nil { | ||
return "", result.Error | ||
} | ||
return opt.ID, nil | ||
} | ||
|
||
func (u *OTP) FindOne(id string) (OTP, error) { | ||
var opt OTP | ||
db.First(&opt, "id = ?", id) | ||
|
||
return opt, nil | ||
} | ||
|
||
func (u *OTP) FindByUser(userId string) (OTP, error) { | ||
var otp OTP | ||
db.First(&otp, "userId = ?", userId) | ||
|
||
return otp, nil | ||
} | ||
|
||
func (u *OTP) ExpireUserOPT(userId string) error { | ||
|
||
//TODO: to expire opt here | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters