Files
web/apps/scandic-web/server/plugins/refIdToConfirmationNumber.ts
2025-05-05 12:26:37 +00:00

47 lines
1.1 KiB
TypeScript

import { initTRPC } from "@trpc/server"
import { z } from "zod"
import { parseRefId } from "@/utils/refId"
import type { Meta } from "@/types/trpc/meta"
import type { Context } from "../context"
export function createRefIdPlugin() {
const t = initTRPC.context<Context>().meta<Meta>().create()
return {
toConfirmationNumber: t.procedure
.input(
z.object({
refId: z.string(),
})
)
.use(({ input, next }) => {
const { confirmationNumber } = parseRefId(input.refId)
return next({
ctx: {
confirmationNumber,
},
})
}),
toConfirmationNumbers: t.procedure
.input(
z.object({
refIds: z.array(z.string()),
})
)
.use(({ input, next }) => {
const confirmationNumbers = input.refIds.map((refId) => {
const { confirmationNumber } = parseRefId(refId)
return confirmationNumber
})
return next({
ctx: {
confirmationNumbers,
},
})
}),
}
}