40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { QueryOptions } from '@apollo/client';
|
|
import axios from 'axios';
|
|
import { CRM_PROXY_URL } from 'core/constants/urls';
|
|
import GQLClient from 'core/graphql/client';
|
|
import { ElementsNames } from 'core/types/Calculation/Store/elements';
|
|
import { IQuote, TCRMEntity } from 'core/types/Entities/crmEntities';
|
|
import { optionizeEntities } from './tools/entity';
|
|
|
|
export default class {
|
|
public static getCRMEntities<K extends string, R>(
|
|
queryOptions: QueryOptions<
|
|
Partial<Record<keyof R, any>> | Record<string, any>,
|
|
Record<K, R>
|
|
>,
|
|
) {
|
|
return GQLClient.query<
|
|
Record<K, R>,
|
|
Partial<Record<keyof R, any> | Record<string, any>>
|
|
>(queryOptions).then(res => res.data);
|
|
}
|
|
|
|
public static getCRMOptions<K extends string = ElementsNames, R = TCRMEntity>(
|
|
queryOptions: QueryOptions<
|
|
Partial<Record<keyof R, any>> | Record<string, any>,
|
|
Record<K, R>
|
|
>,
|
|
) {
|
|
return this.getCRMEntities<K, R | R[]>(queryOptions).then(entities =>
|
|
optionizeEntities<K, R>(entities),
|
|
);
|
|
}
|
|
|
|
public static createKP(data) {
|
|
return axios.post<IQuote>(
|
|
String.prototype.concat(CRM_PROXY_URL, '/offer', '/leasingcalculator'),
|
|
data,
|
|
);
|
|
}
|
|
}
|