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:
@@ -218,7 +218,16 @@ func (r *userRepository) Delete(ctx context.Context, id string) error {
|
||||
|
||||
// GetByIDs retrieves users by IDs
|
||||
func (r *userRepository) GetByIDs(ctx context.Context, userIDs []string) ([]User, error) {
|
||||
users, err := r.ormRepo.FindAll(ctx, bson.M{"_id": bson.M{"$in": userIDs}}, orm.NewPaginationBuilder().Limit(len(userIDs)).Build())
|
||||
objectIDs := make([]bson.ObjectID, 0)
|
||||
for _, id := range userIDs {
|
||||
objectID, err := bson.ObjectIDFromHex(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
objectIDs = append(objectIDs, objectID)
|
||||
}
|
||||
|
||||
users, err := r.ormRepo.FindAll(ctx, bson.M{"_id": bson.M{"$in": objectIDs}}, orm.NewPaginationBuilder().Limit(len(userIDs)).Build())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user