fix(SW-898): remove redundant schema and add transform in signupInput
This commit is contained in:
@@ -40,6 +40,18 @@ export const saveCreditCardInput = z.object({
|
||||
merchantId: z.string().optional(),
|
||||
})
|
||||
|
||||
export const signupInput = signUpSchema.extend({
|
||||
language: z.nativeEnum(Lang),
|
||||
})
|
||||
export const signupInput = signUpSchema
|
||||
.extend({
|
||||
language: z.nativeEnum(Lang),
|
||||
})
|
||||
.omit({ termsAccepted: true })
|
||||
.transform((data) => ({
|
||||
...data,
|
||||
phoneNumber: data.phoneNumber.replace(/\s+/g, ""),
|
||||
address: {
|
||||
...data.address,
|
||||
city: "",
|
||||
country: "",
|
||||
streetAddress: "",
|
||||
},
|
||||
}))
|
||||
|
||||
@@ -3,10 +3,9 @@ import { metrics } from "@opentelemetry/api"
|
||||
import { signupVerify } from "@/constants/routes/signup"
|
||||
import { env } from "@/env/server"
|
||||
import * as api from "@/lib/api"
|
||||
import { badRequestError, serverErrorByStatus } from "@/server/errors/trpc"
|
||||
import { serverErrorByStatus } from "@/server/errors/trpc"
|
||||
import {
|
||||
initiateSaveCardSchema,
|
||||
signupPayloadSchema,
|
||||
subscriberIdSchema,
|
||||
} from "@/server/routers/user/output"
|
||||
import { protectedProcedure, router, serviceProcedure } from "@/server/trpc"
|
||||
@@ -219,31 +218,10 @@ export const userMutationRouter = router({
|
||||
ctx,
|
||||
input,
|
||||
}) {
|
||||
const payload = {
|
||||
...input,
|
||||
language: input.language,
|
||||
phoneNumber: input.phoneNumber.replace(/\s+/g, ""),
|
||||
}
|
||||
signupCounter.add(1)
|
||||
|
||||
const parsedPayload = signupPayloadSchema.safeParse(payload)
|
||||
if (!parsedPayload.success) {
|
||||
signupFailCounter.add(1, {
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(parsedPayload.error),
|
||||
})
|
||||
console.error(
|
||||
"api.user.signup validation error",
|
||||
JSON.stringify({
|
||||
query: input,
|
||||
error: parsedPayload.error,
|
||||
})
|
||||
)
|
||||
throw badRequestError(parsedPayload.error)
|
||||
}
|
||||
|
||||
const apiResponse = await api.post(api.endpoints.v1.Profile.profile, {
|
||||
body: parsedPayload.data,
|
||||
body: input,
|
||||
headers: {
|
||||
Authorization: `Bearer ${ctx.serviceToken}`,
|
||||
},
|
||||
|
||||
@@ -246,20 +246,3 @@ export const initiateSaveCardSchema = z.object({
|
||||
export const subscriberIdSchema = z.object({
|
||||
subscriberId: z.string(),
|
||||
})
|
||||
|
||||
export const signupPayloadSchema = z.object({
|
||||
language: z.string(),
|
||||
firstName: z.string(),
|
||||
lastName: z.string(),
|
||||
email: z.string(),
|
||||
phoneNumber: phoneValidator("Phone is required"),
|
||||
dateOfBirth: z.string(),
|
||||
address: z.object({
|
||||
city: z.string().default(""),
|
||||
country: z.string().default(""),
|
||||
countryCode: z.string().default(""),
|
||||
zipCode: z.string().default(""),
|
||||
streetAddress: z.string().default(""),
|
||||
}),
|
||||
password: passwordValidator("Password is required"),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user