Repository: juspay/hyperswitch
File: crates/diesel_models/src/query/customers.rs (Rust)

Code before:
                Some(dsl::created_at),
            )
            .await
        } else {
            let predicate = dsl::merchant_id.eq(merchant_id.clone());
            generics::generic_filter::<<Self as HasTable>::Table, _, _, Self>(
                conn,
                predicate,
                Some(constraints.limit),
                constraints.offset,
                Some(dsl::created_at),
            )
            .await
        }
    }

    #[cfg(feature = "v2")]
    pub async fn list_by_merchant_id(
        conn: &PgPooledConn,
        merchant_id: &id_type::MerchantId,
        constraints: CustomerListConstraints,
    ) -> StorageResult<Vec<Self>> {
        if let Some(customer_id) = constraints.customer_id {
            let predicate = dsl::merchant_id
                .eq(merchant_id.clone())
                .and(dsl::id.eq(customer_id));
            generics::generic_filter::<<Self as HasTable>::Table, _, _, Self>(
                conn,
                predicate,
                Some(constraints.limit),
                constraints.offset,
                Some(dsl::created_at),
            )
            .await
        } else {
            let predicate = dsl::merchant_id.eq(merchant_id.clone());
            generics::generic_filter::<<Self as HasTable>::Table, _, _, Self>(
                conn,
                predicate,
                Some(constraints.limit),
                constraints.offset,
                Some(dsl::created_at),
            )
            .await
        }
    }

    #[cfg(feature = "v2")]
    pub async fn find_optional_by_merchant_id_merchant_reference_id(
        conn: &PgPooledConn,
        customer_id: &id_type::CustomerId,

Review comment (suggestion):

```suggestion
                .and(dsl::merchant_reference_id.eq(customer_id));
```

Code after:
                Some(dsl::created_at),
            )
            .await
        } else {
            let predicate = dsl::merchant_id.eq(merchant_id.clone());
            generics::generic_filter::<<Self as HasTable>::Table, _, _, Self>(
                conn,
                predicate,
                Some(constraints.limit),
                constraints.offset,
                Some(dsl::created_at),
            )
            .await
        }
    }

    #[cfg(feature = "v2")]
    pub async fn list_by_merchant_id(
        conn: &PgPooledConn,
        merchant_id: &id_type::MerchantId,
        constraints: CustomerListConstraints,
    ) -> StorageResult<Vec<Self>> {
        if let Some(customer_id) = constraints.customer_id {
            let predicate = dsl::merchant_id
                .eq(merchant_id.clone())
                .and(dsl::merchant_reference_id.eq(customer_id));
            generics::generic_filter::<<Self as HasTable>::Table, _, _, Self>(
                conn,
                predicate,
                Some(constraints.limit),
                constraints.offset,
                Some(dsl::created_at),
            )
            .await
        } else {
            let predicate = dsl::merchant_id.eq(merchant_id.clone());
            generics::generic_filter::<<Self as HasTable>::Table, _, _, Self>(
                conn,
                predicate,
                Some(constraints.limit),
                constraints.offset,
                Some(dsl::created_at),
            )
            .await
        }
    }

    #[cfg(feature = "v2")]
    pub async fn find_optional_by_merchant_id_merchant_reference_id(
        conn: &PgPooledConn,
        customer_id: &id_type::CustomerId,