From b3e051bd6339924d87531047544441b033c5004b Mon Sep 17 00:00:00 2001 From: Mayank Mishra Date: Mon, 29 Dec 2025 17:07:48 +0530 Subject: [PATCH] fixed the other documents issue --- src/modules/host/services/host.service.ts | 147 +++++++++++++--------- 1 file changed, 89 insertions(+), 58 deletions(-) diff --git a/src/modules/host/services/host.service.ts b/src/modules/host/services/host.service.ts index 4ab54ff..9d04401 100644 --- a/src/modules/host/services/host.service.ts +++ b/src/modules/host/services/host.service.ts @@ -107,7 +107,7 @@ const bucket = config.aws.bucketName; @Injectable() export class HostService { - constructor(private prisma: PrismaClient) {} + constructor(private prisma: PrismaClient) { } async createHost(data: CreateHostDto) { return this.prisma.user.create({ data }); @@ -762,7 +762,7 @@ export class HostService { if ( existingHostCompany && existingHostCompany.hostStatusInternal === - HOST_STATUS_INTERNAL.HOST_TO_UPDATE && + HOST_STATUS_INTERNAL.HOST_TO_UPDATE && !isDraft ) { hostStatusInternal = HOST_STATUS_INTERNAL.HOST_SUBMITTED; @@ -775,7 +775,7 @@ export class HostService { else if ( existingHostCompany && existingHostCompany.hostStatusInternal === - HOST_STATUS_INTERNAL.HOST_TO_UPDATE && + HOST_STATUS_INTERNAL.HOST_TO_UPDATE && isDraft ) { // keep original @@ -886,19 +886,19 @@ export class HostService { // Safely handle city connection - only connect if valid ID exists cities: parentCompanyData?.cityXid && - !isNaN(Number(parentCompanyData.cityXid)) + !isNaN(Number(parentCompanyData.cityXid)) ? { connect: { id: Number(parentCompanyData.cityXid) } } : undefined, states: parentCompanyData?.stateXid && - !isNaN(Number(parentCompanyData.stateXid)) + !isNaN(Number(parentCompanyData.stateXid)) ? { connect: { id: Number(parentCompanyData.stateXid) } } : undefined, countries: parentCompanyData?.countryXid && - !isNaN(Number(parentCompanyData.countryXid)) + !isNaN(Number(parentCompanyData.countryXid)) ? { connect: { id: Number(parentCompanyData.countryXid) } } : undefined, pinCode: parentCompanyData.pinCode || null, @@ -1048,19 +1048,19 @@ export class HostService { address2: parentCompanyData.address2 || null, cities: parentCompanyData?.cityXid && - !isNaN(Number(parentCompanyData.cityXid)) + !isNaN(Number(parentCompanyData.cityXid)) ? { connect: { id: Number(parentCompanyData.cityXid) } } : undefined, states: parentCompanyData?.stateXid && - !isNaN(Number(parentCompanyData.stateXid)) + !isNaN(Number(parentCompanyData.stateXid)) ? { connect: { id: Number(parentCompanyData.stateXid) } } : undefined, countries: parentCompanyData?.countryXid && - !isNaN(Number(parentCompanyData.countryXid)) + !isNaN(Number(parentCompanyData.countryXid)) ? { connect: { id: Number(parentCompanyData.countryXid) } } : undefined, pinCode: parentCompanyData.pinCode || null, @@ -1106,19 +1106,19 @@ export class HostService { address2: parentCompanyData.address2 || null, cities: parentCompanyData?.cityXid && - !isNaN(Number(parentCompanyData.cityXid)) + !isNaN(Number(parentCompanyData.cityXid)) ? { connect: { id: Number(parentCompanyData.cityXid) } } : undefined, states: parentCompanyData?.stateXid && - !isNaN(Number(parentCompanyData.stateXid)) + !isNaN(Number(parentCompanyData.stateXid)) ? { connect: { id: Number(parentCompanyData.stateXid) } } : undefined, countries: parentCompanyData?.countryXid && - !isNaN(Number(parentCompanyData.countryXid)) + !isNaN(Number(parentCompanyData.countryXid)) ? { connect: { id: Number(parentCompanyData.countryXid) } } : undefined, pinCode: parentCompanyData.pinCode || null, @@ -1143,41 +1143,59 @@ export class HostService { }, }); - if (parentDocuments?.length) { - for (const doc of parentDocuments) { - const existingParentDoc = await tx.hostParenetDocuments.findFirst( - { - where: { - hostParentXid: parentRecord.id, - documentTypeXid: doc.documentTypeXid, - }, - }, - ); + // if (parentDocuments?.length) { + // for (const doc of parentDocuments) { + // const existingParentDoc = await tx.hostParenetDocuments.findFirst( + // { + // where: { + // hostParentXid: parentRecord.id, + // documentTypeXid: doc.documentTypeXid, + // }, + // }, + // ); - if (existingParentDoc) { - await tx.hostParenetDocuments.update({ - where: { id: existingParentDoc.id }, - data: { - filePath: doc.filePath, - documentName: - sanitizeDocumentName(doc.documentName) || - existingParentDoc.documentName, - }, - }); - } else { - await tx.hostParenetDocuments.create({ - data: { - hostParentXid: parentRecord.id, - documentTypeXid: doc.documentTypeXid, - documentName: sanitizeDocumentName(doc.documentName), - filePath: doc.filePath, - }, - }); - } + // if (existingParentDoc) { + // await tx.hostParenetDocuments.update({ + // where: { id: existingParentDoc.id }, + // data: { + // filePath: doc.filePath, + // documentName: + // sanitizeDocumentName(doc.documentName) || + // existingParentDoc.documentName, + // }, + // }); + // } else { + // await tx.hostParenetDocuments.create({ + // data: { + // hostParentXid: parentRecord.id, + // documentTypeXid: doc.documentTypeXid, + // documentName: sanitizeDocumentName(doc.documentName), + // filePath: doc.filePath, + // }, + // }); + // } + // } + // } + if (parentDocuments?.length) { + const parentDocsData = parentDocuments + .filter((doc) => doc.filePath) + .map((doc) => ({ + hostParentXid: parentRecord.id, + documentTypeXid: doc.documentTypeXid, + documentName: sanitizeDocumentName(doc.documentName), + filePath: doc.filePath, + })); + + if (parentDocsData.length) { + await tx.hostParenetDocuments.createMany({ + data: parentDocsData, + }); } } + } - } else { + } + else { console.log('Last ke else block me aaya hai'); const previousParent = existingHostCompany.hostParent; let prevParentId = null; @@ -1727,6 +1745,21 @@ export class HostService { select: { id: true, activityTypeName: true, + interests: { + select: { + id: true, + interestName: true, + } + }, + energyLevel: { + select: { + id: true, + energyLevelName: true, + energyIcon: true, + energyColor: true, + displayOrder: true + } + } }, }, ActivitiesMedia: { @@ -1759,6 +1792,16 @@ export class HostService { mediaFileName: true, }, }, + ActivityPrices: { + select: { + id: true, + noOfSession: true, + isPackage: true, + sessionValidity: true, + sessionValidityFrequency: true, + sellPrice: true + } + } }, }, ActivityPickUpDetails: { @@ -1878,17 +1921,6 @@ export class HostService { termsAndCondition: true, }, }, - energyLevel: { - where: { - isActive: true, - }, - select: { - id: true, - energyLevelName: true, - energyIcon: true, - energyColor: true, - }, - }, ActivityEligibility: { where: { isActive: true, @@ -2399,9 +2431,9 @@ export class HostService { const rootTaxes = taxIds.length > 0 ? await this.prisma.taxes.findMany({ - where: { id: { in: taxIds }, isActive: true }, - select: { id: true, taxPer: true }, - }) + where: { id: { in: taxIds }, isActive: true }, + select: { id: true, taxPer: true }, + }) : []; if (taxIds.length !== rootTaxes.length) { @@ -2521,7 +2553,6 @@ export class HostService { checkOutLong: payload.checkOutLong ?? undefined, checkOutAddress: payload.checkOutAddress ?? undefined, - energyLevelXid: payload.energyLevelXid ?? undefined, activityDurationMins: activityDurationMins ?? undefined, currencyXid: payload.currencyXid ?? undefined,