diff --git a/legal-api/src/legal_api/models/address.py b/legal-api/src/legal_api/models/address.py index 28182ed8f0..b8ce59188d 100644 --- a/legal-api/src/legal_api/models/address.py +++ b/legal-api/src/legal_api/models/address.py @@ -32,7 +32,8 @@ class Address(db.Model): # pylint: disable=too-many-instance-attributes MAILING = 'mailing' DELIVERY = 'delivery' - ADDRESS_TYPES = [MAILING, DELIVERY] + FURNISHING = 'furnishing' + ADDRESS_TYPES = [MAILING, DELIVERY, FURNISHING] JSON_MAILING = 'mailingAddress' JSON_DELIVERY = 'deliveryAddress' JSON_ADDRESS_TYPES = [JSON_MAILING, JSON_DELIVERY] @@ -101,3 +102,24 @@ def find_by_id(cls, internal_id: int = None): if internal_id: address = cls.query.filter_by(id=internal_id).one_or_none() return address + + @classmethod + def find_by(cls, + business_id: int = None, + furnishings_id: int = None, + office_id: int = None) -> dict: + """Return the address matching.""" + query = db.session.query(Address) + addresses = [] + + if business_id: + query = query.filter(Address.business_id == business_id) + + if furnishings_id: + query = query.filter(Address.furnishings_id == furnishings_id) + + if office_id: + query = query.filter(Address.office_id == office_id) + + addresses = query.order_by(Address.id).all() + return addresses