68 lines
1.5 KiB
JavaScript
68 lines
1.5 KiB
JavaScript
/* eslint-disable import/prefer-default-export */
|
|
import { gql, useQuery } from '@apollo/client';
|
|
import { useStore } from 'stores/hooks';
|
|
|
|
const QUERY_GET_INSURANCE_DATA = gql`
|
|
query GetInsuranceData($evo_account_type: [Int!]) {
|
|
osago: accounts(
|
|
evo_account_type: $evo_account_type
|
|
evo_type_ins_policy: [100000001]
|
|
statecode: 0
|
|
) {
|
|
value: accountid
|
|
label: name
|
|
}
|
|
|
|
kasko: accounts(
|
|
evo_account_type: $evo_account_type
|
|
evo_type_ins_policy: [100000000]
|
|
statecode: 0
|
|
) {
|
|
value: accountid
|
|
label: name
|
|
}
|
|
|
|
fingap: accounts(
|
|
evo_account_type: $evo_account_type
|
|
evo_type_ins_policy: [100000002]
|
|
statecode: 0
|
|
) {
|
|
value: accountid
|
|
label: name
|
|
}
|
|
}
|
|
`;
|
|
|
|
export function useInsuranceData() {
|
|
const { $tables } = useStore();
|
|
|
|
function handleOnCompleted(options) {
|
|
Object.keys(options).forEach((key) => {
|
|
const rowOptions = options[key];
|
|
if (rowOptions !== undefined) {
|
|
Object.keys(rowOptions).forEach((valueName) => {
|
|
$tables.insurance.row(key).setOptions(valueName, rowOptions[valueName]);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
useQuery(QUERY_GET_INSURANCE_DATA, {
|
|
onCompleted: (insuranceData) => {
|
|
const insurance = {
|
|
osago: {
|
|
insuranceCompany: insuranceData.osago,
|
|
},
|
|
kasko: {
|
|
insuranceCompany: insuranceData.kasko,
|
|
},
|
|
fingap: {
|
|
insuranceCompany: insuranceData.fingap,
|
|
},
|
|
};
|
|
|
|
handleOnCompleted(insurance);
|
|
},
|
|
});
|
|
}
|