process/load-kp: beautify types
This commit is contained in:
parent
102d3446e6
commit
f1fe8e48bd
@ -1,11 +1,8 @@
|
||||
import { gql } from '@apollo/client';
|
||||
import initializeApollo from 'apollo/client';
|
||||
import { RowSchema } from 'config/schema/insurance';
|
||||
import { defaultValues } from 'config/tables/insurance-table';
|
||||
import type * as CRMTypes from 'graphql/crm.types';
|
||||
import { z } from 'zod';
|
||||
import type { GetQuoteDataInput } from '../load-kp/types';
|
||||
import { GetQuoteDataOutputSchema } from '../load-kp/types';
|
||||
import type { GetQuoteDataInput, GetQuoteDataOutput } from '../load-kp/types';
|
||||
|
||||
const DEFAULT_FINGAP_ROW = defaultValues.find((x) => x.key === 'fingap')!;
|
||||
|
||||
@ -22,16 +19,12 @@ const QUERY_GET_RISKS = gql`
|
||||
}
|
||||
`;
|
||||
|
||||
const QuoteFingapProcessDataSchema = z.object({
|
||||
insurance: z.object({
|
||||
values: z.object({
|
||||
fingap: RowSchema,
|
||||
}),
|
||||
}),
|
||||
fingap: GetQuoteDataOutputSchema.shape.fingap,
|
||||
});
|
||||
|
||||
type QuoteFingapProcessData = z.infer<typeof QuoteFingapProcessDataSchema>;
|
||||
type QuoteFingapProcessData = {
|
||||
insurance: {
|
||||
values: Pick<GetQuoteDataOutput['insurance']['values'], 'fingap'>;
|
||||
};
|
||||
fingap: GetQuoteDataOutput['fingap'];
|
||||
};
|
||||
|
||||
export default async function getFingapDataFromKP({
|
||||
values: { quote: quoteId },
|
||||
@ -50,18 +43,16 @@ export default async function getFingapDataFromKP({
|
||||
},
|
||||
});
|
||||
|
||||
const values: Array<{ key: string }> = [];
|
||||
const keys: Array<string> = [];
|
||||
quote?.evo_product_risks?.forEach((x) => {
|
||||
if (x.evo_addproduct_typeid) {
|
||||
values.push({
|
||||
key: x.evo_addproduct_typeid,
|
||||
});
|
||||
keys.push(x.evo_addproduct_typeid);
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
fingap: {
|
||||
values,
|
||||
keys,
|
||||
},
|
||||
insurance: {
|
||||
values: {
|
||||
|
||||
@ -50,7 +50,7 @@ export default function loadKpReactions({ store, trpcClient }: ReactionsContext)
|
||||
extend($tables.insurance).setRowValues(insurance.values.fingap);
|
||||
}
|
||||
|
||||
if (fingap) $tables.fingap.setSelectedKeys(fingap.values?.map((x) => x.key));
|
||||
if (fingap) $tables.fingap.setSelectedKeys(fingap.keys);
|
||||
|
||||
message.success({
|
||||
key,
|
||||
|
||||
@ -25,11 +25,7 @@ export const GetQuoteDataOutputSchema = z.object({
|
||||
.required(),
|
||||
fingap: z
|
||||
.object({
|
||||
values: z.array(
|
||||
RiskSchema.pick({
|
||||
key: true,
|
||||
})
|
||||
),
|
||||
keys: z.array(RiskSchema.shape.key),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
|
||||
@ -3,9 +3,7 @@ import { gql } from '@apollo/client';
|
||||
import initializeApollo from 'apollo/client';
|
||||
import type * as CRMTypes from 'graphql/crm.types';
|
||||
import { sort } from 'radash';
|
||||
import { z } from 'zod';
|
||||
import type { GetQuoteDataInput } from '../load-kp/types';
|
||||
import { GetQuoteDataOutputSchema } from '../load-kp/types';
|
||||
import type { GetQuoteDataInput, GetQuoteDataOutput } from '../load-kp/types';
|
||||
|
||||
const QUERY_GET_PAYMENTS_DATA_FROM_QUOTE = gql`
|
||||
query GetPaymentsDataFromQuote($quoteId: Uuid!) {
|
||||
@ -29,12 +27,10 @@ const QUERY_GET_PAYMENTS_DATA_FROM_QUOTE = gql`
|
||||
}
|
||||
`;
|
||||
|
||||
const { values, payments } = GetQuoteDataOutputSchema.shape;
|
||||
const QuotePaymentsProcessDataSchema = z.object({
|
||||
values: values.partial(),
|
||||
payments,
|
||||
});
|
||||
type QuotePaymentsProcessData = z.infer<typeof QuotePaymentsProcessDataSchema>;
|
||||
type QuotePaymentsProcessData = {
|
||||
values: Partial<GetQuoteDataOutput['values']>;
|
||||
payments: GetQuoteDataOutput['payments'];
|
||||
};
|
||||
|
||||
export default async function getPaymentsDataFromKP({
|
||||
values: { quote: quoteId, recalcWithRevision },
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
import { gql } from '@apollo/client';
|
||||
import initializeApollo from 'apollo/client';
|
||||
import type * as CRMTypes from 'graphql/crm.types';
|
||||
import { z } from 'zod';
|
||||
import type { GetQuoteDataInput } from '../../load-kp/types';
|
||||
import { GetQuoteDataOutputSchema } from '../../load-kp/types';
|
||||
import type { GetQuoteDataInput, GetQuoteDataOutput } from '../../load-kp/types';
|
||||
import getSums from './get-sums';
|
||||
|
||||
const QUERY_GET_AGENTS_DATA_FROM_QUOTE = gql`
|
||||
@ -39,10 +37,10 @@ const QUERY_GET_AGENTS_DATA_FROM_QUOTE = gql`
|
||||
`;
|
||||
|
||||
export type Quote = NonNullable<CRMTypes.GetAgentsDataFromQuoteQuery['quote']>;
|
||||
const QuoteSupplierAgentProcessDataSchema = z.object({
|
||||
values: GetQuoteDataOutputSchema.shape.values.partial(),
|
||||
});
|
||||
type QuoteSupplierAgentProcessData = z.infer<typeof QuoteSupplierAgentProcessDataSchema>;
|
||||
|
||||
type QuoteSupplierAgentProcessData = {
|
||||
values: Partial<GetQuoteDataOutput['values']>;
|
||||
};
|
||||
|
||||
export default async function getSupplierAgentsDataFromKP({
|
||||
values: { quote: quoteId },
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user