from sqlalchemy import text from sqlalchemy.exc import NoResultFound from delivery_metadata.api.app import app from delivery_metadata.exceptions import StoreNotFound from delivery_metadata.models import Model class ArtRelationsStoreCustomer(Model): customer_name: str ddex_party_id: str | None supports_localization: str instant_grat: str | None is_user_defined_contributors_supported: str async def get_store_customer(store_id: int) -> ArtRelationsStoreCustomer: async with app.state.art_relations_connector.db_session() as session: result = await session.execute( text( """ SELECT customer_name, ddex_party_id, supports_localization, instant_grat, is_user_defined_contributors_supported FROM customer_master_master WHERE customer_master_master_id = :store_id """ ), { "store_id": store_id, }, ) try: return ArtRelationsStoreCustomer(**result.mappings().one()) except NoResultFound as exc: raise StoreNotFound(f"No store found for store_id: {store_id}") from exc