add FindUserByEmai

This commit is contained in:
Hoang 2021-12-01 14:34:52 +07:00
parent 4d632ed042
commit 445cacc540
2 changed files with 53 additions and 0 deletions

View File

@ -24,6 +24,16 @@ func (s Service) FindUser(userID string) (model.User, error) {
return user.FindUser(userID)
}
// FindUserByEmail ...
func (s Service) FindUserByEmail(email string) (model.User, error) {
return user.FindUserByEmail(email)
}
// GetHashedPassword ...
func (s Service) GetHashedPassword(userID string) (string, error) {
return user.GetHashedPassword(userID)
}
// UpdateUser ...
func (s Service) UpdateUser(userID string, payload model.UserUpdateOptions) error {
return user.UpdateByUserID(userID, payload)

View File

@ -98,6 +98,49 @@ func FindUser(userID string) (r model.User, err error) {
return
}
// FindUserByEmail ...
func FindUserByEmail(email string) (r model.User, err error) {
var (
ctx = context.Background()
)
// Find user exists or not
if email == "" {
err = errors.New("invalid email data")
return
}
user, _ := findOneByCondition(ctx, bson.M{"email": email})
if user.ID.IsZero() {
err = errors.New("user not found")
return
}
r = getResponse(ctx, user)
return
}
// GetHashedPassword ...
func GetHashedPassword(userID string) (result string, err error) {
var (
ctx = context.Background()
)
// Find user exists or not
id, isValid := mongodb.NewIDFromString(userID)
if !isValid {
err = errors.New("invalid email data")
return
}
user, _ := findByID(ctx, id)
if user.ID.IsZero() {
err = errors.New("user not found")
return
}
result = user.HashedPassword
return
}
// All ...
func All(queryParams model.UserAllQuery) (r model.UserAll) {
var (