diff --git a/src/modules/host/services/host.service.ts b/src/modules/host/services/host.service.ts index 0a1107d..25ccfa0 100644 --- a/src/modules/host/services/host.service.ts +++ b/src/modules/host/services/host.service.ts @@ -506,7 +506,7 @@ export class HostService { } }, countryXid: true, - country:{ + country: { select: { id: true, countryName: true @@ -1159,6 +1159,29 @@ export class HostService { throw new ApiError(400, 'Valid hostXid is required'); } + const hostHeader = await this.prisma.hostHeader.findFirst({ + where: { id: hostXid, isActive: true }, + select: { + id: true, + isCommisionBase: true, + commisionPer: true, + durationNumber: true, + durationFrequency: true, + amountPerBooking: true, + agreementStartDate: true, + payoutDurationNum: true, + payoutDurationFrequency: true, + registrationNumber: true, + companyName: true, + companyTypes: { + select: { + id: true, + companyTypeName: true + } + } + } + }); + const agreement = await this.prisma.hostAgreement.findFirst({ where: { hostXid, isActive: true }, orderBy: { createdAt: 'desc' }, @@ -1172,23 +1195,30 @@ export class HostService { }, }); - if (!agreement) { + // ❌ If both missing + if (!agreement && !hostHeader) { throw new ApiError(404, 'No active agreement found for this host'); } - const filePath = agreement.filePath; + let presignedUrl = ""; - // If full URL is saved, extract only S3 key part - const key = filePath.startsWith('http') - ? filePath.split('.com/')[1] - : filePath; + if (agreement?.filePath) { + const key = agreement.filePath.startsWith('http') + ? agreement.filePath.split('.com/')[1] + : agreement.filePath; - const bucket = config.aws.bucketName; - const presignedUrl = await getPresignedUrl(bucket, key); + const bucket = config.aws.bucketName; + presignedUrl = await getPresignedUrl(bucket, key); + } return { - ...agreement, - presignedUrl, + hostHeader: hostHeader || null, + agreement: agreement + ? { + ...agreement, + presignedUrl + } + : null }; }