apps/web: graphql: GetInsuranceCompanies -> sort совком first

This commit is contained in:
vchikalkin 2024-09-09 15:57:28 +03:00
parent 7014462d42
commit 09959e3ac3

View File

@ -9,6 +9,10 @@ import { getCurrentScope } from '@sentry/nextjs';
import getConfig from 'next/config';
import { isServer } from 'tools';
function isSovkom(account) {
return account.label.toLowerCase().includes('совком');
}
export function createLink(headers) {
const { URL_CRM_GRAPHQL } = getUrls();
@ -44,16 +48,24 @@ export function createLink(headers) {
}
if (operation.operationName === 'GetInsuranceCompanies') {
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,
};
response.data.accounts = response.data.accounts
.sort((a, b) => {
if (isSovkom(a)) return -1;
return account;
});
if (isSovkom(b)) return 1;
return 0;
})
.map((account) => {
const substring = account.label.match(/"(.+)"/u);
if (substring)
return {
...account,
label: substring ? substring[1].replaceAll('"', '').trim() : account.label,
};
return account;
});
}
}