Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a906dc5635 | |||
| 8ec8cf4854 | |||
| fab7642302 |
@@ -409,7 +409,7 @@ getAllPQPDetailsForAM:
|
|||||||
|
|
||||||
|
|
||||||
getSuggestionsForAM:
|
getSuggestionsForAM:
|
||||||
handler: src/modules/minglaradmin/handlers/hosthub/pqp/getAllPQPDetailsForAM.handler
|
handler: src/modules/minglaradmin/handlers/hosthub/onboarding/showSuggestionToAM.handler
|
||||||
memorySize: 384
|
memorySize: 384
|
||||||
package:
|
package:
|
||||||
patterns:
|
patterns:
|
||||||
|
|||||||
@@ -91,4 +91,19 @@ getFrequenciesOfActivity:
|
|||||||
events:
|
events:
|
||||||
- httpApi:
|
- httpApi:
|
||||||
path: /prepopulate/get-all-Frequencies
|
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
|
||||||
|
|||||||
@@ -426,6 +426,21 @@ export const handler = safeHandler(async (event: APIGatewayProxyEvent): Promise<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!parsedCompany.isSubsidairy) {
|
||||||
|
const parentDocuments = await hostService.getParentDocumentsByHostId(userInfo.id);
|
||||||
|
if (parentDocuments.length > 0) {
|
||||||
|
for (const doc of parentDocuments) {
|
||||||
|
try {
|
||||||
|
const s3Key = getS3KeyFromUrl(doc.filePath);
|
||||||
|
await deleteFromS3(s3Key);
|
||||||
|
} catch (e) {
|
||||||
|
console.error("S3 delete failed:", doc.filePath, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await hostService.deleteExistingParentRecords(userInfo.id)
|
||||||
|
}
|
||||||
|
|
||||||
/** 12) SAVE / UPDATE HOST ENTRY */
|
/** 12) SAVE / UPDATE HOST ENTRY */
|
||||||
const createdOrUpdated = await hostService.addOrUpdateCompanyDetails(
|
const createdOrUpdated = await hostService.addOrUpdateCompanyDetails(
|
||||||
userInfo.id,
|
userInfo.id,
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export const handler = safeHandler(async (
|
|||||||
// ✅ Validate payload using Zod
|
// ✅ Validate payload using Zod
|
||||||
const validationResult = hostBankDetailsSchema.safeParse({
|
const validationResult = hostBankDetailsSchema.safeParse({
|
||||||
...(body as object),
|
...(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) {
|
if (!validationResult.success) {
|
||||||
|
|||||||
@@ -27,10 +27,6 @@ export const handler = safeHandler(async (
|
|||||||
// Fetch user with their HostHeader stepper info
|
// Fetch user with their HostHeader stepper info
|
||||||
const host = await hostService.getHostIdByUserXid(userId);
|
const host = await hostService.getHostIdByUserXid(userId);
|
||||||
|
|
||||||
if (!host) {
|
|
||||||
throw new ApiError(404, 'Host record not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
headers: {
|
headers: {
|
||||||
@@ -41,7 +37,7 @@ export const handler = safeHandler(async (
|
|||||||
success: true,
|
success: true,
|
||||||
message: 'Stepper information retrieved successfully',
|
message: 'Stepper information retrieved successfully',
|
||||||
data: {
|
data: {
|
||||||
stepper: host.stepper,
|
stepper: host?.host?.stepper || null,
|
||||||
emailAddress: host.user?.emailAddress || null,
|
emailAddress: host.user?.emailAddress || null,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -85,9 +85,14 @@ export class HostService {
|
|||||||
async getHostIdByUserXid(user_xid: number) {
|
async getHostIdByUserXid(user_xid: number) {
|
||||||
const host = await this.prisma.hostHeader.findFirst({
|
const host = await this.prisma.hostHeader.findFirst({
|
||||||
where: { userXid: user_xid },
|
where: { userXid: user_xid },
|
||||||
select: { id: true, companyName: true, countryXid: true, stepper: true, user: { select: { id: true, emailAddress: true }} },
|
select: { id: true, stepper: true },
|
||||||
});
|
});
|
||||||
return host;
|
|
||||||
|
const user = await this.prisma.user.findUnique({
|
||||||
|
where: { id: user_xid },
|
||||||
|
select: { id: true, emailAddress: true },
|
||||||
|
})
|
||||||
|
return { host, user };
|
||||||
}
|
}
|
||||||
|
|
||||||
async getHostById(id: number) {
|
async getHostById(id: number) {
|
||||||
@@ -303,11 +308,14 @@ export class HostService {
|
|||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
roleXid: true,
|
roleXid: true,
|
||||||
|
firstName: true,
|
||||||
|
lastName: true,
|
||||||
|
emailAddress: true,
|
||||||
|
mobileNumber: true,
|
||||||
userPassword: true,
|
userPassword: true,
|
||||||
userStatus: true
|
userStatus: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log(existingUser, "ajsbfkjd")
|
|
||||||
|
|
||||||
if (!existingUser) {
|
if (!existingUser) {
|
||||||
throw new ApiError(404, 'User not found');
|
throw new ApiError(404, 'User not found');
|
||||||
@@ -624,6 +632,52 @@ export class HostService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getParentDocumentsByHostId(userId: number) {
|
||||||
|
const host = await this.prisma.hostHeader.findFirst({
|
||||||
|
where: { userXid: userId },
|
||||||
|
select: { id: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!host) return [];
|
||||||
|
|
||||||
|
const parents = await this.prisma.hostParent.findMany({
|
||||||
|
where: { hostXid: host.id },
|
||||||
|
include: { HostParenetDocuments: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
return parents.flatMap(p => p.HostParenetDocuments);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async deleteExistingParentRecords(userId: number) {
|
||||||
|
const host = await this.prisma.hostHeader.findFirst({
|
||||||
|
where: { userXid: userId },
|
||||||
|
select: { id: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!host) return;
|
||||||
|
|
||||||
|
const parents = await this.prisma.hostParent.findMany({
|
||||||
|
where: { hostXid: host.id },
|
||||||
|
select: { id: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!parents.length) return;
|
||||||
|
|
||||||
|
const parentIds = parents.map(p => p.id);
|
||||||
|
|
||||||
|
// 1️⃣ Delete documents first
|
||||||
|
await this.prisma.hostParenetDocuments.deleteMany({
|
||||||
|
where: { hostParentXid: { in: parentIds } },
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2️⃣ Then delete parent records
|
||||||
|
await this.prisma.hostParent.deleteMany({
|
||||||
|
where: { id: { in: parentIds } },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async addOrUpdateCompanyDetails(
|
async addOrUpdateCompanyDetails(
|
||||||
user_xid: number,
|
user_xid: number,
|
||||||
companyData: HostCompanyDetailsInput,
|
companyData: HostCompanyDetailsInput,
|
||||||
@@ -775,22 +829,20 @@ export class HostService {
|
|||||||
const createdParent = await tx.hostParent.create({
|
const createdParent = await tx.hostParent.create({
|
||||||
data: {
|
data: {
|
||||||
host: { connect: { id: createdHost.id } },
|
host: { connect: { id: createdHost.id } },
|
||||||
companyName: parentCompanyData.companyName,
|
companyName: parentCompanyData.companyName || null,
|
||||||
address1: parentCompanyData.address1 || null,
|
address1: parentCompanyData.address1 || null,
|
||||||
address2: parentCompanyData.address2 || null,
|
address2: parentCompanyData.address2 || null,
|
||||||
// Safely handle city connection - only connect if valid ID exists
|
// Safely handle city connection - only connect if valid ID exists
|
||||||
cities: companyData.cityXid && !isNaN(Number(companyData.cityXid))
|
cities: parentCompanyData?.cityXid && !isNaN(Number(parentCompanyData.cityXid))
|
||||||
? { connect: { id: Number(companyData.cityXid) } }
|
? { connect: { id: Number(parentCompanyData.cityXid) } }
|
||||||
: undefined, // Don't change if not provided
|
|
||||||
|
|
||||||
// Same for state
|
|
||||||
states: companyData.stateXid && !isNaN(Number(companyData.stateXid))
|
|
||||||
? { connect: { id: Number(companyData.stateXid) } }
|
|
||||||
: undefined,
|
: undefined,
|
||||||
|
|
||||||
// Same for country
|
states: parentCompanyData?.stateXid && !isNaN(Number(parentCompanyData.stateXid))
|
||||||
countries: companyData.countryXid && !isNaN(Number(companyData.countryXid))
|
? { connect: { id: Number(parentCompanyData.stateXid) } }
|
||||||
? { connect: { id: Number(companyData.countryXid) } }
|
: undefined,
|
||||||
|
|
||||||
|
countries: parentCompanyData?.countryXid && !isNaN(Number(parentCompanyData.countryXid))
|
||||||
|
? { connect: { id: Number(parentCompanyData.countryXid) } }
|
||||||
: undefined,
|
: undefined,
|
||||||
pinCode: parentCompanyData.pinCode || null,
|
pinCode: parentCompanyData.pinCode || null,
|
||||||
logoPath: parentCompanyData.logoPath || null,
|
logoPath: parentCompanyData.logoPath || null,
|
||||||
@@ -927,20 +979,22 @@ export class HostService {
|
|||||||
const createdParent = await tx.hostParent.create({
|
const createdParent = await tx.hostParent.create({
|
||||||
data: {
|
data: {
|
||||||
host: { connect: { id: updatedHost.id } },
|
host: { connect: { id: updatedHost.id } },
|
||||||
companyName: parentCompanyData.companyName,
|
companyName: parentCompanyData.companyName || null,
|
||||||
address1: parentCompanyData.address1 || null,
|
address1: parentCompanyData.address1 || null,
|
||||||
address2: parentCompanyData.address2 || null,
|
address2: parentCompanyData.address2 || null,
|
||||||
cities: parentCompanyData.cityXid
|
cities: parentCompanyData?.cityXid && !isNaN(Number(parentCompanyData.cityXid))
|
||||||
? { connect: { id: parentCompanyData.cityXid } }
|
? { connect: { id: Number(parentCompanyData.cityXid) } }
|
||||||
: undefined,
|
: undefined,
|
||||||
states: parentCompanyData.stateXid
|
|
||||||
? { connect: { id: parentCompanyData.stateXid } }
|
states: parentCompanyData?.stateXid && !isNaN(Number(parentCompanyData.stateXid))
|
||||||
|
? { connect: { id: Number(parentCompanyData.stateXid) } }
|
||||||
: undefined,
|
: undefined,
|
||||||
countries: parentCompanyData.countryXid
|
|
||||||
? { connect: { id: parentCompanyData.countryXid } }
|
countries: parentCompanyData?.countryXid && !isNaN(Number(parentCompanyData.countryXid))
|
||||||
|
? { connect: { id: Number(parentCompanyData.countryXid) } }
|
||||||
: undefined,
|
: undefined,
|
||||||
pinCode: parentCompanyData.pinCode || null,
|
pinCode: parentCompanyData.pinCode || null,
|
||||||
logoPath: parentCompanyData.logoPath || existingParentCompany.logoPath,
|
logoPath: parentCompanyData?.logoPath || existingParentCompany?.logoPath || null,
|
||||||
registrationNumber: parentCompanyData.registrationNumber || null,
|
registrationNumber: parentCompanyData.registrationNumber || null,
|
||||||
panNumber: parentCompanyData.panNumber || null,
|
panNumber: parentCompanyData.panNumber || null,
|
||||||
gstNumber: parentCompanyData.gstNumber || null,
|
gstNumber: parentCompanyData.gstNumber || null,
|
||||||
@@ -974,20 +1028,22 @@ export class HostService {
|
|||||||
await tx.hostParent.update({
|
await tx.hostParent.update({
|
||||||
where: { id: parentRecord.id },
|
where: { id: parentRecord.id },
|
||||||
data: {
|
data: {
|
||||||
companyName: parentCompanyData.companyName,
|
companyName: parentCompanyData.companyName || null,
|
||||||
address1: parentCompanyData.address1 || null,
|
address1: parentCompanyData.address1 || null,
|
||||||
address2: parentCompanyData.address2 || null,
|
address2: parentCompanyData.address2 || null,
|
||||||
cities: parentCompanyData.cityXid
|
cities: parentCompanyData?.cityXid && !isNaN(Number(parentCompanyData.cityXid))
|
||||||
? { connect: { id: parentCompanyData.cityXid } }
|
? { connect: { id: Number(parentCompanyData.cityXid) } }
|
||||||
: undefined,
|
: undefined,
|
||||||
states: parentCompanyData.stateXid
|
|
||||||
? { connect: { id: parentCompanyData.stateXid } }
|
states: parentCompanyData?.stateXid && !isNaN(Number(parentCompanyData.stateXid))
|
||||||
|
? { connect: { id: Number(parentCompanyData.stateXid) } }
|
||||||
: undefined,
|
: undefined,
|
||||||
countries: parentCompanyData.countryXid
|
|
||||||
? { connect: { id: parentCompanyData.countryXid } }
|
countries: parentCompanyData?.countryXid && !isNaN(Number(parentCompanyData.countryXid))
|
||||||
|
? { connect: { id: Number(parentCompanyData.countryXid) } }
|
||||||
: undefined,
|
: undefined,
|
||||||
pinCode: parentCompanyData.pinCode || null,
|
pinCode: parentCompanyData.pinCode || null,
|
||||||
logoPath: parentCompanyData.logoPath || existingParentCompany.logoPath,
|
logoPath: parentCompanyData?.logoPath || existingParentCompany?.logoPath || null,
|
||||||
registrationNumber: parentCompanyData.registrationNumber || null,
|
registrationNumber: parentCompanyData.registrationNumber || null,
|
||||||
panNumber: parentCompanyData.panNumber || null,
|
panNumber: parentCompanyData.panNumber || null,
|
||||||
gstNumber: parentCompanyData.gstNumber || null,
|
gstNumber: parentCompanyData.gstNumber || null,
|
||||||
|
|||||||
@@ -26,6 +26,13 @@ export const handler = safeHandler(async (
|
|||||||
|
|
||||||
const hostXid = Number(event.pathParameters?.hostXid)
|
const hostXid = Number(event.pathParameters?.hostXid)
|
||||||
|
|
||||||
|
if (!hostXid) {
|
||||||
|
throw new ApiError(
|
||||||
|
400,
|
||||||
|
'Host ID is required in path parameters.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Get suggestions using service
|
// Get suggestions using service
|
||||||
const suggestions = await minglarService.getSuggestionsForAM(hostXid);
|
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