apps/web: fix apollo modifyDataLink: check values are exist
This commit is contained in:
parent
8c69b3b9c4
commit
c2982cf31b
@ -1,3 +1,4 @@
|
||||
/* eslint-disable sonarjs/cognitive-complexity */
|
||||
import getUrls from '@/config/urls';
|
||||
import { ApolloLink, from, HttpLink } from '@apollo/client';
|
||||
import { onError } from '@apollo/client/link/error';
|
||||
@ -11,27 +12,41 @@ const modifyDataLink = new ApolloLink((operation, forward) => {
|
||||
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} руб.)`,
|
||||
}));
|
||||
response.data.evo_addproduct_types = response.data.evo_addproduct_types.map(
|
||||
(evo_addproduct_type) => {
|
||||
if (evo_addproduct_type.evo_graph_price)
|
||||
return {
|
||||
...evo_addproduct_type,
|
||||
label: `${evo_addproduct_type.label} (${evo_addproduct_type.evo_graph_price} руб.)`,
|
||||
};
|
||||
|
||||
return evo_addproduct_type;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
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})`,
|
||||
}));
|
||||
response.data.evo_equipments = response.data.evo_equipments.map((evo_equipment) => {
|
||||
if (evo_equipment.evo_start_production_year)
|
||||
return {
|
||||
...evo_equipment,
|
||||
label: `${evo_equipment.label} (${evo_equipment.evo_start_production_year})`,
|
||||
};
|
||||
|
||||
return evo_equipment;
|
||||
});
|
||||
}
|
||||
|
||||
if (operation.operationName === 'GetInsuranceCompanies') {
|
||||
response.data.accounts = response.data.accounts.map((x) => {
|
||||
const substring = x.label.match(/"(.+)"/u);
|
||||
response.data.accounts = response.data.accounts.map((account) => {
|
||||
const substring = account.label.match(/"(.+)"/u);
|
||||
if (substring)
|
||||
return {
|
||||
...account,
|
||||
label: substring ? substring[1].replaceAll('"', '').trim() : account.label,
|
||||
};
|
||||
|
||||
return {
|
||||
...x,
|
||||
label: substring ? substring[1].replaceAll('"', '').trim() : x.label,
|
||||
};
|
||||
return account;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user