Merged in feat/SW-1371-delete-ancillary (pull request #1455)
feat(SW-1371): delete ancillary * feat(SW-1371): delete ancillary * Remove outline from dialog * Consistent return type from mutation * Error flow Approved-by: Michael Zetterberg Approved-by: Pontus Dreij
This commit is contained in:
@@ -96,6 +96,12 @@ export const addPackageInput = z.object({
|
||||
language: z.nativeEnum(Lang).transform((val) => langToApiLang[val]),
|
||||
})
|
||||
|
||||
export const removePackageInput = z.object({
|
||||
confirmationNumber: z.string(),
|
||||
codes: z.array(z.string()),
|
||||
language: z.nativeEnum(Lang).transform((val) => langToApiLang[val]),
|
||||
})
|
||||
|
||||
export const priceChangeInput = z.object({
|
||||
confirmationNumber: z.string(),
|
||||
})
|
||||
|
||||
@@ -7,10 +7,11 @@ import { router, safeProtectedServiceProcedure } from "@/server/trpc"
|
||||
import { getMembership } from "@/utils/user"
|
||||
|
||||
import {
|
||||
cancelBookingInput,
|
||||
addPackageInput,
|
||||
cancelBookingInput,
|
||||
createBookingInput,
|
||||
priceChangeInput,
|
||||
removePackageInput,
|
||||
} from "./input"
|
||||
import { createBookingSchema } from "./output"
|
||||
|
||||
@@ -48,6 +49,14 @@ const addPackageFailCounter = meter.createCounter(
|
||||
"trpc.bookings.add-package-fail"
|
||||
)
|
||||
|
||||
const removePackageCounter = meter.createCounter("trpc.bookings.remove-package")
|
||||
const removePackageSuccessCounter = meter.createCounter(
|
||||
"trpc.bookings.remove-package-success"
|
||||
)
|
||||
const removePackageFailCounter = meter.createCounter(
|
||||
"trpc.bookings.remove-package-fail"
|
||||
)
|
||||
|
||||
async function getMembershipNumber(
|
||||
session: Session | null
|
||||
): Promise<string | undefined> {
|
||||
@@ -379,4 +388,72 @@ export const bookingMutationRouter = router({
|
||||
|
||||
return verifiedData.data
|
||||
}),
|
||||
removePackage: safeProtectedServiceProcedure
|
||||
.input(removePackageInput)
|
||||
.mutation(async function ({ ctx, input }) {
|
||||
const accessToken = ctx.session?.token.access_token ?? ctx.serviceToken
|
||||
const { confirmationNumber, codes, language } = input
|
||||
|
||||
const headers = {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
}
|
||||
|
||||
const loggingAttributes = {
|
||||
confirmationNumber,
|
||||
codes,
|
||||
language,
|
||||
}
|
||||
|
||||
removePackageCounter.add(1, loggingAttributes)
|
||||
|
||||
console.info(
|
||||
"api.booking.remove-package start",
|
||||
JSON.stringify({
|
||||
request: loggingAttributes,
|
||||
headers,
|
||||
})
|
||||
)
|
||||
|
||||
const apiResponse = await api.remove(
|
||||
api.endpoints.v1.Booking.packages(confirmationNumber),
|
||||
{
|
||||
headers,
|
||||
} as RequestInit,
|
||||
{ language, codes }
|
||||
)
|
||||
|
||||
if (!apiResponse.ok) {
|
||||
const text = await apiResponse.text()
|
||||
removePackageFailCounter.add(1, {
|
||||
confirmationNumber,
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({
|
||||
status: apiResponse.status,
|
||||
}),
|
||||
})
|
||||
console.error(
|
||||
"api.booking.remove-package error",
|
||||
JSON.stringify({
|
||||
error: {
|
||||
status: apiResponse.status,
|
||||
statusText: apiResponse.statusText,
|
||||
text,
|
||||
},
|
||||
query: loggingAttributes,
|
||||
})
|
||||
)
|
||||
return false
|
||||
}
|
||||
|
||||
removePackageSuccessCounter.add(1, loggingAttributes)
|
||||
|
||||
console.info(
|
||||
"api.booking.remove-package success",
|
||||
JSON.stringify({
|
||||
query: loggingAttributes,
|
||||
})
|
||||
)
|
||||
|
||||
return true
|
||||
}),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user