UNPKG

cluedin-widget

Version:

This project contains all the pages needed for browsing entities and searching them. The aim is to replace the CluedIn.Webapp project with this one when all the pages ( including the Admin page ) will be ported to REACT.

65 lines (55 loc) 1.82 kB
/* eslint no-underscore-dangle: ["error", { "allow": ["__token"] }]*/ import entityAPI from '../../iso/entity'; import { apiRequest } from '../helpers/request'; export function getEntity(id) { return apiRequest('GET', `api/entity?id=${id}`).then((resp) => (entityAPI.toVM(resp.body, false, resp.__token, true)) ); } /* * {{url}}/api/widget/your?type=Files/File {{url}}/api/widget/latest?type=Files/File {{url}}/api/widget/upcoming?type=Files/File * */ export function getLatest(type, id) { let url = `api/widget/latest?type=${type}`; if (id) { url += `&id=${id}`; } return apiRequest('GET', url).then((resp) => ( resp.body.map((entity) => (entityAPI.toVM(entity, true, resp.__token))) )); } export function getSuggestedSearch(search) { return apiRequest( 'GET', `api/suggestedsearch?queryKey=${search.SearchQuery}&tokens=${search.Tokens}` ).then((resp) => ( resp.body.map((entity) => (entityAPI.toVM(entity, false, resp.__token))) )); } export function getEntityByName(name) { return apiRequest('GET', `api/entity/code?id=${name}`).then((resp) => ( entityAPI.toVM(resp.body, false, resp.__token, true) )); } export function getEntityByEmail(email) { return apiRequest('GET', `api/entity/email?email=${email}`).then((resp) => ( entityAPI.toVM(resp.body, false, resp.__token, true) )); } export function getEntityForSalesForce(type, origin, value) { return apiRequest( 'GET', `api/v1/entity/code?type=${type}&origin=${origin}&value=${value}` ).then((resp) => ( resp.body )); } export function getLatestEntities(entityId, entityType) { return apiRequest( 'GET', `/api/generic/latest?id=${entityId}&type=${entityType}` ).then((resp) => ( resp.body.map((entity) => (entityAPI.toVM(entity, true, resp.__token))) )); }