filter evo_baseproducts on page load
This commit is contained in:
parent
0ff6ba3f74
commit
c3c7399823
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,4 +1,5 @@
|
||||
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';
|
||||
|
||||
@ -30,10 +31,29 @@ export async function getInitialData({ query }: ApolloClient<object>, user: User
|
||||
},
|
||||
});
|
||||
|
||||
let {
|
||||
data: { evo_baseproducts },
|
||||
} = await query({
|
||||
query: CRMTypes.GetProductsDocument,
|
||||
});
|
||||
|
||||
const {
|
||||
data: { systemuser },
|
||||
} = await query({
|
||||
fetchPolicy: 'network-only',
|
||||
query: CRMTypes.GetSystemUserDocument,
|
||||
variables: {
|
||||
domainname: user?.domainName,
|
||||
},
|
||||
});
|
||||
|
||||
evo_baseproducts = crmTools.evo_baseproducts(evo_baseproducts).filterBy.systemuser(systemuser);
|
||||
|
||||
return {
|
||||
options: {
|
||||
selectLead: leads,
|
||||
selectOpportunity: opportunities,
|
||||
selectProduct: evo_baseproducts,
|
||||
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