made minor fixes
This commit is contained in:
@@ -27,11 +27,11 @@ export const parentCompanySchema = z.object({
|
||||
// Parent companies do NOT need this
|
||||
isSubsidairy: z.boolean().optional(),
|
||||
|
||||
registrationNumber: z.string().min(1, "Registration number is required"),
|
||||
panNumber: z.string().min(1, "PAN number is required"),
|
||||
registrationNumber: z.string().optional(),
|
||||
panNumber: z.string().optional(),
|
||||
gstNumber: z.string().optional(),
|
||||
|
||||
formationDate: z.string().refine((val) => !isNaN(Date.parse(val)), {
|
||||
formationDate: z.string().optional().refine((val) => !isNaN(Date.parse(val)), {
|
||||
message: "Formation date must be a valid date",
|
||||
}),
|
||||
|
||||
@@ -58,7 +58,7 @@ export const hostCompanyDetailsSchema = z.object({
|
||||
registrationNumber: z.string().optional(),
|
||||
panNumber: z.string().min(1, "PAN number is required"),
|
||||
gstNumber: z.string().optional(),
|
||||
formationDate: z.string().refine((val) => !isNaN(Date.parse(val)), {
|
||||
formationDate: z.string().optional().refine((val) => !isNaN(Date.parse(val)), {
|
||||
message: "Formation date must be a valid date",
|
||||
}),
|
||||
companyType: z.string().min(1, "Company type is required"),
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
} from '../../../../../common/utils/validation/host/hostCompanyDetails.validation';
|
||||
import { HostService } from '../../../services/host.service';
|
||||
import { sendEmailToAM, sendEmailToMinglarAdmin } from '../../../services/sendHostResubmitEmailToAM.service';
|
||||
import { HOST_STATUS_INTERNAL } from '@/common/utils/constants/host.constant';
|
||||
|
||||
const prisma = new PrismaService();
|
||||
const hostService = new HostService(prisma);
|
||||
@@ -149,17 +150,31 @@ export const handler = safeHandler(async (event: APIGatewayProxyEvent): Promise<
|
||||
// 5) Parse companyDetails
|
||||
const companyDetailsRaw = normalizeJsonField(fields, "companyDetails");
|
||||
if (!companyDetailsRaw) throw new ApiError(400, "companyDetails is required.");
|
||||
// --- FIXED HOST ID INITIALIZATION ---
|
||||
let hostId: number;
|
||||
|
||||
// Get existing host to determine host ID for folder structure
|
||||
const existingHost = await prisma.hostHeader.findFirst({
|
||||
// Check if host already exists
|
||||
let existingHost = await prisma.hostHeader.findFirst({
|
||||
where: { userXid: userInfo.id },
|
||||
});
|
||||
|
||||
let hostId: number;
|
||||
if (existingHost) {
|
||||
hostId = existingHost.id;
|
||||
if (!existingHost) {
|
||||
// Create empty hostHeader FIRST before uploading files
|
||||
const createdHost = await prisma.hostHeader.create({
|
||||
data: {
|
||||
userXid: Number(userInfo.id),
|
||||
companyName: "", // temporary placeholder
|
||||
hostStatusInternal: HOST_STATUS_INTERNAL.DRAFT, // or whatever default
|
||||
}
|
||||
});
|
||||
|
||||
hostId = createdHost.id;
|
||||
existingHost = createdHost;
|
||||
|
||||
console.log("🔥 HostHeader created first. Host ID:", hostId);
|
||||
} else {
|
||||
hostId = userInfo.id;
|
||||
hostId = existingHost.id;
|
||||
console.log("ℹ Using existing Host ID:", hostId);
|
||||
}
|
||||
|
||||
// Define uploadToS3 function (same as before)
|
||||
@@ -376,13 +391,13 @@ export const handler = safeHandler(async (event: APIGatewayProxyEvent): Promise<
|
||||
},
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: isDraft
|
||||
? 'Company details saved as draft successfully.'
|
||||
message: isDraft
|
||||
? 'Company details saved as draft successfully.'
|
||||
: 'Company (and parent if provided) details and documents uploaded successfully.',
|
||||
data: {
|
||||
id: createdOrUpdated.id,
|
||||
data: {
|
||||
id: createdOrUpdated.id,
|
||||
hostRefNumber: (createdOrUpdated as any).hostRefNumber,
|
||||
isDraft
|
||||
isDraft
|
||||
}
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -90,7 +90,7 @@ export class PrePopulateService {
|
||||
}
|
||||
|
||||
async getAllDocumentTypeWithCountryStateCity() {
|
||||
const [documentDetails, countryDetails, stateDetails, cityDetails] =
|
||||
const [documentDetails, countryDetails, stateDetails] =
|
||||
await this.prisma.$transaction([
|
||||
this.prisma.documentType.findMany({
|
||||
where: { isActive: true, isVisible: true },
|
||||
@@ -102,12 +102,9 @@ export class PrePopulateService {
|
||||
this.prisma.states.findMany({
|
||||
where: { isActive: true },
|
||||
}),
|
||||
this.prisma.cities.findMany({
|
||||
where: { isActive: true },
|
||||
}),
|
||||
]);
|
||||
|
||||
return { documentDetails, countryDetails, stateDetails, cityDetails };
|
||||
return { documentDetails, countryDetails, stateDetails };
|
||||
}
|
||||
|
||||
async getAllFrequencies() {
|
||||
|
||||
Reference in New Issue
Block a user