Getting Suppliers From Postcode Proximity
Introduction
Here, we will understand the flow of getting the suppliers from the postcode proximity.
Flow Diagram
Flow of code
- Upon receiving the user's input of postcode, service type, supplier type and franchises, an API call is made to the getSuppliersFromPostcodeProximity endpoint.
- The first step entails identifying all suppliers located in the proximity of the given postcode within the Algolia.
- In order to accomplish this, we retrieve the precise latitude and longitude coordinates corresponding to the provided postcode.
- To optimize the process, we initially verify if the postcode exists within our internal database. If found, we directly retrieve the associated latitude and longitude from the database.
- In cases where the postcode is not present in our database, we execute an API call to postcode.io to obtain the necessary latitude and longitude data.
- If the "postcode.io" API fails to locate the specified location, we leverage the Google Maps API to acquire the latitude and longitude information.
- If we fail to get the data through Google Maps, we resort to approximating the latitude and longitude by making minor adjustments to the provided postcode.
- With the latitude and longitude successfully obtained, a call is made to Algolia, retrieving all suppliers within the vicinity of the specified postcode.
- Within the Algolia call, we effectively apply the supplier type filter while also ensuring that the supplier is capable of providing services within the given distance.
- Subsequently, we proceed to filter out any service units that have not been approved by the lease company.
- Further, we eliminate any service units that do not offer the specific service types requested by the customer.
- Next step is to append franchise details to the service units.
- Final filter is to eliminate any service units that do not offer the specific franchises requested by the customer.
- Finally, the resulting list of service units meeting all the specified criteria is promptly returned to the client.
Configurable values
- Supplier Proximity: Can be set from by the admin for each lease company.
- Number of service units to be fetched from algolia per call: Can be set while making the algolia call (hitsPerPage).
Inputs by the client
- Postcode
- Service Type
- Supplier Type
- Franchises (Only if supplier type is franchise)
External APIs used
Relation between user input and filtering of suppliers
- If the customer selects supplier type as Franchise, then only the Franchise suppliers will be returned.
- If the customer selects supplier type as Independent, then only the Independent suppliers will be returned.
- If the customer selects supplier type as Mobile, then any Independent or Franchise type garage who also offer Mobile services will be returned.
- If the customer chooses 2 service types then only the suppliers who have both the service types will be returned. (This applies only in the case of weblink enquiries, since book-in enquiry only allows one service type at a time).
Status: Accepted
Category: Protected
Authored By: Shubham H on Aug 10, 2023