From 09959e3ac3c104bd6628da70c89b27929eeb5c54 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Mon, 9 Sep 2024 15:57:28 +0300 Subject: [PATCH] =?UTF-8?q?apps/web:=20graphql:=20GetInsuranceCompanies=20?= =?UTF-8?q?->=20sort=20=D1=81=D0=BE=D0=B2=D0=BA=D0=BE=D0=BC=20first?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/apollo/link.js | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/apps/web/apollo/link.js b/apps/web/apollo/link.js index faa1baa..7c524da 100644 --- a/apps/web/apollo/link.js +++ b/apps/web/apollo/link.js @@ -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; + }); } }