This commit is contained in:
paritosh18
2025-11-27 16:07:33 +05:30
9 changed files with 58 additions and 51 deletions

View File

@@ -3,11 +3,11 @@ import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
import AWS from 'aws-sdk';
import Busboy from 'busboy';
import crypto from 'crypto';
import { PrismaService } from '../../../common/database/prisma.service';
import { verifyHostToken } from '../../../common/middlewares/jwt/authForHost';
import { safeHandler } from '../../../common/utils/handlers/safeHandler';
import ApiError from '../../../common/utils/helper/ApiError';
import { HostService } from '../services/host.service';
import { PrismaService } from '../../../../../common/database/prisma.service';
import { verifyHostToken } from '../../../../../common/middlewares/jwt/authForHost';
import { safeHandler } from '../../../../../common/utils/handlers/safeHandler';
import ApiError from '../../../../../common/utils/helper/ApiError';
import { HostService } from '../../../services/host.service';
import { LAST_QUESTION_ID } from '@/common/utils/constants/host.constant';
const prisma = new PrismaService();

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

View File

@@ -253,7 +253,6 @@ export class HostService {
data: {
stepper: STEPPER.AGREEMENT_ACCEPTED,
agreementAccepted: true,
isApproved: true
}
})
}