fix using queries in code

This commit is contained in:
vchikalkin 2024-04-16 17:38:34 +03:00
parent 8f80ed5446
commit 5ee420dde6
10 changed files with 81 additions and 44 deletions

View File

@ -31,13 +31,15 @@ query GetCurrencyChanges($currentDate: DateTime) {
}
query GetLeads($domainname: String) {
leads(
systemusers(
filterConditionGroup: {
andFilterConditions: { filterConditionString: { fieldName: "domainname", eq: $domainname } }
}
) {
label: fullname
value: leadid
leads {
label: fullname
value: leadid
}
}
}

View File

@ -1,12 +1,14 @@
import type * as CRMTypes from '@/graphql/crm.types';
function evo_baseproducts(evo_baseproducts: CRMTypes.GetProductsQuery['evo_baseproducts']) {
type SystemUser = NonNullable<CRMTypes.GetSystemUserQuery['systemusers']>[number];
function evo_baseproducts(baseproducts: CRMTypes.GetProductsQuery['evo_baseproducts']) {
return {
filterBy: {
systemuser(systemuser: CRMTypes.GetSystemUserQuery['systemuser']) {
if (!evo_baseproducts?.length || !systemuser) return [];
systemuser(systemuser: SystemUser) {
if (!baseproducts?.length || !systemuser) return [];
return evo_baseproducts?.filter(
return baseproducts?.filter(
(evo_baseproduct) =>
!evo_baseproduct?.systemusers?.length ||
evo_baseproduct?.systemusers?.some(

View File

@ -1852,7 +1852,7 @@ export type GetLeadsQueryVariables = Exact<{
}>;
export type GetLeadsQuery = { __typename?: 'Query', leads: Array<{ __typename?: 'lead', label: string | null, value: any | null } | null> | null };
export type GetLeadsQuery = { __typename?: 'Query', systemusers: Array<{ __typename?: 'systemuser', leads: Array<{ __typename?: 'lead', label: string | null, value: any | null } | null> | null } | null> | null };
export type GetLeadQueryVariables = Exact<{
leadid: Scalars['UUID']['input'];
@ -2213,7 +2213,7 @@ export const CoreAddProductTypesFieldsFragmentDoc = {"kind":"Document","definiti
export const GetTransactionCurrenciesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetTransactionCurrencies"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"transactioncurrencies"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"currencyname"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"transactioncurrencyid"}},{"kind":"Field","name":{"kind":"Name","value":"transactioncurrencyid"}},{"kind":"Field","name":{"kind":"Name","value":"isocurrencycode"}},{"kind":"Field","name":{"kind":"Name","value":"currencysymbol"}}]}}]}}]} as unknown as DocumentNode<GetTransactionCurrenciesQuery, GetTransactionCurrenciesQueryVariables>;
export const GetTransactionCurrencyDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetTransactionCurrency"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currencyid"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"transactioncurrency"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"transactioncurrencyid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currencyid"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"currencysymbol"}},{"kind":"Field","name":{"kind":"Name","value":"isocurrencycode"}},{"kind":"Field","name":{"kind":"Name","value":"transactioncurrencyid"}}]}}]}}]} as unknown as DocumentNode<GetTransactionCurrencyQuery, GetTransactionCurrencyQueryVariables>;
export const GetCurrencyChangesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetCurrencyChanges"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_currencychanges"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filterConditionGroup"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"andFilterConditions"},"value":{"kind":"ListValue","values":[{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"filterConditionInt"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"fieldName"},"value":{"kind":"StringValue","value":"statecode","block":false}},{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"IntValue","value":"0"}}]}}]},{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"filterConditionDateTime"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"fieldName"},"value":{"kind":"StringValue","value":"evo_coursedate","block":false}},{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}}]}]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_currencychange"}},{"kind":"Field","name":{"kind":"Name","value":"evo_ref_transactioncurrency"}}]}}]}}]} as unknown as DocumentNode<GetCurrencyChangesQuery, GetCurrencyChangesQueryVariables>;
export const GetLeadsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetLeads"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"domainname"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"leads"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filterConditionGroup"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"andFilterConditions"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"filterConditionString"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"fieldName"},"value":{"kind":"StringValue","value":"domainname","block":false}},{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"domainname"}}}]}}]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"fullname"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"leadid"}}]}}]}}]} as unknown as DocumentNode<GetLeadsQuery, GetLeadsQueryVariables>;
export const GetLeadsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetLeads"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"domainname"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"systemusers"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filterConditionGroup"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"andFilterConditions"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"filterConditionString"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"fieldName"},"value":{"kind":"StringValue","value":"domainname","block":false}},{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"domainname"}}}]}}]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"leads"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"fullname"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"leadid"}}]}}]}}]}}]} as unknown as DocumentNode<GetLeadsQuery, GetLeadsQueryVariables>;
export const GetLeadDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetLead"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"leadid"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"lead"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"leadid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"leadid"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_agent_accountid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_double_agent_accountid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_broker_accountid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_fin_department_accountid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_opportunityidData"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"opportunityid"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_inn"}},{"kind":"Field","name":{"kind":"Name","value":"accountidData"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_address_legalidData"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_region_fias_id"}},{"kind":"Field","name":{"kind":"Name","value":"evo_city_fias_id"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_okved"}}]}},{"kind":"Field","name":{"kind":"Name","value":"link"}}]}}]}}]} as unknown as DocumentNode<GetLeadQuery, GetLeadQueryVariables>;
export const GetOpportunityDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetOpportunity"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"opportunityid"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"opportunity"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"opportunityid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"opportunityid"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_leadid"}},{"kind":"Field","name":{"kind":"Name","value":"accountidData"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_address_legalidData"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_region_fias_id"}},{"kind":"Field","name":{"kind":"Name","value":"evo_city_fias_id"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_okved"}}]}},{"kind":"Field","name":{"kind":"Name","value":"link"}}]}}]}}]} as unknown as DocumentNode<GetOpportunityQuery, GetOpportunityQueryVariables>;
export const GetOpportunitiesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetOpportunities"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"domainname"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"systemusers"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filterConditionGroup"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"andFilterConditions"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"filterConditionString"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"fieldName"},"value":{"kind":"StringValue","value":"domainname","block":false}},{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"domainname"}}}]}}]}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"opportunities"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"opportunityid"}}]}}]}}]}}]} as unknown as DocumentNode<GetOpportunitiesQuery, GetOpportunitiesQueryVariables>;

View File

@ -13,7 +13,7 @@ export default function helper({ apolloClient, user }: ValidationContext) {
}
const {
data: { systemuser },
data: { systemusers },
} = await apolloClient.query({
query: CRMTypes.GetSystemUserDocument,
variables: {
@ -21,6 +21,8 @@ export default function helper({ apolloClient, user }: ValidationContext) {
},
});
const systemuser = systemusers?.[0];
if (!systemuser?.evo_job_titleid) {
return null;
}

View File

@ -369,7 +369,7 @@ export default function reactions({ store, apolloClient, user }: ProcessContext)
if (user && evo_baseproducts) {
const {
data: { systemuser },
data: { systemusers },
} = await apolloClient.query({
fetchPolicy: 'network-only',
query: CRMTypes.GetSystemUserDocument,
@ -378,9 +378,13 @@ export default function reactions({ store, apolloClient, user }: ProcessContext)
},
});
evo_baseproducts = crmTools
.evo_baseproducts(evo_baseproducts)
.filterBy.systemuser(systemuser);
const systemuser = systemusers?.[0];
if (systemuser) {
evo_baseproducts = crmTools
.evo_baseproducts(evo_baseproducts)
.filterBy.systemuser(systemuser);
}
}
if (!$calculation.element('cbxRecalcWithRevision').getValue()) {

View File

@ -16,23 +16,35 @@ export default function unlimitedReactions({ store, apolloClient }: ProcessConte
return;
}
const {
data: { leads },
} = await apolloClient.query({
query: CRMTypes.GetLeadsDocument,
variables: { domainname },
});
$calculation.element('selectLead').setOptions(normalizeOptions(leads));
{
const { data } = await apolloClient.query({
query: CRMTypes.GetLeadsDocument,
variables: { domainname },
});
const {
data: { opportunities },
} = await apolloClient.query({
query: CRMTypes.GetOpportunitiesDocument,
variables: { domainname },
});
const systemuser = data?.systemusers?.[0];
$calculation.element('selectOpportunity').setOptions(normalizeOptions(opportunities));
if (systemuser) {
const { leads } = systemuser;
$calculation.element('selectLead').setOptions(normalizeOptions(leads));
}
}
{
const { data } = await apolloClient.query({
query: CRMTypes.GetOpportunitiesDocument,
variables: { domainname },
});
const systemuser = data?.systemusers?.[0];
if (systemuser) {
const { opportunities } = systemuser;
$calculation.element('selectOpportunity').setOptions(normalizeOptions(opportunities));
}
}
}
);
}

View File

@ -22,9 +22,14 @@ function getMainData({ query }, onCompleted, user) {
query: CRMTypes.GetLeadsDocument,
variables: { domainname: user.domainName },
}).then(({ data }) => {
onCompleted({
selectLead: data?.leads,
});
const systemuser = data?.systemusers?.[0];
if (systemuser) {
const { leads } = systemuser;
onCompleted({
selectLead: leads,
});
}
});
query({
@ -46,16 +51,22 @@ function getMainData({ query }, onCompleted, user) {
fetchPolicy: 'network-only',
query: CRMTypes.GetSystemUserDocument,
variables: { domainname: user?.domainName },
}).then(({ data: { systemuser } }) => {
query({
fetchPolicy: 'network-only',
query: CRMTypes.GetProductsDocument,
variables: { currentDate },
}).then(({ data: { evo_baseproducts } }) => {
onCompleted({
selectProduct: crmTools.evo_baseproducts(evo_baseproducts).filterBy.systemuser(systemuser),
}).then(({ data: { systemusers } }) => {
const systemuser = systemusers?.[0];
if (systemuser) {
query({
fetchPolicy: 'network-only',
query: CRMTypes.GetProductsDocument,
variables: { currentDate },
}).then(({ data: { evo_baseproducts } }) => {
onCompleted({
selectProduct: crmTools
.evo_baseproducts(evo_baseproducts)
.filterBy.systemuser(systemuser),
});
});
});
}
});
// query({

View File

@ -18,7 +18,7 @@ export const userMiddleware = t.middleware(async ({ ctx, next }) => {
const apolloClient = initializeApollo();
const {
data: { systemuser },
data: { systemusers },
} = await apolloClient.query({
query: CRMTypes.GetSystemUserDocument,
variables: {
@ -26,6 +26,8 @@ export const userMiddleware = t.middleware(async ({ ctx, next }) => {
},
});
const systemuser = systemusers?.at(0);
const unlimited = systemuser?.roles?.some((x) => x?.name && unlimitedRoles.includes(x.name));
return next({

View File

@ -76,7 +76,7 @@ export async function createRequestData({
const currentDate = dayjs().utc(false);
let systemuser: CRMTypes.GetSystemUserQuery['systemuser'] = null;
let systemuser: NonNullable<CRMTypes.GetSystemUserQuery['systemusers']>[number] = null;
if (user?.domainName) {
const { data } = await apolloClient.query({
@ -85,7 +85,7 @@ export async function createRequestData({
domainname: user.domainName,
},
});
if (data.systemuser) systemuser = data.systemuser;
systemuser = data.systemusers?.at(0) ?? null;
}
async function getDeprecation() {

View File

@ -31,7 +31,7 @@ export function makeGetUserType({ apolloClient, queryClient }: MakeGetUserTypePr
);
const {
data: { systemuser },
data: { systemusers },
} = await apolloClient.query({
fetchPolicy: 'network-only',
query: CRMTypes.GetSystemUserDocument,
@ -40,6 +40,8 @@ export function makeGetUserType({ apolloClient, queryClient }: MakeGetUserTypePr
},
});
const systemuser = systemusers?.[0];
const roles = systemuser?.roles ? sift(systemuser?.roles)?.map((x) => x?.name) : [];
return {