merge fix/evo_baseproducts-filter
This commit is contained in:
parent
0ff6ba3f74
commit
07c87d583f
25
apps/web/graphql/crm.tools.ts
Normal file
25
apps/web/graphql/crm.tools.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import type * as CRMTypes from '@/graphql/crm.types';
|
||||
|
||||
function evo_baseproducts(evo_baseproducts: CRMTypes.GetProductsQuery['evo_baseproducts']) {
|
||||
return {
|
||||
filterBy: {
|
||||
systemuser(systemuser: CRMTypes.GetSystemUserQuery['systemuser']) {
|
||||
if (!evo_baseproducts?.length || !systemuser) return [];
|
||||
|
||||
return evo_baseproducts?.filter(
|
||||
(evo_baseproduct) =>
|
||||
!evo_baseproduct?.systemusers?.length ||
|
||||
evo_baseproduct?.systemusers?.some(
|
||||
(evo_baseproduct_systemuser) =>
|
||||
systemuser?.systemuserid &&
|
||||
evo_baseproduct_systemuser?.systemuserid === systemuser?.systemuserid
|
||||
)
|
||||
);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const crmTools = {
|
||||
evo_baseproducts,
|
||||
};
|
||||
@ -1,5 +1,6 @@
|
||||
/* eslint-disable sonarjs/cognitive-complexity */
|
||||
import { radioCalcType, radioGraphType, selectSeasonType } from '@/config/default-options';
|
||||
import { crmTools } from '@/graphql/crm.tools';
|
||||
import * as CRMTypes from '@/graphql/crm.types';
|
||||
import { SEASON_TYPES } from '@/process/payments/lib/seasons-constants';
|
||||
import type { ProcessContext } from '@/process/types';
|
||||
@ -380,15 +381,9 @@ export default function reactions({ store, apolloClient, user }: ProcessContext)
|
||||
},
|
||||
});
|
||||
|
||||
evo_baseproducts = evo_baseproducts?.filter(
|
||||
(x) =>
|
||||
!x?.systemusers?.length ||
|
||||
x?.systemusers?.some(
|
||||
(evo_baseproduct_systemuser) =>
|
||||
systemuser?.systemuserid &&
|
||||
evo_baseproduct_systemuser?.systemuserid === systemuser?.systemuserid
|
||||
)
|
||||
);
|
||||
evo_baseproducts = crmTools
|
||||
.evo_baseproducts(evo_baseproducts)
|
||||
.filterBy.systemuser(systemuser);
|
||||
}
|
||||
|
||||
if (!$calculation.element('cbxRecalcWithRevision').getValue()) {
|
||||
@ -434,9 +429,6 @@ export default function reactions({ store, apolloClient, user }: ProcessContext)
|
||||
} else {
|
||||
$calculation.element('selectProduct').setOptions(normalizeOptions(evo_baseproducts));
|
||||
}
|
||||
},
|
||||
{
|
||||
fireImmediately: true,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,39 +1,70 @@
|
||||
import type { User } from '@/api/user/types';
|
||||
import { crmTools } from '@/graphql/crm.tools';
|
||||
import * as CRMTypes from '@/graphql/crm.types';
|
||||
import type { ApolloClient } from '@apollo/client';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
export async function getInitialData({ query }: ApolloClient<object>, user: User) {
|
||||
const {
|
||||
data: { leads },
|
||||
} = await query({ query: CRMTypes.GetLeadsDocument, variables: { domainname: user.domainName } });
|
||||
|
||||
const {
|
||||
data: { opportunities },
|
||||
} = await query({
|
||||
const leadsQuery = query({
|
||||
query: CRMTypes.GetLeadsDocument,
|
||||
variables: { domainname: user.domainName },
|
||||
});
|
||||
const opportunitiesQuery = query({
|
||||
query: CRMTypes.GetOpportunitiesDocument,
|
||||
variables: { domainname: user.domainName },
|
||||
});
|
||||
|
||||
const {
|
||||
data: { transactioncurrencies },
|
||||
} = await query({
|
||||
query: CRMTypes.GetTransactionCurrenciesDocument,
|
||||
const transactionCurrenciesQuery = query({ query: CRMTypes.GetTransactionCurrenciesDocument });
|
||||
const productsQuery = query({
|
||||
fetchPolicy: 'network-only',
|
||||
query: CRMTypes.GetProductsDocument,
|
||||
variables: { currentDate: dayjs().utc(false).toISOString() },
|
||||
});
|
||||
const systemUserQuery = query({
|
||||
fetchPolicy: 'network-only',
|
||||
query: CRMTypes.GetSystemUserDocument,
|
||||
variables: { domainname: user?.domainName },
|
||||
});
|
||||
|
||||
const [
|
||||
{
|
||||
data: { leads },
|
||||
},
|
||||
{
|
||||
data: { opportunities },
|
||||
},
|
||||
{
|
||||
data: { transactioncurrencies },
|
||||
},
|
||||
{
|
||||
data: { evo_baseproducts },
|
||||
},
|
||||
{
|
||||
data: { systemuser },
|
||||
},
|
||||
] = await Promise.all([
|
||||
leadsQuery,
|
||||
opportunitiesQuery,
|
||||
transactionCurrenciesQuery,
|
||||
productsQuery,
|
||||
systemUserQuery,
|
||||
]);
|
||||
|
||||
const transactioncurrency_rub = transactioncurrencies?.find((x) => x?.isocurrencycode === 'RUB');
|
||||
|
||||
if (transactioncurrency_rub?.transactioncurrencyid)
|
||||
if (transactioncurrency_rub?.transactioncurrencyid) {
|
||||
await query({
|
||||
query: CRMTypes.GetTransactionCurrencyDocument,
|
||||
variables: {
|
||||
currencyid: transactioncurrency_rub?.transactioncurrencyid,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
options: {
|
||||
selectLead: leads,
|
||||
selectOpportunity: opportunities,
|
||||
selectProduct: crmTools.evo_baseproducts(evo_baseproducts).filterBy.systemuser(systemuser),
|
||||
selectSupplierCurrency: transactioncurrencies,
|
||||
},
|
||||
values: {
|
||||
|
||||
@ -33,17 +33,6 @@ function getMainData({ query }, onCompleted) {
|
||||
});
|
||||
});
|
||||
|
||||
query({
|
||||
query: CRMTypes.GetProductsDocument,
|
||||
variables: {
|
||||
currentDate,
|
||||
},
|
||||
}).then(({ data }) => {
|
||||
onCompleted({
|
||||
selectProduct: data?.evo_baseproducts,
|
||||
});
|
||||
});
|
||||
|
||||
query({
|
||||
query: CRMTypes.GetSubsidiesDocument,
|
||||
variables: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user