Refactor Customer and User Repository Methods for ObjectID Handling
- Updated GetByIDs methods in customer and user repositories to convert string IDs to bson.ObjectID, ensuring proper handling of MongoDB object IDs. - Enhanced error handling for ID conversion to provide clearer feedback when invalid IDs are provided. - Modified notification service calls in customer and user services to use context.Background() for asynchronous email sending, improving concurrency management. - Ensured consistent handling of company IDs in the customer repository for retrieving customers by companies.
This commit is contained in:
@@ -152,7 +152,7 @@ func (s *customerService) Register(ctx context.Context, form *CreateCustomerForm
|
||||
"company_ids": Companies,
|
||||
})
|
||||
|
||||
s.notification.SendEmail(ctx, notification.Model{
|
||||
go s.notification.SendEmail(context.Background(), notification.Model{
|
||||
Recipient: customer.Email,
|
||||
Title: "Welcome to Opplens",
|
||||
Message: fmt.Sprintf("Welcome to Opplens\nUsername: %s\nPassword: %s", strings.ToLower(customer.Username), form.Password),
|
||||
@@ -428,7 +428,7 @@ func (s *customerService) UpdateStatus(ctx context.Context, id string, form *Upd
|
||||
"status": form.Status,
|
||||
})
|
||||
|
||||
s.notification.SendEmail(ctx, notification.Model{
|
||||
go s.notification.SendEmail(context.Background(), notification.Model{
|
||||
Recipient: customer.Email,
|
||||
Title: "Account Status Updated",
|
||||
Message: fmt.Sprintf("Your account has been %s", strings.ToUpper(form.Status)),
|
||||
@@ -888,7 +888,7 @@ func (s *customerService) RequestResetPassword(ctx context.Context, form *Reques
|
||||
}
|
||||
|
||||
// Send OTP via email
|
||||
s.notification.SendEmail(ctx, notification.Model{
|
||||
go s.notification.SendEmail(context.Background(), notification.Model{
|
||||
Recipient: form.Email,
|
||||
Title: "Password Reset",
|
||||
Message: fmt.Sprintf("Your password reset code is: %s", otpCode),
|
||||
@@ -1083,7 +1083,7 @@ func (s *customerService) ResetPassword(ctx context.Context, form *ResetPassword
|
||||
"customer_id": customer.ID,
|
||||
})
|
||||
|
||||
s.notification.SendEmail(ctx, notification.Model{
|
||||
go s.notification.SendEmail(context.Background(), notification.Model{
|
||||
Recipient: tokenData.Email,
|
||||
Title: "Password Reset Success",
|
||||
Message: "Your password has been reset successfully",
|
||||
|
||||
Reference in New Issue
Block a user