107 lines
2.8 KiB
TypeScript
107 lines
2.8 KiB
TypeScript
/* eslint-disable import/prefer-default-export */
|
|
import type { ApolloClient } from '@apollo/client';
|
|
import { gql } from '@apollo/client';
|
|
import dayjs from 'dayjs';
|
|
import utc from 'dayjs/plugin/utc';
|
|
import type { GetMainOptions } from './__generated__/GetMainOptions';
|
|
import type { GetRegions } from './__generated__/GetRegions';
|
|
import type { GetSubsidies } from './__generated__/GetSubsidies';
|
|
|
|
dayjs.extend(utc);
|
|
|
|
const QUERY_GET_MAIN_OPTIONS = gql`
|
|
query GetMainOptions($currentDate: DateTime) {
|
|
selectSupplierCurrency: transactioncurrencies {
|
|
label: currencyname
|
|
currencysymbol
|
|
value: transactioncurrencyid
|
|
}
|
|
|
|
selectProduct: evo_baseproducts(
|
|
statecode: 0
|
|
evo_relation: [100000000]
|
|
evo_datefrom_param: { lte: $currentDate }
|
|
evo_dateto_param: { gte: $currentDate }
|
|
) {
|
|
label: evo_name
|
|
value: evo_baseproductid
|
|
}
|
|
|
|
selectLeaseObjectType: evo_leasingobject_types(statecode: 0) {
|
|
label: evo_name
|
|
value: evo_leasingobject_typeid
|
|
}
|
|
|
|
selectGPSBrand: evo_gps_brands(statecode: 0) {
|
|
label: evo_name
|
|
value: evo_gps_brandid
|
|
}
|
|
}
|
|
`;
|
|
|
|
const QUERY_GET_SUBSIDIES = gql`
|
|
query GetSubsidies($currentDate: DateTime) {
|
|
evo_subsidies(
|
|
statecode: 0
|
|
evo_datefrom_param: { lte: $currentDate }
|
|
evo_dateto_param: { gte: $currentDate }
|
|
) {
|
|
label: evo_name
|
|
value: evo_subsidyid
|
|
evo_subsidy_type
|
|
}
|
|
}
|
|
`;
|
|
|
|
const QUERY_GET_REGIONS = gql`
|
|
query GetRegions {
|
|
evo_regions {
|
|
label: evo_name
|
|
value: evo_regionid
|
|
}
|
|
}
|
|
`;
|
|
|
|
export default async function getMainData(apolloClient: ApolloClient<object>) {
|
|
// prettier-ignore
|
|
const { data: mainOptions } = await apolloClient.query<GetMainOptions>({
|
|
query: QUERY_GET_MAIN_OPTIONS,
|
|
variables: {
|
|
currentDate: dayjs().utc().toISOString()
|
|
}
|
|
});
|
|
|
|
const { data: subsidies } = await apolloClient.query<GetSubsidies>({
|
|
query: QUERY_GET_SUBSIDIES,
|
|
variables: {
|
|
currentDate: dayjs().utc().toISOString(),
|
|
},
|
|
});
|
|
const selectSubsidy = subsidies.evo_subsidies?.filter(
|
|
(x) => x?.evo_subsidy_type && [100_000_000, 100_000_001].includes(x?.evo_subsidy_type)
|
|
);
|
|
|
|
const selectImportProgram = subsidies.evo_subsidies?.filter(
|
|
(x) => x?.evo_subsidy_type && [100_000_002].includes(x?.evo_subsidy_type)
|
|
);
|
|
|
|
const { data: regions } = await apolloClient.query<GetRegions>({
|
|
query: QUERY_GET_REGIONS,
|
|
});
|
|
|
|
const selectRegionRegistration = regions.evo_regions;
|
|
const selectObjectRegionRegistration = regions.evo_regions;
|
|
const selectLegalClientRegion = regions.evo_regions;
|
|
|
|
return {
|
|
options: {
|
|
...mainOptions,
|
|
selectSubsidy,
|
|
selectImportProgram,
|
|
selectRegionRegistration,
|
|
selectObjectRegionRegistration,
|
|
selectLegalClientRegion,
|
|
},
|
|
};
|
|
}
|