fix: handle duplicate input

This commit is contained in:
ericprd
2025-02-24 19:47:40 +08:00
parent bd305f0edf
commit 3b2321d5db
7 changed files with 19 additions and 10 deletions
+2 -2
View File
@@ -7,8 +7,8 @@ import (
"github.com/ardeman/project-legalgo-go/internal/utilities/utils"
)
func (sv *AuthSvc) LoginAsUser(spec authdomain.LoginReq) (string, error) {
user, err := sv.userRepo.GetUserByEmail(spec.Email)
func (a *AuthSvc) LoginAsUser(spec authdomain.LoginReq) (string, error) {
user, err := a.userRepo.GetUserByEmail(spec.Email)
if err != nil {
return "", errors.New(err.Error())
}
+4
View File
@@ -9,6 +9,10 @@ import (
)
func (a *AuthSvc) RegisterStaff(spec authdomain.RegisterStaffReq) (string, error) {
_, err := a.staffRepo.GetStaffByEmail(spec.Email)
if err == nil {
return "", errors.New("this email address is already in use")
}
hashedPwd, err := HashPassword(spec.Password)
if err != nil {
return "", err
+6
View File
@@ -9,6 +9,12 @@ import (
)
func (a *AuthSvc) RegisterUser(spec authdomain.RegisterUserReq) (string, error) {
_, err := a.userRepo.GetUserByEmail(spec.Email)
if err == nil {
return "", errors.New("this email address is already in use")
}
subsId, err := a.subsRepo.Create(spec.SubscribePlanID)
if err != nil {
return "", nil