feat (SW-2864): Move booking router to trpc package * Add env to trpc package * Add eslint to trpc package * Apply lint rules * Use direct imports from trpc package * Add lint-staged config to trpc * Move lang enum to common * Restructure trpc package folder structure * WIP first step * update internal imports in trpc * Fix most errors in scandic-web Just 100 left... * Move Props type out of trpc * Fix CategorizedFilters types * Move more schemas in hotel router * Fix deps * fix getNonContentstackUrls * Fix import error * Fix entry error handling * Fix generateMetadata metrics * Fix alertType enum * Fix duplicated types * lint:fix * Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package * Fix broken imports * Move booking router to trpc package * Merge branch 'master' into feat/sw-2864-move-hotels-router-to-trpc-package Approved-by: Linus Flood
116 lines
3.6 KiB
TypeScript
116 lines
3.6 KiB
TypeScript
import { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
|
|
|
|
import type { Packages } from "@scandic-hotels/trpc/types/packages"
|
|
|
|
import type { Price } from "@/types/components/hotelReservation/price"
|
|
import type {
|
|
Rate,
|
|
Room,
|
|
} from "@/types/components/hotelReservation/selectRate/selectRate"
|
|
|
|
export function mapRate(
|
|
room: Rate,
|
|
index: number,
|
|
bookingRooms: Room[],
|
|
packages: NonNullable<Packages>
|
|
) {
|
|
const rate = {
|
|
adults: bookingRooms[index].adults,
|
|
cancellationText: room.product.rateDefinition?.cancellationText ?? "",
|
|
childrenInRoom: bookingRooms[index].childrenInRoom ?? undefined,
|
|
rateDetails: room.product.rateDefinition?.generalTerms,
|
|
roomPrice: {
|
|
currency: CurrencyEnum.Unknown,
|
|
perNight: <Price>{
|
|
local: {
|
|
currency: CurrencyEnum.Unknown,
|
|
price: 0,
|
|
},
|
|
requested: undefined,
|
|
},
|
|
perStay: <Price>{
|
|
local: {
|
|
currency: CurrencyEnum.Unknown,
|
|
price: 0,
|
|
},
|
|
requested: undefined,
|
|
},
|
|
},
|
|
roomRate: room.product,
|
|
roomType: room.roomType,
|
|
packages,
|
|
}
|
|
|
|
if ("corporateCheque" in room.product) {
|
|
rate.roomPrice.currency = CurrencyEnum.CC
|
|
rate.roomPrice.perNight.local = {
|
|
currency: CurrencyEnum.CC,
|
|
price: room.product.corporateCheque.localPrice.numberOfCheques,
|
|
additionalPrice:
|
|
room.product.corporateCheque.localPrice.additionalPricePerStay,
|
|
additionalPriceCurrency:
|
|
room.product.corporateCheque.localPrice.currency ??
|
|
CurrencyEnum.Unknown,
|
|
}
|
|
rate.roomPrice.perStay.local = {
|
|
currency: CurrencyEnum.CC,
|
|
price: room.product.corporateCheque.localPrice.numberOfCheques,
|
|
additionalPrice:
|
|
room.product.corporateCheque.localPrice.additionalPricePerStay,
|
|
additionalPriceCurrency:
|
|
room.product.corporateCheque.localPrice.currency ??
|
|
CurrencyEnum.Unknown,
|
|
}
|
|
} else if ("redemption" in room.product) {
|
|
rate.roomPrice.currency = CurrencyEnum.POINTS
|
|
rate.roomPrice.perNight.local = {
|
|
currency: CurrencyEnum.POINTS,
|
|
price: room.product.redemption.localPrice.pointsPerNight,
|
|
additionalPrice:
|
|
room.product.redemption.localPrice.additionalPricePerStay,
|
|
additionalPriceCurrency:
|
|
room.product.redemption.localPrice.currency ?? CurrencyEnum.Unknown,
|
|
}
|
|
rate.roomPrice.perStay.local = {
|
|
currency: CurrencyEnum.POINTS,
|
|
price: room.product.redemption.localPrice.pointsPerStay,
|
|
additionalPrice:
|
|
room.product.redemption.localPrice.additionalPricePerStay,
|
|
additionalPriceCurrency:
|
|
room.product.redemption.localPrice.currency ?? CurrencyEnum.Unknown,
|
|
}
|
|
} else if ("voucher" in room.product) {
|
|
rate.roomPrice.currency = CurrencyEnum.Voucher
|
|
rate.roomPrice.perNight.local = {
|
|
currency: CurrencyEnum.Voucher,
|
|
price: room.product.voucher.numberOfVouchers,
|
|
}
|
|
rate.roomPrice.perStay.local = {
|
|
currency: CurrencyEnum.Voucher,
|
|
price: room.product.voucher.numberOfVouchers,
|
|
}
|
|
} else {
|
|
const currency =
|
|
room.product.public?.localPrice.currency ||
|
|
room.product.member?.localPrice.currency ||
|
|
CurrencyEnum.Unknown
|
|
rate.roomPrice.currency = currency
|
|
rate.roomPrice.perNight.local = {
|
|
currency,
|
|
price:
|
|
room.product.public?.localPrice.pricePerNight ||
|
|
room.product.member?.localPrice.pricePerNight ||
|
|
0,
|
|
}
|
|
rate.roomPrice.perStay.local = {
|
|
currency,
|
|
price:
|
|
room.product.public?.localPrice.pricePerStay ||
|
|
room.product.member?.localPrice.pricePerStay ||
|
|
0,
|
|
}
|
|
}
|
|
|
|
return rate
|
|
}
|