diff --git a/serverless/functions/prepopulate.yml b/serverless/functions/prepopulate.yml index 7521ddb..d9282b5 100644 --- a/serverless/functions/prepopulate.yml +++ b/serverless/functions/prepopulate.yml @@ -91,4 +91,19 @@ getFrequenciesOfActivity: events: - httpApi: path: /prepopulate/get-all-Frequencies - method: get \ No newline at end of file + method: get + +getAddActivityPrePopulate: + handler: src/modules/prepopulate/handlers/getAddActivityPrePopulate.handler + memorySize: 384 + package: + patterns: + - 'src/modules/prepopulate/**' + - ${file(./serverless/patterns/base.yml):pattern1} + - ${file(./serverless/patterns/base.yml):pattern2} + - ${file(./serverless/patterns/base.yml):pattern3} + - ${file(./serverless/patterns/base.yml):pattern4} + events: + - httpApi: + path: /prepopulate/get-add-activity-prepopulate + method: get diff --git a/src/modules/host/handlers/Host_Admin/onboarding/updateBankDetails.ts b/src/modules/host/handlers/Host_Admin/onboarding/updateBankDetails.ts index edfabfe..0853bd7 100644 --- a/src/modules/host/handlers/Host_Admin/onboarding/updateBankDetails.ts +++ b/src/modules/host/handlers/Host_Admin/onboarding/updateBankDetails.ts @@ -43,7 +43,7 @@ export const handler = safeHandler(async ( // ✅ Validate payload using Zod const validationResult = hostBankDetailsSchema.safeParse({ ...(body as object), - hostXid: host.id, // inject hostId from token (not from user input) + hostXid: host.host.id, // inject hostId from token (not from user input) }); if (!validationResult.success) { diff --git a/src/modules/host/services/host.service.ts b/src/modules/host/services/host.service.ts index 4322178..81b6b11 100644 --- a/src/modules/host/services/host.service.ts +++ b/src/modules/host/services/host.service.ts @@ -308,11 +308,14 @@ export class HostService { select: { id: true, roleXid: true, + firstName: true, + lastName: true, + emailAddress: true, + mobileNumber: true, userPassword: true, userStatus: true } }); - console.log(existingUser, "ajsbfkjd") if (!existingUser) { throw new ApiError(404, 'User not found'); @@ -991,7 +994,7 @@ export class HostService { ? { connect: { id: Number(parentCompanyData.countryXid) } } : undefined, pinCode: parentCompanyData.pinCode || null, - logoPath: parentCompanyData.logoPath || existingParentCompany.logoPath, + logoPath: parentCompanyData?.logoPath || existingParentCompany?.logoPath || null, registrationNumber: parentCompanyData.registrationNumber || null, panNumber: parentCompanyData.panNumber || null, gstNumber: parentCompanyData.gstNumber || null, @@ -1040,7 +1043,7 @@ export class HostService { ? { connect: { id: Number(parentCompanyData.countryXid) } } : undefined, pinCode: parentCompanyData.pinCode || null, - logoPath: parentCompanyData.logoPath || existingParentCompany.logoPath, + logoPath: parentCompanyData?.logoPath || existingParentCompany?.logoPath || null, registrationNumber: parentCompanyData.registrationNumber || null, panNumber: parentCompanyData.panNumber || null, gstNumber: parentCompanyData.gstNumber || null, diff --git a/src/modules/minglaradmin/handlers/hosthub/onboarding/showSuggestionToAM.ts b/src/modules/minglaradmin/handlers/hosthub/onboarding/showSuggestionToAM.ts index 7202228..dd83b3d 100644 --- a/src/modules/minglaradmin/handlers/hosthub/onboarding/showSuggestionToAM.ts +++ b/src/modules/minglaradmin/handlers/hosthub/onboarding/showSuggestionToAM.ts @@ -26,6 +26,13 @@ export const handler = safeHandler(async ( const hostXid = Number(event.pathParameters?.hostXid) + if (!hostXid) { + throw new ApiError( + 400, + 'Host ID is required in path parameters.', + ); + } + // Get suggestions using service const suggestions = await minglarService.getSuggestionsForAM(hostXid); diff --git a/src/modules/prepopulate/handlers/getAddActivityPrePopulate.ts b/src/modules/prepopulate/handlers/getAddActivityPrePopulate.ts new file mode 100644 index 0000000..c23def5 --- /dev/null +++ b/src/modules/prepopulate/handlers/getAddActivityPrePopulate.ts @@ -0,0 +1,38 @@ +import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda'; +import { prismaClient } from '../../../common/database/prisma.lambda.service'; +import { verifyMinglarAdminHostToken } from '../../../common/middlewares/jwt/authForMinglarAdminHost'; +import { safeHandler } from '../../../common/utils/handlers/safeHandler'; +import ApiError from '../../../common/utils/helper/ApiError'; +import { PrePopulateService } from '../services/prepopulate.service'; + +const prePopulateService = new PrePopulateService(prismaClient); + +export const handler = safeHandler(async ( + event: APIGatewayProxyEvent, + context?: Context +): Promise => { + // Extract token from headers + const token = event.headers['x-auth-token'] || event.headers['X-Auth-Token'] + if (!token) { + throw new ApiError(400, 'This is a protected route. Please provide a valid token.'); + } + + // Authenticate user using the shared authForHost function + await verifyMinglarAdminHostToken(token); + + const result = await prePopulateService.getAllPrePopulateDataForAddActivity(); + + return { + statusCode: 200, + headers: { + 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', + }, + body: JSON.stringify({ + success: true, + message: 'Data retrieved successfully', + data: result, + }), + }; +}); + diff --git a/src/modules/prepopulate/services/prepopulate.service.ts b/src/modules/prepopulate/services/prepopulate.service.ts index b62e2ae..563fb85 100644 --- a/src/modules/prepopulate/services/prepopulate.service.ts +++ b/src/modules/prepopulate/services/prepopulate.service.ts @@ -141,4 +141,62 @@ export class PrePopulateService { }, }); } + + async getAllPrePopulateDataForAddActivity() { + const [ + foodType, + cuisineDetails, + vehicleType, + navigationMode, + taxDetails, + energyLevel, + aminitiesDetails, + allowedEntryType, + ageRestrictionDetails + ] = + await this.prisma.$transaction([ + this.prisma.foodTypes.findMany({ + where: { isActive: true }, + orderBy: { foodTypeName: 'asc' }, + }), + this.prisma.foodCuisines.findMany({ + where: { isActive: true }, + }), + this.prisma.transportModes.findMany({ + where: { isActive: true }, + }), + this.prisma.navigationModes.findMany({ + where: { isActive: true }, + }), + this.prisma.taxes.findMany({ + where: { isActive: true }, + }), + this.prisma.energyLevels.findMany({ + where: { isActive: true }, + }), + this.prisma.amenities.findMany({ + where: { isActive: true }, + }), + this.prisma.allowedEntryTypes.findMany({ + where: { isActive: true }, + orderBy: { allowedEntryTypeName: 'asc' } + }), + this.prisma.ageRestrictions.findMany({ + where: { isActive: true }, + orderBy: { ageRestrictionName: 'asc' } + }), + ]); + + return { + foodType, + cuisineDetails, + vehicleType, + navigationMode, + taxDetails, + energyLevel, + aminitiesDetails, + allowedEntryType, + ageRestrictionDetails + }; + } }