made minor fixes

This commit is contained in:
2025-11-27 15:03:34 +05:30
parent f421a1e88a
commit 62637ecc9a
5 changed files with 52 additions and 40 deletions

View File

@@ -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
}
}),
};