replace createKp with post request
This commit is contained in:
parent
2a1caa90c3
commit
928c5966b1
@ -2,10 +2,10 @@ import { SERVER_PORT } from 'core/constants/urls';
|
||||
|
||||
export const API_HOSTNAME = window.location.hostname;
|
||||
|
||||
export const getServerUrl = url =>
|
||||
export const getServerUrl = (...url) =>
|
||||
String.prototype.concat(
|
||||
(process.env.NODE_ENV === 'development' &&
|
||||
`http://${API_HOSTNAME}:${SERVER_PORT}`) ||
|
||||
'',
|
||||
url || '',
|
||||
...url,
|
||||
);
|
||||
|
||||
@ -1,12 +1,7 @@
|
||||
import { IMutateToCRMGQL } from './../../core/types/Calculation/Requests';
|
||||
import { ApolloClient, gql, HttpLink, InMemoryCache } from '@apollo/client';
|
||||
import axios from 'axios';
|
||||
import { getServerUrl } from 'client/common/urls';
|
||||
import {
|
||||
CORE_PROXY_URL,
|
||||
CRM_GRAPHQL_PROXY_URL,
|
||||
CRM_GRAPHQL_URL,
|
||||
} from 'core/constants/urls';
|
||||
import { CORE_PROXY_URL, CRM_PROXY_URL, CRM_URL } from 'core/constants/urls';
|
||||
import { convertEntityToOption } from 'core/tools/entities';
|
||||
import { convertJSONToGQLQuery } from 'core/tools/query';
|
||||
import {
|
||||
@ -20,16 +15,20 @@ import {
|
||||
IGetUserResponse,
|
||||
} from 'core/types/Calculation/Responses';
|
||||
import { IBaseOption } from 'core/types/Calculation/Store/options';
|
||||
import { TCRMEntity } from 'core/types/Entities/crmEntities';
|
||||
import { IQuote, TCRMEntity } from 'core/types/Entities/crmEntities';
|
||||
import { TEntities } from 'core/types/Entities/crmEntityNames';
|
||||
import { isPlural, singular } from 'pluralize';
|
||||
import {
|
||||
ICreateKpRequest,
|
||||
IMutateToCRMGQL,
|
||||
} from './../../core/types/Calculation/Requests';
|
||||
|
||||
const client = new ApolloClient({
|
||||
uri: CRM_GRAPHQL_URL,
|
||||
uri: CRM_URL,
|
||||
cache: new InMemoryCache(),
|
||||
|
||||
link: new HttpLink({
|
||||
uri: getServerUrl(String.prototype.concat('/proxy', CRM_GRAPHQL_PROXY_URL)),
|
||||
uri: getServerUrl('/proxy', CRM_PROXY_URL),
|
||||
}),
|
||||
|
||||
defaultOptions: {
|
||||
@ -43,9 +42,14 @@ const client = new ApolloClient({
|
||||
class CalculationService {
|
||||
static getUser = (): Promise<IGetUserResponse> =>
|
||||
new Promise((resolve, reject) => {
|
||||
axios.get('/api/users/getUser').then(res => {
|
||||
resolve(res.data);
|
||||
});
|
||||
axios
|
||||
.get('/api/users/getUser')
|
||||
.then(res => {
|
||||
resolve(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
|
||||
static calculate = (
|
||||
@ -55,14 +59,12 @@ class CalculationService {
|
||||
axios
|
||||
.post<IGetCalculationResponse>(
|
||||
getServerUrl(
|
||||
String.prototype.concat(
|
||||
'/proxy',
|
||||
CORE_PROXY_URL,
|
||||
'/api',
|
||||
'/v1',
|
||||
'/calculation',
|
||||
'/calculate',
|
||||
),
|
||||
'/proxy',
|
||||
CORE_PROXY_URL,
|
||||
'/api',
|
||||
'/v1',
|
||||
'/calculation',
|
||||
'/calculate',
|
||||
),
|
||||
preparedData,
|
||||
)
|
||||
@ -98,8 +100,8 @@ class CalculationService {
|
||||
resEntities[targetName];
|
||||
|
||||
if (toOptions)
|
||||
//@ts-ignore
|
||||
if (toOptions.includes(targetName)) {
|
||||
//@ts-ignore
|
||||
//@ts-ignore
|
||||
if (Array.isArray(targetEnt)) {
|
||||
let optionatedEntities: (TCRMEntity & IBaseOption)[] = [];
|
||||
@ -160,6 +162,21 @@ class CalculationService {
|
||||
});
|
||||
});
|
||||
|
||||
static createKp = (data: ICreateKpRequest): Promise<IQuote> =>
|
||||
new Promise(async (resolve, reject) => {
|
||||
axios
|
||||
.post<IQuote>(
|
||||
getServerUrl('/proxy', CRM_PROXY_URL, '/offer', '/leasingcalculator'),
|
||||
data,
|
||||
)
|
||||
.then(res => {
|
||||
resolve(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
|
||||
@ -174,50 +174,37 @@ const actions: TAction = {
|
||||
console.log('domainName', domainName);
|
||||
// }
|
||||
|
||||
CalculationService.crmgqlmutaion({
|
||||
mutation: gql`
|
||||
mutation CreateOffer(
|
||||
$postValues: PostValuesInput
|
||||
$columns: CalculationColumnsInput
|
||||
$preparedValues: PreparedValuesInput
|
||||
$preparedPayments: PreparedPaymentsInput
|
||||
$values: CalculationValuesInput
|
||||
$domainName: String
|
||||
) {
|
||||
createBy(domainName: $domainName) {
|
||||
createOfferLeasingCalculator(
|
||||
calculation: {
|
||||
calculationColumns: $columns
|
||||
postValues: $postValues
|
||||
preparedValues: $preparedValues
|
||||
preparedPayments: $preparedPayments
|
||||
calculationValues: $values
|
||||
}
|
||||
) {
|
||||
offerprintform
|
||||
evo_quotename
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
values,
|
||||
columns,
|
||||
postValues,
|
||||
preparedValues,
|
||||
preparedPayments,
|
||||
domainName,
|
||||
},
|
||||
CalculationService.createKp({
|
||||
domainName,
|
||||
preparedValues,
|
||||
preparedPayments,
|
||||
calculationColumns: columns,
|
||||
postValues,
|
||||
calculationValues: values,
|
||||
})
|
||||
.then(({ entities: { quote } }) => {
|
||||
message.success({
|
||||
content: `КП ${quote.evo_quotename} создано!`,
|
||||
duration: 5,
|
||||
style: {
|
||||
marginTop: '7vh',
|
||||
.then(({ quoteid }) => {
|
||||
CalculationService.crmgqlquery({
|
||||
query: gql`
|
||||
query($quoteid: String) {
|
||||
quote(quoteId: $quoteid) {
|
||||
offerprintform
|
||||
evo_quotename
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
quoteid,
|
||||
},
|
||||
}).then(({ entities: { quote } }) => {
|
||||
message.success({
|
||||
content: `КП ${quote.evo_quotename} создано!`,
|
||||
duration: 5,
|
||||
style: {
|
||||
marginTop: '7vh',
|
||||
},
|
||||
});
|
||||
if (quote.offerprintform) window.open(quote.offerprintform, '_blank');
|
||||
});
|
||||
if (quote.offerprintform) window.open(quote.offerprintform, '_blank');
|
||||
})
|
||||
.catch(err => {
|
||||
throw err;
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
export const SERVER_PORT = process.env.NODE_ENV === 'development' ? 3001 : 80;
|
||||
export const CRM_GRAPHQL_URL =
|
||||
export const CRM_URL =
|
||||
process.env.crm !== 'prod'
|
||||
? 'http://crmgraphql-dev.evoleasing.ru'
|
||||
: 'http://crm-graphql.evoleasing.ru';
|
||||
export const CRM_GRAPHQL_PROXY_URL = '/crmgraphql';
|
||||
export const CRM_PROXY_URL = '/crmgraphql';
|
||||
export const CORE_URL =
|
||||
process.env.NODE_ENV === 'development'
|
||||
? 'http://localhost:5000'
|
||||
|
||||
@ -4,6 +4,8 @@ import {
|
||||
} from 'core/types/Calculation/Prepare';
|
||||
import { CRMEntityNames } from 'core/types/Entities/crmEntityNames';
|
||||
import { TEntityQuery } from '../Entities/query';
|
||||
import { ColumnsNames, IColumn, PostValues } from 'core/types/Calculation/Core';
|
||||
import { TValues } from 'core/types/Calculation/Store/values';
|
||||
|
||||
export interface IGetEntitiesRequest {
|
||||
queries: TEntityQuery[];
|
||||
@ -24,3 +26,12 @@ export interface IGetCalculationRequest {
|
||||
preparedPayments: PreparedPayments;
|
||||
preparedValues: PreparedValues;
|
||||
}
|
||||
|
||||
export interface ICreateKpRequest {
|
||||
domainName: string;
|
||||
preparedValues: PreparedValues;
|
||||
preparedPayments: PreparedPayments;
|
||||
calculationColumns: { [column in ColumnsNames]?: IColumn };
|
||||
postValues: PostValues;
|
||||
calculationValues: TValues<any>;
|
||||
}
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
import { Router } from 'express';
|
||||
import proxy from 'express-http-proxy';
|
||||
import {
|
||||
CRM_GRAPHQL_PROXY_URL,
|
||||
CRM_GRAPHQL_URL,
|
||||
CRM_PROXY_URL,
|
||||
CRM_URL,
|
||||
CORE_URL,
|
||||
CORE_PROXY_URL,
|
||||
} from '../../core/constants/urls';
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.use(CRM_GRAPHQL_PROXY_URL, proxy(CRM_GRAPHQL_URL));
|
||||
router.use(CRM_PROXY_URL, proxy(CRM_URL));
|
||||
router.use(CORE_PROXY_URL, proxy(CORE_URL));
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user