Update parent company validation to allow optional fields and handle null values in company details submission.

This commit is contained in:
2025-12-16 15:38:03 +05:30
parent 46daec00ce
commit 2767d29d79
2 changed files with 12 additions and 3 deletions

View File

@@ -2,8 +2,8 @@ import { z } from "zod";
export const parentCompanySchema = z.object({
companyName: z.string()
.min(1, "Parent company name is required")
.max(100, "Parent company name cannot exceed 100 characters"),
.max(100, "Parent company name cannot exceed 100 characters")
.optional(),
address1: z.string()
.max(150, "Address1 cannot exceed 150 characters")
@@ -44,7 +44,7 @@ export const parentCompanySchema = z.object({
}),
companyTypeXid: z.number()
.min(1, "Company type XID is required"),
.optional(),
websiteUrl: z.string().nullable().optional(),
instagramUrl: z.string().nullable().optional(),

View File

@@ -159,6 +159,15 @@ export const handler = safeHandler(async (event: APIGatewayProxyEvent): Promise<
}
}
if (
companyDetailsRaw.parentCompany &&
Object.values(companyDetailsRaw.parentCompany).every(
(v) => v === undefined || v === null
)
) {
companyDetailsRaw.parentCompany = null;
}
/** 6) Profile update if provided */
if (fields.userProfile) {
const userProfileRaw = normalizeJsonField(fields, 'userProfile');