Merged in feat/SW-3549-handle-unlinked-account (pull request #3019)

fix(SW-3549): update social session management functions for clarity and consistency

* refactor(SW-3549): rename session management functions for clarity and consistency

* merge


Approved-by: Hrishikesh Vaipurkar
This commit is contained in:
Joakim Jäderberg
2025-10-28 09:51:30 +00:00
parent 4a6c64f921
commit a4f1a55e56
15 changed files with 105 additions and 90 deletions

View File

@@ -5,7 +5,6 @@ import { router } from "../../.."
import * as api from "../../../api"
import { createRefIdPlugin } from "../../../plugins/refIdToConfirmationNumber"
import { safeProtectedServiceProcedure } from "../../../procedures"
import { isValidSession } from "../../../utils/session"
import {
addPackageInput,
cancelBookingsInput,
@@ -14,7 +13,7 @@ import {
updateBookingInput,
} from "../input"
import { bookingConfirmationSchema } from "../output"
import { cancelBooking, isPartnerLoggedInUser } from "../utils"
import { cancelBooking } from "../utils"
import { createBookingSchema } from "./create/schema"
import { create } from "./create"
@@ -26,10 +25,7 @@ export const bookingMutationRouter = router({
priceChange: safeProtectedServiceProcedure
.concat(refIdPlugin.toConfirmationNumber)
.use(async ({ ctx, next }) => {
const token =
isValidSession(ctx.session) && !isPartnerLoggedInUser(ctx.session)
? ctx.session.token.access_token
: ctx.serviceToken
const token = await ctx.getScandicUserToken()
return next({
ctx: {
@@ -38,13 +34,14 @@ export const bookingMutationRouter = router({
})
})
.mutation(async function ({ ctx }) {
const { confirmationNumber, token } = ctx
const { confirmationNumber } = ctx
const priceChangeCounter = createCounter("trpc.booking", "price-change")
const metricsPriceChange = priceChangeCounter.init({ confirmationNumber })
metricsPriceChange.start()
const token = ctx.token ?? ctx.serviceToken
const headers = {
Authorization: `Bearer ${token}`,
}
@@ -76,10 +73,7 @@ export const bookingMutationRouter = router({
.input(cancelBookingsInput)
.concat(refIdPlugin.toConfirmationNumbers)
.use(async ({ ctx, next }) => {
const token =
isValidSession(ctx.session) && !isPartnerLoggedInUser(ctx.session)
? ctx.session.token.access_token
: ctx.serviceToken
const token = await ctx.getScandicUserToken()
return next({
ctx: {
@@ -88,9 +82,10 @@ export const bookingMutationRouter = router({
})
})
.mutation(async function ({ ctx, input }) {
const { confirmationNumbers, token } = ctx
const { confirmationNumbers } = ctx
const { language } = input
const token = ctx.token ?? ctx.serviceToken
const responses = await Promise.allSettled(
confirmationNumbers.map((confirmationNumber) =>
cancelBooking(confirmationNumber, language, token)
@@ -120,11 +115,7 @@ export const bookingMutationRouter = router({
.input(addPackageInput)
.concat(refIdPlugin.toConfirmationNumber)
.use(async ({ ctx, next }) => {
const token =
isValidSession(ctx.session) && !isPartnerLoggedInUser(ctx.session)
? ctx.session.token.access_token
: ctx.serviceToken
const token = await ctx.getScandicUserToken()
return next({
ctx: {
token,
@@ -132,7 +123,7 @@ export const bookingMutationRouter = router({
})
})
.mutation(async function ({ ctx, input }) {
const { confirmationNumber, token } = ctx
const { confirmationNumber } = ctx
const { language, refId, ...body } = input
const addPackageCounter = createCounter("trpc.booking", "package.add")
@@ -143,6 +134,7 @@ export const bookingMutationRouter = router({
metricsAddPackage.start()
const token = ctx.token ?? ctx.serviceToken
const headers = {
Authorization: `Bearer ${token}`,
}
@@ -176,10 +168,7 @@ export const bookingMutationRouter = router({
.input(guaranteeBookingInput)
.concat(refIdPlugin.toConfirmationNumber)
.use(async ({ ctx, next }) => {
const token =
isValidSession(ctx.session) && !isPartnerLoggedInUser(ctx.session)
? ctx.session.token.access_token
: ctx.serviceToken
const token = await ctx.getScandicUserToken()
return next({
ctx: {
@@ -188,7 +177,7 @@ export const bookingMutationRouter = router({
})
})
.mutation(async function ({ ctx, input }) {
const { confirmationNumber, token } = ctx
const { confirmationNumber } = ctx
const { language, refId, ...body } = input
const guaranteeBookingCounter = createCounter("trpc.booking", "guarantee")
@@ -199,6 +188,7 @@ export const bookingMutationRouter = router({
metricsGuaranteeBooking.start()
const token = ctx.token ?? ctx.serviceToken
const headers = {
Authorization: `Bearer ${token}`,
}
@@ -232,10 +222,7 @@ export const bookingMutationRouter = router({
.input(updateBookingInput)
.concat(refIdPlugin.toConfirmationNumber)
.use(async ({ ctx, next }) => {
const token =
isValidSession(ctx.session) && !isPartnerLoggedInUser(ctx.session)
? ctx.session.token.access_token
: ctx.serviceToken
const token = await ctx.getScandicUserToken()
return next({
ctx: {
@@ -244,7 +231,7 @@ export const bookingMutationRouter = router({
})
})
.mutation(async function ({ ctx, input }) {
const { confirmationNumber, token } = ctx
const { confirmationNumber } = ctx
const { language, refId, ...body } = input
const updateBookingCounter = createCounter("trpc.booking", "update")
@@ -254,7 +241,7 @@ export const bookingMutationRouter = router({
})
metricsUpdateBooking.start()
const token = ctx.token ?? ctx.serviceToken
const apiResponse = await api.put(
api.endpoints.v1.Booking.booking(confirmationNumber),
{
@@ -287,10 +274,7 @@ export const bookingMutationRouter = router({
.input(removePackageInput)
.concat(refIdPlugin.toConfirmationNumber)
.use(async ({ ctx, next }) => {
const token =
isValidSession(ctx.session) && !isPartnerLoggedInUser(ctx.session)
? ctx.session.token.access_token
: ctx.serviceToken
const token = await ctx.getScandicUserToken()
return next({
ctx: {
@@ -299,7 +283,7 @@ export const bookingMutationRouter = router({
})
})
.mutation(async function ({ ctx, input }) {
const { confirmationNumber, token } = ctx
const { confirmationNumber } = ctx
const { codes, language } = input
const removePackageCounter = createCounter(
@@ -314,6 +298,7 @@ export const bookingMutationRouter = router({
metricsRemovePackage.start()
const token = ctx.token ?? ctx.serviceToken
const headers = {
Authorization: `Bearer ${token}`,
}