Merged in feat/SW-165-correct-labels (pull request #427)

Feat/SW-165 correct labels

* feat(SW-165): sort friend transactions and return additional properties

* feat(SW-165): Added points being calculated label

* feat(SW-165): added transactionDate for transactions without checkinDate

* feat(SW-165): Updated description copy for various reward types

* feat(SW-165): filter out expired transactions

* feat(SW-165): removed Mobile table and unified them into Table instead

* feat(SW-165): Added bookingUrl to friend transactions

* fix(SW-165): style fixes

* fix(SW-165): fix issues from merge

* fix(SW-165): remove comment

* fix(SW-165): fixed booking urls not being set and smaller fixes

* fix(SW-165): added comment regarding 'BALFWD'


Approved-by: Michael Zetterberg
Approved-by: Christel Westerberg
This commit is contained in:
Tobias Johansson
2024-08-21 13:54:55 +00:00
parent 72ebc14f7d
commit 1ec1033267
21 changed files with 292 additions and 239 deletions

View File

@@ -26,6 +26,7 @@ import {
staysInput,
} from "./input"
import {
FriendTransaction,
getCreditCardsSchema,
getFriendTransactionsSchema,
getMembershipCardsSchema,
@@ -38,6 +39,7 @@ import { benefits, extendedUser, nextLevelPerks } from "./temp"
import type { Session } from "next-auth"
import { RewardTransactionTypes } from "@/types/components/myPages/myPage/enums"
import type {
LoginType,
TrackingSDKUserData,
@@ -91,11 +93,23 @@ function fakingRequest<T>(payload: T): Promise<T> {
})
}
const updateStaysBookingUrl = async (
async function updateStaysBookingUrl(
data: Stay[],
token: string,
lang: Lang
) => {
): Promise<Stay[]>
async function updateStaysBookingUrl(
data: FriendTransaction[],
token: string,
lang: Lang
): Promise<FriendTransaction[]>
async function updateStaysBookingUrl(
data: Stay[] | FriendTransaction[],
token: string,
lang: Lang
) {
// Tenporary API call needed till we have user name in ctx session data
const apiResponse = await api.get(api.endpoints.v1.profile, {
cache: "no-store",
@@ -135,9 +149,9 @@ const updateStaysBookingUrl = async (
if (apiResponse.ok) {
const apiJson = await apiResponse.json()
if (apiJson.data?.attributes) {
return data.map((stay: Stay) => {
return data.map((d) => {
const originalString =
stay.attributes.confirmationNumber.toString() +
d.attributes.confirmationNumber.toString() +
"," +
apiJson.data.attributes.lastName
const encryptedBookingValue = encryptValue(originalString)
@@ -147,11 +161,11 @@ const updateStaysBookingUrl = async (
"?lastName=" +
apiJson.data.attributes.lastName +
"&bookingId=" +
stay.attributes.confirmationNumber
d.attributes.confirmationNumber
return {
...stay,
...d,
attributes: {
...stay.attributes,
...d.attributes,
bookingUrl: bookingUrl,
},
}
@@ -492,15 +506,29 @@ export const userQueryRouter = router({
return null
}
const pageData = verifiedData.data.data.slice(
limit * (page - 1),
limit * page
const updatedData = await updateStaysBookingUrl(
verifiedData.data.data,
ctx.session.token.access_token,
ctx.lang
)
const pageData = updatedData
.filter((t) => t.type !== RewardTransactionTypes.expired)
.sort((a, b) => {
// 'BALFWD' are transactions from Opera migration that happended in May 2021
const isBalfwd =
a.type === RewardTransactionTypes.stayAdj &&
a.attributes.confirmationNumber === "BALFWD"
if (isBalfwd) return 1
return a.attributes.checkinDate > b.attributes.checkinDate ? -1 : 1
})
.slice(limit * (page - 1), limit * page)
return {
data: {
transactions: pageData.map(({ attributes }) => {
transactions: pageData.map(({ type, attributes }) => {
return {
type,
awardPoints: attributes.awardPoints,
checkinDate: attributes.checkinDate,
checkoutDate: attributes.checkoutDate,
@@ -508,6 +536,10 @@ export const userQueryRouter = router({
confirmationNumber: attributes.confirmationNumber,
hotelName: attributes.hotelInformation?.name,
nights: attributes.nights,
pointsCalculated: attributes.pointsCalculated,
hotelId: attributes.hotelOperaId,
transactionDate: attributes.transactionDate,
bookingUrl: attributes.bookingUrl,
}
}),
},