Change status and password method #3

Merged
lqhoang99 merged 3 commits from feature/changeStatus-password into master 2021-11-09 04:03:28 +00:00
2 changed files with 8 additions and 14 deletions
Showing only changes of commit bc0e3b4076 - Show all commits

View File

@ -24,8 +24,7 @@ func (s Service) Create(payload CreateOptions) error {
)
// Validate payload
err := payload.validate(ctx)
if err != nil {
if err := payload.validate(ctx); err != nil {
return err
}
@ -36,8 +35,7 @@ func (s Service) Create(payload CreateOptions) error {
}
// Create user
err = s.userCreate(ctx, doc)
if err != nil {
if err = s.userCreate(ctx, doc); err != nil {
return err
}

View File

@ -30,8 +30,7 @@ func (s Service) UpdateByUserID(userID string, payload UpdateOptions) error {
)
// Validate payload
err := payload.validate(ctx)
if err != nil {
if err := payload.validate(ctx); err != nil {
return err
}
@ -55,8 +54,7 @@ func (s Service) UpdateByUserID(userID string, payload UpdateOptions) error {
}
namhq1989 commented 2021-11-09 02:46:11 +00:00 (Migrated from github.com)
Review

ChangePasswordByUserID -> ChangeUserPassword

ChangePasswordByUserID -> ChangeUserPassword
namhq1989 commented 2021-11-09 02:47:10 +00:00 (Migrated from github.com)
Review

đưa ra validate:

  • user id -> valid mongo id
  • old password != ""
  • new password != ""
đưa ra validate: - user id -> valid mongo id - old password != "" - new password != ""
namhq1989 commented 2021-11-09 02:47:26 +00:00 (Migrated from github.com)
Review

old or new password cannot be empty

old or new password cannot be empty
namhq1989 commented 2021-11-09 02:47:42 +00:00 (Migrated from github.com)
Review

user not found

user not found
namhq1989 commented 2021-11-09 02:48:21 +00:00 (Migrated from github.com)
Review
if isValid := checkPasswordHash(oldPassword, user.HashedPassword); !isValid {
  return errors.New("the password is incorrect")
}
```go if isValid := checkPasswordHash(oldPassword, user.HashedPassword); !isValid { return errors.New("the password is incorrect") } ```
namhq1989 commented 2021-11-09 02:48:54 +00:00 (Migrated from github.com)
Review

ChangeUserStatus

  • func này check thêm nếu user.Status == newStatus thì return luôn ko cần làm gì nữa
ChangeUserStatus - func này check thêm nếu `user.Status == newStatus` thì return luôn ko cần làm gì nữa
namhq1989 commented 2021-11-09 02:49:16 +00:00 (Migrated from github.com)
Review

mọi id client gửi qua đều phải validate lại

mọi id client gửi qua đều phải validate lại
lqhoang99 commented 2021-11-09 03:22:59 +00:00 (Migrated from github.com)
Review

done

done
lqhoang99 commented 2021-11-09 03:23:03 +00:00 (Migrated from github.com)
Review

done

done
lqhoang99 commented 2021-11-09 03:23:08 +00:00 (Migrated from github.com)
Review

done

done
lqhoang99 commented 2021-11-09 03:23:12 +00:00 (Migrated from github.com)
Review

done

done
lqhoang99 commented 2021-11-09 03:23:16 +00:00 (Migrated from github.com)
Review

done

done
lqhoang99 commented 2021-11-09 03:23:19 +00:00 (Migrated from github.com)
Review

done

done
lqhoang99 commented 2021-11-09 03:23:28 +00:00 (Migrated from github.com)
Review

done

done
// Update
err = s.userUpdateOneByCondition(ctx, cond, updateData)
if err != nil {
if err := s.userUpdateOneByCondition(ctx, cond, updateData); err != nil {
return err
}
@ -88,13 +86,12 @@ func (s Service) ChangeUserPassword(userID string, opt ChangePasswordOptions) er
}
// Update password
err = s.userUpdateOneByCondition(ctx, bson.M{"_id": user.ID}, bson.M{
if err = s.userUpdateOneByCondition(ctx, bson.M{"_id": user.ID}, bson.M{
"$set": bson.M{
"hashedPassword": hashPassword(opt.NewPassword),
"updatedAt": now(),
},
})
if err != nil {
}); err != nil {
return err
}
@ -114,13 +111,12 @@ func (s Service) ChangeUserStatus(userID, newStatus string) error {
}
// Update status
err := s.userUpdateOneByCondition(ctx, bson.M{"_id": id}, bson.M{
if err := s.userUpdateOneByCondition(ctx, bson.M{"_id": id}, bson.M{
"$set": bson.M{
"status": newStatus,
"updatedAt": now(),
},
})
if err != nil {
}); err != nil {
return err
}