fix(SW-2614): send language to API
We were missing the language param on some endpoints. We are still missing it on some, but I left those without when we don't need it, e.g. when only caring about the IDs in the response.
This commit is contained in:
committed by
Michael Zetterberg
parent
35a2ae9dcc
commit
e0fe5ff0d5
@@ -112,6 +112,7 @@ export default function GuestDetails({
|
|||||||
phoneNumber: data.phoneNumber,
|
phoneNumber: data.phoneNumber,
|
||||||
countryCode: data.countryCode,
|
countryCode: data.countryCode,
|
||||||
},
|
},
|
||||||
|
language: lang,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ export default function Confirmation({
|
|||||||
refId: bookedRoom.refId,
|
refId: bookedRoom.refId,
|
||||||
checkInDate,
|
checkInDate,
|
||||||
checkOutDate,
|
checkOutDate,
|
||||||
|
language: lang,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -157,6 +157,7 @@ export const updateBookingInput = z.object({
|
|||||||
countryCode: z.string().optional(),
|
countryCode: z.string().optional(),
|
||||||
})
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
|
language: z.nativeEnum(Lang).transform((val) => langToApiLang[val]),
|
||||||
})
|
})
|
||||||
|
|
||||||
// Query
|
// Query
|
||||||
|
|||||||
@@ -151,10 +151,13 @@ export const bookingMutationRouter = router({
|
|||||||
.mutation(async function ({ ctx, input }) {
|
.mutation(async function ({ ctx, input }) {
|
||||||
const accessToken = ctx.session?.token.access_token ?? ctx.serviceToken
|
const accessToken = ctx.session?.token.access_token ?? ctx.serviceToken
|
||||||
const { confirmationNumber } = ctx
|
const { confirmationNumber } = ctx
|
||||||
const { refId, ...body } = input
|
const { language, refId, ...body } = input
|
||||||
|
|
||||||
const addPackageCounter = createCounter("trpc.booking", "package.add")
|
const addPackageCounter = createCounter("trpc.booking", "package.add")
|
||||||
const metricsAddPackage = addPackageCounter.init({ confirmationNumber })
|
const metricsAddPackage = addPackageCounter.init({
|
||||||
|
confirmationNumber,
|
||||||
|
language,
|
||||||
|
})
|
||||||
|
|
||||||
metricsAddPackage.start()
|
metricsAddPackage.start()
|
||||||
|
|
||||||
@@ -167,7 +170,8 @@ export const bookingMutationRouter = router({
|
|||||||
{
|
{
|
||||||
headers,
|
headers,
|
||||||
body: body,
|
body: body,
|
||||||
}
|
},
|
||||||
|
{ language }
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
if (!apiResponse.ok) {
|
||||||
@@ -192,11 +196,12 @@ export const bookingMutationRouter = router({
|
|||||||
.mutation(async function ({ ctx, input }) {
|
.mutation(async function ({ ctx, input }) {
|
||||||
const accessToken = ctx.session?.token.access_token ?? ctx.serviceToken
|
const accessToken = ctx.session?.token.access_token ?? ctx.serviceToken
|
||||||
const { confirmationNumber } = ctx
|
const { confirmationNumber } = ctx
|
||||||
const { refId, language, ...body } = input
|
const { language, refId, ...body } = input
|
||||||
|
|
||||||
const guaranteeBookingCounter = createCounter("trpc.booking", "guarantee")
|
const guaranteeBookingCounter = createCounter("trpc.booking", "guarantee")
|
||||||
const metricsGuaranteeBooking = guaranteeBookingCounter.init({
|
const metricsGuaranteeBooking = guaranteeBookingCounter.init({
|
||||||
confirmationNumber,
|
confirmationNumber,
|
||||||
|
language,
|
||||||
})
|
})
|
||||||
|
|
||||||
metricsGuaranteeBooking.start()
|
metricsGuaranteeBooking.start()
|
||||||
@@ -236,11 +241,12 @@ export const bookingMutationRouter = router({
|
|||||||
.mutation(async function ({ ctx, input }) {
|
.mutation(async function ({ ctx, input }) {
|
||||||
const accessToken = ctx.session?.token.access_token || ctx.serviceToken
|
const accessToken = ctx.session?.token.access_token || ctx.serviceToken
|
||||||
const { confirmationNumber } = ctx
|
const { confirmationNumber } = ctx
|
||||||
const { refId, ...body } = input
|
const { language, refId, ...body } = input
|
||||||
|
|
||||||
const updateBookingCounter = createCounter("trpc.booking", "update")
|
const updateBookingCounter = createCounter("trpc.booking", "update")
|
||||||
const metricsUpdateBooking = updateBookingCounter.init({
|
const metricsUpdateBooking = updateBookingCounter.init({
|
||||||
confirmationNumber,
|
confirmationNumber,
|
||||||
|
language,
|
||||||
})
|
})
|
||||||
|
|
||||||
metricsUpdateBooking.start()
|
metricsUpdateBooking.start()
|
||||||
@@ -252,7 +258,8 @@ export const bookingMutationRouter = router({
|
|||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${accessToken}`,
|
Authorization: `Bearer ${accessToken}`,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
|
{ language }
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
if (!apiResponse.ok) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
safeProtectedServiceProcedure,
|
safeProtectedServiceProcedure,
|
||||||
serviceProcedure,
|
serviceProcedure,
|
||||||
} from "@/server/trpc"
|
} from "@/server/trpc"
|
||||||
|
import { toApiLang } from "@/server/utils"
|
||||||
|
|
||||||
import { getBookedHotelRoom } from "@/utils/booking"
|
import { getBookedHotelRoom } from "@/utils/booking"
|
||||||
|
|
||||||
@@ -208,11 +209,13 @@ export const bookingQueryRouter = router({
|
|||||||
.input(getBookingStatusInput)
|
.input(getBookingStatusInput)
|
||||||
.concat(refIdPlugin.toConfirmationNumber)
|
.concat(refIdPlugin.toConfirmationNumber)
|
||||||
.query(async function ({ ctx }) {
|
.query(async function ({ ctx }) {
|
||||||
const { confirmationNumber } = ctx
|
const { confirmationNumber, lang } = ctx
|
||||||
|
const language = toApiLang(lang)
|
||||||
|
|
||||||
const getBookingStatusCounter = createCounter("trpc.booking", "status")
|
const getBookingStatusCounter = createCounter("trpc.booking", "status")
|
||||||
const metricsGetBookingStatus = getBookingStatusCounter.init({
|
const metricsGetBookingStatus = getBookingStatusCounter.init({
|
||||||
confirmationNumber,
|
confirmationNumber,
|
||||||
|
language,
|
||||||
})
|
})
|
||||||
|
|
||||||
metricsGetBookingStatus.start()
|
metricsGetBookingStatus.start()
|
||||||
@@ -223,7 +226,8 @@ export const bookingQueryRouter = router({
|
|||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${ctx.serviceToken}`,
|
Authorization: `Bearer ${ctx.serviceToken}`,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
|
{ language }
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
if (!apiResponse.ok) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
router,
|
router,
|
||||||
safeProtectedProcedure,
|
safeProtectedProcedure,
|
||||||
} from "@/server/trpc"
|
} from "@/server/trpc"
|
||||||
|
import { toApiLang } from "@/server/utils"
|
||||||
|
|
||||||
import { isValidSession } from "@/utils/session"
|
import { isValidSession } from "@/utils/session"
|
||||||
import { getFriendsMembership, getMembershipCards } from "@/utils/user"
|
import { getFriendsMembership, getMembershipCards } from "@/utils/user"
|
||||||
@@ -154,7 +155,8 @@ export const userQueryRouter = router({
|
|||||||
|
|
||||||
const previousStaysData = await getPreviousStays(
|
const previousStaysData = await getPreviousStays(
|
||||||
ctx.session.token.access_token,
|
ctx.session.token.access_token,
|
||||||
1
|
1,
|
||||||
|
ctx.lang
|
||||||
)
|
)
|
||||||
if (!previousStaysData) {
|
if (!previousStaysData) {
|
||||||
metricsUserTrackingInfo.success({
|
metricsUserTrackingInfo.success({
|
||||||
@@ -199,6 +201,7 @@ export const userQueryRouter = router({
|
|||||||
const data = await getPreviousStays(
|
const data = await getPreviousStays(
|
||||||
ctx.session.token.access_token,
|
ctx.session.token.access_token,
|
||||||
limit,
|
limit,
|
||||||
|
language,
|
||||||
cursor
|
cursor
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -231,6 +234,7 @@ export const userQueryRouter = router({
|
|||||||
const data = await getUpcomingStays(
|
const data = await getUpcomingStays(
|
||||||
ctx.session.token.access_token,
|
ctx.session.token.access_token,
|
||||||
limit,
|
limit,
|
||||||
|
language,
|
||||||
cursor
|
cursor
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -258,7 +262,7 @@ export const userQueryRouter = router({
|
|||||||
friendTransactions: languageProtectedProcedure
|
friendTransactions: languageProtectedProcedure
|
||||||
.input(friendTransactionsInput)
|
.input(friendTransactionsInput)
|
||||||
.query(async ({ ctx, input }) => {
|
.query(async ({ ctx, input }) => {
|
||||||
const { limit, page } = input
|
const { limit, page, lang } = input
|
||||||
|
|
||||||
const friendTransactionsCounter = createCounter(
|
const friendTransactionsCounter = createCounter(
|
||||||
"trpc.user.transactions",
|
"trpc.user.transactions",
|
||||||
@@ -268,16 +272,22 @@ export const userQueryRouter = router({
|
|||||||
const metricsFriendTransactions = friendTransactionsCounter.init({
|
const metricsFriendTransactions = friendTransactionsCounter.init({
|
||||||
limit,
|
limit,
|
||||||
page,
|
page,
|
||||||
|
lang,
|
||||||
})
|
})
|
||||||
|
|
||||||
metricsFriendTransactions.start()
|
metricsFriendTransactions.start()
|
||||||
|
|
||||||
|
const language = lang ?? ctx.lang
|
||||||
|
|
||||||
const apiResponse = await api.get(
|
const apiResponse = await api.get(
|
||||||
api.endpoints.v1.Profile.Transaction.friendTransactions,
|
api.endpoints.v1.Profile.Transaction.friendTransactions,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${ctx.session.token.access_token}`,
|
Authorization: `Bearer ${ctx.session.token.access_token}`,
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
language: toApiLang(language),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { env } from "@/env/server"
|
|||||||
import * as api from "@/lib/api"
|
import * as api from "@/lib/api"
|
||||||
import { dt } from "@/lib/dt"
|
import { dt } from "@/lib/dt"
|
||||||
import { createCounter } from "@/server/telemetry"
|
import { createCounter } from "@/server/telemetry"
|
||||||
|
import { toApiLang } from "@/server/utils"
|
||||||
|
|
||||||
import { cache } from "@/utils/cache"
|
import { cache } from "@/utils/cache"
|
||||||
import { encrypt } from "@/utils/encryption"
|
import { encrypt } from "@/utils/encryption"
|
||||||
@@ -114,17 +115,22 @@ export async function getMembershipNumber(
|
|||||||
export async function getPreviousStays(
|
export async function getPreviousStays(
|
||||||
accessToken: string,
|
accessToken: string,
|
||||||
limit: number = 10,
|
limit: number = 10,
|
||||||
|
language: Lang,
|
||||||
cursor?: string
|
cursor?: string
|
||||||
) {
|
) {
|
||||||
const getPreviousStaysCounter = createCounter("user", "getPreviousStays")
|
const getPreviousStaysCounter = createCounter("user", "getPreviousStays")
|
||||||
const metricsGetPreviousStays = getPreviousStaysCounter.init({
|
const metricsGetPreviousStays = getPreviousStaysCounter.init({
|
||||||
limit,
|
limit,
|
||||||
cursor,
|
cursor,
|
||||||
|
language,
|
||||||
})
|
})
|
||||||
|
|
||||||
metricsGetPreviousStays.start()
|
metricsGetPreviousStays.start()
|
||||||
|
|
||||||
const params: Record<string, string> = { limit: String(limit) }
|
const params: Record<string, string> = {
|
||||||
|
limit: String(limit),
|
||||||
|
language: toApiLang(language),
|
||||||
|
}
|
||||||
|
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
params.offset = cursor
|
params.offset = cursor
|
||||||
@@ -161,17 +167,22 @@ export async function getPreviousStays(
|
|||||||
export async function getUpcomingStays(
|
export async function getUpcomingStays(
|
||||||
accessToken: string,
|
accessToken: string,
|
||||||
limit: number = 10,
|
limit: number = 10,
|
||||||
|
language: Lang,
|
||||||
cursor?: string
|
cursor?: string
|
||||||
) {
|
) {
|
||||||
const getUpcomingStaysCounter = createCounter("user", "getUpcomingStays")
|
const getUpcomingStaysCounter = createCounter("user", "getUpcomingStays")
|
||||||
const metricsGetUpcomingStays = getUpcomingStaysCounter.init({
|
const metricsGetUpcomingStays = getUpcomingStaysCounter.init({
|
||||||
limit,
|
limit,
|
||||||
cursor,
|
cursor,
|
||||||
|
language,
|
||||||
})
|
})
|
||||||
|
|
||||||
metricsGetUpcomingStays.start()
|
metricsGetUpcomingStays.start()
|
||||||
|
|
||||||
const params: Record<string, string> = { limit: String(limit) }
|
const params: Record<string, string> = {
|
||||||
|
limit: String(limit),
|
||||||
|
language: toApiLang(language),
|
||||||
|
}
|
||||||
|
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
params.offset = cursor
|
params.offset = cursor
|
||||||
|
|||||||
Reference in New Issue
Block a user