partial: rewrite reactions
This commit is contained in:
parent
cd8f7f7447
commit
7a043aae3a
@ -43,7 +43,6 @@ const Calculation = () => {
|
||||
{ entities: staticEntities },
|
||||
{ entities: insuranceCompanies },
|
||||
]) => {
|
||||
console.log(insuranceCompanies);
|
||||
calculationStore.applyOptions(initialOptions);
|
||||
calculationStore.applyStaticData(staticEntities);
|
||||
calculationStore.setTableColumns('tableInsurance')({
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import axios from 'axios';
|
||||
import CalculationStore from 'client/stores/CalculationStore';
|
||||
import { IGetEntitiesRequest } from 'core/types/Calculation/Requests';
|
||||
import { IGetEntitiesResponse } from 'core/types/Calculation/Responses';
|
||||
|
||||
@ -14,7 +15,8 @@ class CalculationService {
|
||||
resolve(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
CalculationStore.showModal(err);
|
||||
// reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -17,7 +17,7 @@ import {
|
||||
import { staticData, staticDataAction } from './Data/staticEntities';
|
||||
import autorunEffects from './Effects/autorun';
|
||||
import computedEffects from './Effects/computed';
|
||||
// import reactionEffects from './Effects/reaction';
|
||||
import reactionEffects from './Effects/reaction';
|
||||
import whenEffects from './Effects/when';
|
||||
|
||||
const CalculationStore: ICalculationStore = makeAutoObservable(
|
||||
@ -42,15 +42,15 @@ autorunEffects.map(autorunEffect =>
|
||||
autorun(autorunEffect(CalculationStore, CommonStore)),
|
||||
);
|
||||
|
||||
// reactionEffects.map(reactionEffectBuilder => {
|
||||
// const reactionEffect = reactionEffectBuilder(CalculationStore);
|
||||
// return reaction(reactionEffect.expression, reactionEffect.effect, {
|
||||
// ...reactionEffect.options,
|
||||
// equals: (nextParams, prevParams) => {
|
||||
// return isEqual(nextParams, prevParams);
|
||||
// },
|
||||
// });
|
||||
// });
|
||||
reactionEffects.map(reactionEffectBuilder => {
|
||||
const reactionEffect = reactionEffectBuilder(CalculationStore);
|
||||
return reaction(reactionEffect.expression, reactionEffect.effect, {
|
||||
...reactionEffect.options,
|
||||
equals: (nextParams, prevParams) => {
|
||||
return isEqual(nextParams, prevParams);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
whenEffects.map(whenEffectBuilder => {
|
||||
const whenEffect = whenEffectBuilder(CalculationStore);
|
||||
|
||||
@ -7,7 +7,15 @@ const initialOptions: TEntityQuery[] = [
|
||||
{
|
||||
alias: 'selectLead',
|
||||
entityName: 'lead',
|
||||
fields: ['leadid', 'fullname', 'evo_opportunityid'],
|
||||
fields: [
|
||||
'leadid',
|
||||
'fullname',
|
||||
'evo_opportunityid',
|
||||
'evo_agent_accountid',
|
||||
'evo_double_agent_accountid',
|
||||
'evo_broker_accountid',
|
||||
'evo_fin_department_accountid',
|
||||
],
|
||||
where: { statecode: 0 },
|
||||
many: true,
|
||||
},
|
||||
|
||||
@ -28,7 +28,6 @@ const convert = {
|
||||
return res_related.toString().replace(/"/, '');
|
||||
},
|
||||
where: (where: TWhere<any>): string => {
|
||||
// return JSON.stringify(whereIn || {}).replace(/[^\w\s,[\]:!?]/g, '');
|
||||
return stringifyObject(where);
|
||||
},
|
||||
whereCmp: (whereCmp?: TWhere<ComparisonOperators>) => {
|
||||
@ -44,7 +43,8 @@ const convert = {
|
||||
|
||||
function convertNestedEntity(query: TBaseEntityQuery) {
|
||||
let entityQuery: string = `${
|
||||
query.many ? plural(query.entityName) : query.entityName}{
|
||||
query.many ? plural(query.entityName) : query.entityName
|
||||
}{
|
||||
${convert.fields(query.fields)}
|
||||
${convert.relatedEntities(query.relatedEntities)}
|
||||
}`;
|
||||
|
||||
@ -4,7 +4,7 @@ import { TValue, TValues } from './Store/values';
|
||||
|
||||
export interface IGetEntitiesRequest {
|
||||
queries: TEntityQuery[];
|
||||
toOptions: boolean;
|
||||
toOptions?: boolean;
|
||||
}
|
||||
|
||||
export interface IGetCalculationRequest {
|
||||
|
||||
@ -2,7 +2,7 @@ import { TCRMEntity } from '../Entities/crmEntities';
|
||||
import { TEntities } from '../Entities/crmEntityNames';
|
||||
|
||||
export interface IGetEntitiesResponse {
|
||||
entities: TEntities<TCRMEntity[]>;
|
||||
entities: TEntities<TCRMEntity | TCRMEntity[]>;
|
||||
}
|
||||
|
||||
export interface IGetCalculationResponse {
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
import { CRMEntityNames } from './crmEntityNames';
|
||||
|
||||
interface AccountData {}
|
||||
|
||||
export interface IAccount {
|
||||
name?: string;
|
||||
accountid?: string;
|
||||
@ -14,7 +12,6 @@ export interface IAccount {
|
||||
ownerid?: string;
|
||||
evo_broker_accountid?: string;
|
||||
evo_client_riskid?: string;
|
||||
accountidData?: AccountData;
|
||||
evo_type_ins_policy?: number[];
|
||||
}
|
||||
|
||||
@ -25,6 +22,11 @@ export interface ILead {
|
||||
account?: string;
|
||||
ownerid?: string;
|
||||
statecode?: number;
|
||||
evo_fin_department_accountid?: string;
|
||||
evo_broker_accountid?: string;
|
||||
evo_double_agent_accountid?: string;
|
||||
evo_agent_accountid?: string;
|
||||
accountidData?: IAccount;
|
||||
}
|
||||
|
||||
export interface IOpportunity {
|
||||
@ -34,6 +36,7 @@ export interface IOpportunity {
|
||||
evo_client_riskid?: string;
|
||||
ownerid?: string;
|
||||
statecode?: number;
|
||||
accountidData?: IAccount;
|
||||
}
|
||||
|
||||
export interface IQuote {
|
||||
|
||||
@ -30,7 +30,16 @@ export type CRMEntityNames =
|
||||
| 'systemuser'
|
||||
| 'evo_sot_coefficient_type';
|
||||
|
||||
export const CRMEntityAliases = [
|
||||
'agent',
|
||||
'double_agent',
|
||||
'broker',
|
||||
'findepartment',
|
||||
] as const;
|
||||
type CRMEntityAliasesType = typeof CRMEntityAliases;
|
||||
export type CRMEntityAliasesUnion = CRMEntityAliasesType[number];
|
||||
|
||||
//TODO: or string
|
||||
export type TEntities<T> = {
|
||||
[entityName in CRMEntityNames]?: T;
|
||||
[entityName in CRMEntityNames | CRMEntityAliasesUnion]?: T;
|
||||
};
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
// import { ElementsNames } from 'core/types/Calculation/Store/elements';
|
||||
import { TCRMEntity } from './crmEntities';
|
||||
import { CRMEntityNames } from './crmEntityNames';
|
||||
import { CRMEntityNames, CRMEntityAliasesUnion } from './crmEntityNames';
|
||||
import { ElementsNames } from 'core/types/Calculation/Store/elements';
|
||||
|
||||
export type ComparisonOperators = {
|
||||
eq?: any;
|
||||
@ -15,8 +16,7 @@ export type TEntitiesKeys = keyof TCRMEntity;
|
||||
export type TWhere<T> = { [prop in TEntitiesKeys]?: T };
|
||||
|
||||
export type TBaseEntityQuery = {
|
||||
//TODO: alias: ElementsNames
|
||||
alias?: string;
|
||||
alias?: CRMEntityAliasesUnion | ElementsNames;
|
||||
entityName: CRMEntityNames;
|
||||
fields: [TEntitiesKeys, ...TEntitiesKeys[]];
|
||||
relatedEntities?: TBaseEntityQuery[];
|
||||
|
||||
@ -13,8 +13,10 @@ import {
|
||||
import {
|
||||
CRMEntityNames,
|
||||
TEntities,
|
||||
CRMEntityAliases,
|
||||
} from '../../../core/types/Entities/crmEntityNames';
|
||||
import { getEntities } from './crmManager';
|
||||
import { singular, isPlural } from 'pluralize';
|
||||
|
||||
class CalculationController {
|
||||
static getCRMEntities = async (
|
||||
@ -22,7 +24,13 @@ class CalculationController {
|
||||
res: Response,
|
||||
next: NextFunction,
|
||||
): Promise<any> => {
|
||||
const { queries, toOptions } = req.body as IGetEntitiesRequest;
|
||||
let { queries, toOptions } = req.body as IGetEntitiesRequest;
|
||||
|
||||
queries = queries.filter(query => {
|
||||
return Object.values(query.where).some(
|
||||
x => x !== null && x !== undefined,
|
||||
);
|
||||
});
|
||||
let resEntities = await getEntities(queries);
|
||||
if (toOptions) {
|
||||
let entitiesWithOptions: TEntities<TCRMEntity & IBaseOption> = {};
|
||||
@ -37,7 +45,12 @@ class CalculationController {
|
||||
convertEntityToOption(entity, entity.__typename),
|
||||
);
|
||||
}
|
||||
entitiesWithOptions[name] = optionatedOptions;
|
||||
entitiesWithOptions[
|
||||
//@ts-ignore
|
||||
!CRMEntityAliases.includes(name) && isPlural(name)
|
||||
? singular(name)
|
||||
: name
|
||||
] = optionatedOptions;
|
||||
});
|
||||
res.send({ entities: entitiesWithOptions });
|
||||
return;
|
||||
|
||||
@ -3,7 +3,6 @@ import { Router } from 'express';
|
||||
|
||||
const router = Router();
|
||||
|
||||
//TODO: use
|
||||
router.post('/getCRMEntities', CalculationController.getCRMEntities);
|
||||
router.post('/calculate', CalculationController.calculate);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user