46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
import getUrls from './urls';
|
||
import { ApolloLink, HttpLink } from '@apollo/client';
|
||
|
||
const { URL_CRM_GRAPHQL } = getUrls();
|
||
|
||
const modifyDataLink = new ApolloLink((operation, forward) => {
|
||
const context = operation?.getContext();
|
||
|
||
return forward(operation).map((response) => {
|
||
if (!context?.disableModify) {
|
||
if (Object.keys(response?.data).includes('evo_addproduct_types')) {
|
||
response.data.evo_addproduct_types = response.data.evo_addproduct_types.map((x) => ({
|
||
...x,
|
||
label: `${x.label} (${x.evo_graph_price} руб.)`,
|
||
}));
|
||
}
|
||
|
||
if (Object.keys(response?.data).includes('evo_equipments')) {
|
||
response.data.evo_equipments = response.data.evo_equipments.map((x) => ({
|
||
...x,
|
||
label: `${x.label} (${x.evo_start_production_year})`,
|
||
}));
|
||
}
|
||
|
||
if (operation.operationName === 'GetInsuranceCompanies') {
|
||
response.data.accounts = response.data.accounts.map((x) => {
|
||
const substring = x.label.match(/"(.+)"/u);
|
||
|
||
return {
|
||
...x,
|
||
label: substring ? substring[1].replaceAll('"', '').trim() : x.label,
|
||
};
|
||
});
|
||
}
|
||
}
|
||
|
||
return response;
|
||
});
|
||
});
|
||
|
||
const httpLink = new HttpLink({
|
||
uri: URL_CRM_GRAPHQL,
|
||
});
|
||
|
||
export const link = modifyDataLink.concat(httpLink);
|