{"version":3,"file":"index-DHcsr5f9.js","sources":["../../Client/shared/Models/ComparisonQuoteModels/ComparisonQuoteImportantNoticeModel.ts","../../Client/api/ComparisonQuoteApi/index.ts"],"sourcesContent":["export enum ComparisonQuoteImportantNotice {\r\n // AKA CD-1 Form\r\n TexasUseOfCreditInformationDisclosure,\r\n}\r\n\r\nexport interface ComparisonQuoteImportantNoticeModel {\r\n readonly quoteId: string;\r\n readonly importantNotices: ComparisonQuoteImportantNotice[];\r\n}\r\n","import { ProductLine, RatingType, StateCode } from '@business/CommonSets';\r\nimport {\r\n ComparisonElementDescriptionModel,\r\n ComparisonQuoteImportantNotice,\r\n ComparisonQuoteImportantNoticeModel,\r\n ComparisonQuoteModel,\r\n ComparisonQuotesModel,\r\n CreateQuoteError,\r\n ElementDescriptions,\r\n Mutable,\r\n QuoteCreateRequestModel,\r\n QuotePatchRequestModel,\r\n} from '@shared/Models';\r\nimport { fetchAndLog, fetchAndLogWithResponse, uuidV4 } from '../Fetch';\r\n\r\nconst CacheBusterQueryString = `?_=${new Date().getTime()}`;\r\n\r\nexport type CreateQuoteResponseModel = {\r\n quoteId: string | null;\r\n quoteCount: number;\r\n error: CreateQuoteError | null;\r\n comparisonModel: ComparisonQuotesModel | null;\r\n};\r\n\r\n/** Creates or gets a quote based on ProductLine and QuoteCreateRequestModel and returns the response. */\r\nexport async function createOrGetQuotesByProduct(\r\n productLine: ProductLine,\r\n request: QuoteCreateRequestModel\r\n): Promise<CreateQuoteResponseModel> {\r\n return await createOrGetQuotesByProductInternal(productLine, request, 'PUT');\r\n}\r\n\r\n/** Forces a create quote using the provided ProductLine and QuoteCreateRequestModel and returns the response. */\r\nexport async function createQuotesByProduct(\r\n productLine: ProductLine,\r\n request: QuoteCreateRequestModel\r\n): Promise<CreateQuoteResponseModel> {\r\n return await createOrGetQuotesByProductInternal(productLine, request, 'POST');\r\n}\r\n\r\nasync function createOrGetQuotesByProductInternal(\r\n productLine: ProductLine,\r\n request: QuoteCreateRequestModel,\r\n method: 'POST' | 'PUT'\r\n): Promise<CreateQuoteResponseModel> {\r\n request.RequestUuid = uuidV4();\r\n\r\n const endpoint = productLine.switch<string>({\r\n onHomeowner: () => '/api/quotes',\r\n onCommercial: productLine.throwUnsupportedError,\r\n onFlood: () => '/api/flood/quotes',\r\n });\r\n\r\n const response = await fetchAndLogWithResponse(endpoint, `create or get ${productLine.lowercaseName} quote`, {\r\n method,\r\n body: JSON.stringify(request),\r\n });\r\n\r\n const json = await response.json();\r\n return {\r\n quoteId: response.ok ? json.Quotes[0].QuoteId : null,\r\n quoteCount: response.ok ? json.Quotes.length : 0,\r\n error: response.ok ? null : json,\r\n comparisonModel: response.ok ? json : null,\r\n };\r\n}\r\n\r\n/** Gets a ComparisonQuotesModel based on ProductLine and QuoteId. */\r\nexport async function getComparisonQuotesByProduct(\r\n productLine: ProductLine,\r\n quoteId: string\r\n): Promise<ComparisonQuotesModel> {\r\n const endpoint = productLine.switch<string>({\r\n onHomeowner: () => `/api/comparisonquotes/quoteId/${quoteId}`,\r\n onCommercial: () => `/api/commercial/quotes/comparisonquotes/quoteid/${quoteId}`,\r\n onFlood: () => `/api/flood/quotes/quoteId/${quoteId}`,\r\n });\r\n\r\n return await fetchAndLog<ComparisonQuotesModel>(endpoint, `get ${productLine.lowercaseName} comparison quotes`);\r\n}\r\n\r\n/** Gets a ComparisonElementDescriptionModel by ProductLine for each quote in the ComparisonQuotesModel. */\r\nexport async function getComparisonElementDescriptions(\r\n productLine: ProductLine,\r\n comparisonModel: ComparisonQuotesModel\r\n): Promise<ComparisonElementDescriptionModel[]> {\r\n const carrierCodes = comparisonModel.Quotes.map(quote => quote.CarrierCode || ''),\r\n stateCode = comparisonModel.QuoteProperty?.StateCode || '';\r\n\r\n return await Promise.all(carrierCodes.map(mapToElementDescriptions));\r\n\r\n async function mapToElementDescriptions(carrierCode: string): Promise<ComparisonElementDescriptionModel> {\r\n const elementDescriptions = await getElementDescriptions(productLine, stateCode, carrierCode),\r\n comparisonElementDescription = {\r\n carrierCode: carrierCode,\r\n descriptions: elementDescriptions,\r\n } as ComparisonElementDescriptionModel;\r\n return comparisonElementDescription;\r\n }\r\n}\r\n\r\n/** Gets ElementDescriptions based on product, stateCode, and carrierCode. */\r\nasync function getElementDescriptions(\r\n productLine: ProductLine,\r\n stateCode: string,\r\n carrierCode: string\r\n): Promise<ElementDescriptions> {\r\n return await fetchAndLog<ElementDescriptions>(\r\n `/api/elements/descriptions/${productLine.lowercaseName}/${stateCode}/${carrierCode}${CacheBusterQueryString}`,\r\n 'get element descriptions'\r\n );\r\n}\r\n\r\n/** Patches a comparison quote based on ProductLine and QuotePatchRequest and returns a ComparisonQuoteModel. */\r\nexport async function patchComparisonQuoteByProduct(\r\n productLine: ProductLine,\r\n quotePatchRequest: QuotePatchRequestModel,\r\n quoteOrder: string[]\r\n): Promise<ComparisonQuotesModel> {\r\n const endpoint = productLine.switch<string>({\r\n onHomeowner: () => '/api/quotes',\r\n onCommercial: () => '/api/commercial/quotes/new',\r\n onFlood: () => '/api/flood/quotes',\r\n });\r\n\r\n const comparisonQuoteModel = await fetchAndLog<Mutable<ComparisonQuotesModel>>(endpoint, 'patch comparison quote', {\r\n method: 'PATCH',\r\n body: JSON.stringify({ ...quotePatchRequest, IsComparisonQuote: true }),\r\n });\r\n\r\n const quotes: ComparisonQuoteModel[] = [];\r\n for (const quoteId of quoteOrder) {\r\n const quote = comparisonQuoteModel.Quotes.find(q => q.QuoteId === quoteId);\r\n if (quote) quotes.push(quote);\r\n }\r\n\r\n return { ...comparisonQuoteModel, Quotes: quotes };\r\n}\r\n\r\n/** Gets a ComparisonQuoteImportantNoticeModel for each quote in the ComparisonQuotesModel. These important notices are\r\n * defined in this method and are not currently provided by the server. */\r\nexport function getComparisonImportantNotices(\r\n productLine: ProductLine,\r\n comparisonModel: ComparisonQuotesModel\r\n): ComparisonQuoteImportantNoticeModel[] {\r\n return comparisonModel.Quotes.map(quote => {\r\n return {\r\n quoteId: quote.QuoteId,\r\n importantNotices: getImportantNotices(quote),\r\n } as ComparisonQuoteImportantNoticeModel;\r\n });\r\n\r\n function getImportantNotices(quote: ComparisonQuoteModel) {\r\n const importantNotices: ComparisonQuoteImportantNotice[] = [];\r\n\r\n if (\r\n productLine === ProductLine.Homeowner &&\r\n RatingType.parse(quote.RatingType) === RatingType.Admitted &&\r\n comparisonModel.QuoteProperty?.StateCode === StateCode.TX.code\r\n )\r\n importantNotices.push(ComparisonQuoteImportantNotice.TexasUseOfCreditInformationDisclosure);\r\n\r\n return importantNotices;\r\n }\r\n}\r\n"],"names":["ComparisonQuoteImportantNotice","ComparisonQuoteImportantNotice2","CacheBusterQueryString","createOrGetQuotesByProduct","productLine","request","createOrGetQuotesByProductInternal","createQuotesByProduct","method","uuidV4","endpoint","response","fetchAndLogWithResponse","json","getComparisonQuotesByProduct","quoteId","fetchAndLog","getComparisonElementDescriptions","comparisonModel","carrierCodes","quote","stateCode","_a","mapToElementDescriptions","carrierCode","elementDescriptions","getElementDescriptions","patchComparisonQuoteByProduct","quotePatchRequest","quoteOrder","comparisonQuoteModel","quotes","q","getComparisonImportantNotices","getImportantNotices","importantNotices","ProductLine","RatingType","StateCode"],"mappings":"8KAAY,IAAAA,GAAAA,IAERA,EAAAC,EAAA,sCAAA,CAAA,EAAA,wCAFQD,IAAAA,GAAA,CAAA,CAAA,ECeZ,MAAME,EAAyB,MAAM,IAAI,KAAK,EAAE,SAAS,GAUnC,eAAAC,EAClBC,EACAC,EACiC,CACjC,OAAO,MAAMC,EAAmCF,EAAaC,EAAS,KAAK,CAC/E,CAGsB,eAAAE,EAClBH,EACAC,EACiC,CACjC,OAAO,MAAMC,EAAmCF,EAAaC,EAAS,MAAM,CAChF,CAEA,eAAeC,EACXF,EACAC,EACAG,EACiC,CACjCH,EAAQ,YAAcI,EAAO,EAEvB,MAAAC,EAAWN,EAAY,OAAe,CACxC,YAAa,IAAM,cACnB,aAAcA,EAAY,sBAC1B,QAAS,IAAM,mBAAA,CAClB,EAEKO,EAAW,MA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