Add getAddActivityPrePopulate handler and implement prepopulate data retrieval
- Introduced a new handler for adding activity prepopulation. - Enhanced the PrePopulateService to fetch all necessary prepopulate data for the new activity. - Updated the updateBankDetails handler to correctly inject host ID. - Improved user data retrieval in HostService to include additional fields. - Added validation for host ID in showSuggestionToAM handler.
This commit is contained in:
@@ -91,4 +91,19 @@ getFrequenciesOfActivity:
|
||||
events:
|
||||
- httpApi:
|
||||
path: /prepopulate/get-all-Frequencies
|
||||
method: get
|
||||
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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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<APIGatewayProxyResult> => {
|
||||
// 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,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user