Files
frontend-app-authn/src/recommendations/data/service.js
Mubbshar Anwar c31c03f5a9 feat: personalized recommendations (#751)
configured algolia for recommendations based on user location or education level
VAN-1287

Co-authored-by: Mubbshar Anwar <mubbsharanwar@users.noreply.github.com>
2023-02-22 10:59:00 +05:00

23 lines
714 B
JavaScript

import { camelCaseObject } from '@edx/frontend-platform';
import algoliasearch from 'algoliasearch/lite';
const INDEX_NAME = process.env.ALGOLIA_AUTHN_RECOMMENDATIONS_INDEX;
const getPersonalizedRecommendations = async (educationLevel) => {
const facetFilters = ['product:Course', 'availability:Available now'];
if (educationLevel) {
facetFilters.push(`level:${educationLevel}`);
}
const client = algoliasearch(process.env.ALGOLIA_APP_ID, process.env.ALGOLIA_SEARCH_KEY);
const index = client.initIndex(INDEX_NAME);
const { hits } = await index.search('', {
aroundLatLngViaIP: true,
facetFilters,
});
return camelCaseObject(hits);
};
export default getPersonalizedRecommendations;