Gobot1234
Gobot1234
TtRPC
Created by Gobot1234 on 1/16/2025 in #❓-help
Modifying input in a middleware
Is it possible to modify input somewhere so that I can do something like this
const signIn = deskOrAdminProcedure
.input(
z.object({
name: LocationNameSchema,
ucard_number: z
.string()
.regex(/\d{9,}/),
data: CreateSignInSchema.extend({
reason_id: z.string(),
}),
}),
)
.mutation(async ({ input, ctx: { db, logger } }) => {
const { user, name, data } = await ensureUser(input, { db });
const signIn = deskOrAdminProcedure
.input(
z.object({
name: LocationNameSchema,
ucard_number: z
.string()
.regex(/\d{9,}/),
data: CreateSignInSchema.extend({
reason_id: z.string(),
}),
}),
)
.mutation(async ({ input, ctx: { db, logger } }) => {
const { user, name, data } = await ensureUser(input, { db });
as just
const signIn = deskOrAdminProcedure
.input(
z.object({
name: LocationNameSchema,
ucard_number: z
.string()
.regex(/\d{9,}/)
.transform(ldapLibraryToUcardNumber),
data: CreateSignInSchema.extend({
reason_id: z.string(),
}),
}),
)
// ... IDK what but inject ensureUser and db
.mutation(async ({ { user, name, data }, ctx: { db, logger } }) => {
const signIn = deskOrAdminProcedure
.input(
z.object({
name: LocationNameSchema,
ucard_number: z
.string()
.regex(/\d{9,}/)
.transform(ldapLibraryToUcardNumber),
data: CreateSignInSchema.extend({
reason_id: z.string(),
}),
}),
)
// ... IDK what but inject ensureUser and db
.mutation(async ({ { user, name, data }, ctx: { db, logger } }) => {
12 replies