@procraft/widget-order
Version:
Order widget for landing
106 lines (91 loc) • 3.17 kB
text/typescript
import { WidgetOrderCourseItem } from '../../interfaces'
import {
CourseFragment,
CourseFragmentCatalogItem,
} from '../../interfaces/CourseFragment'
// import { Scalars } from '../../modules/gql/generated/types'
import { getCatalogItemData } from '../getCatalogItemData'
/**
* Из запроса всех данных получаем элементы каталога
* @deprecated
*/
export const getCatalogItems = (
course: CourseFragment,
catalogItem: CourseFragmentCatalogItem
// courseUid: Scalars['Int'],
// tariffUid: Scalars['Int']
): WidgetOrderCourseItem[] => {
// console.log('getCatalogItems course', course);
// console.log('getCatalogItems catalogItem', catalogItem);
const items: WidgetOrderCourseItem[] = []
// const course = courses.find((n) => n.uid === courseUid)
// if (!course) {
// console.error('getCatalogItems. Can not get course')
// } else {
const tariff = course.tariffs?.find(
(n) => n.uid === catalogItem.course?.tariffId
)
if (!tariff) {
console.error('getCatalogItems. Can not get tariff')
} else {
catalogItem.fieldValues?.map((fieldValue) => {
/**
* Получаем каталогитем по потоку, курсу и тарифу
*/
// const catalogItem = course.catalogItems?.find((catalogItem) => {
// return (
// catalogItem.course?.courseId === course.uid &&
// catalogItem.course.flowId === flow.uid &&
// catalogItem.course.tariffId === tariff.uid
// )
// })
// if (!catalogItem) {
// // console.error('getCatalogItems. Can not get catalogItem');
// return null
// }
fieldValue
// const catalogItemData = getCatalogItemData(catalogItem, course, tariff, flow);
// const catalogItemData = getCatalogItemData(catalogItem, course)
const catalogItemData = getCatalogItemData(fieldValue)
if (!catalogItemData) {
console.error('getCatalogItems. Can not get catalogItemData')
return null
}
const { placesLeft } = catalogItemData
// items.push({
// id: flow.id,
// uid: flow.uid,
// name: flow.name,
// price: catalogItem.unitPrice || 0,
// oldPrice: catalogItem.unitPriceOriginal || null,
// catalogItem,
// course: {
// flow,
// tariff,
// },
// placesLeft,
// reviewsCount: catalogItem.reviewsCount || undefined,
// reviews: catalogItem.reviews || undefined,
// subscriptions: catalogItem.subscriptions || undefined,
// })
items.push({
// id: fieldValue.id,
// uid: fieldValue.uid,
name: fieldValue.optionName,
price: catalogItem.unitPrice || 0,
oldPrice: catalogItem.unitPriceOriginal || null,
catalogItem,
course: {
// flow,
tariff,
},
placesLeft,
reviewsCount: catalogItem.reviewsCount || undefined,
reviews: catalogItem.reviews || undefined,
// subscriptions: catalogItem.subscriptions || undefined,
})
})
}
// }
return items
}