This commit is contained in:
paritosh18
2025-11-14 15:23:08 +05:30
5 changed files with 54 additions and 131 deletions

View File

@@ -194,10 +194,10 @@ functions:
getStepperInfo:
handler: src/modules/common/handlers/getStepperHandler
handler: src/modules/host/handlers/getStepper.handler
package:
patterns:
- "src/common/utils/handlers/getStepperHandler.*"
- "src/modules/host/handlers/getStepper.handler.*"
- "src/common/utils/handlers/safeHandler.*"
- "src/common/database/**"
- "src/modules/host/services/**"

View File

@@ -1,98 +0,0 @@
import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
import { safeHandler } from '../../../common/utils/handlers/safeHandler';
import { PrismaService } from '../../../common/database/prisma.service';
import ApiError from '../../../common/utils/helper/ApiError';
import { verifyHostToken } from '../../../common/middlewares/jwt/authForHost';
const prismaService = new PrismaService();
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.');
}
// Verify token and get user info
const userInfo = await verifyHostToken(token);
const userId = Number(userInfo.id);
if (!userId || isNaN(userId)) {
throw new ApiError(400, 'Invalid user ID');
}
// Fetch user with their HostHeader stepper info
const user = await prismaService.user.findUnique({
where: { id: userId },
select: {
id: true,
firstName: true,
lastName: true,
emailAddress: true,
roleXid: true,
HostHeader: {
select: {
id: true,
stepper: true,
},
},
},
});
if (!user) {
throw new ApiError(404, 'User not found');
}
if (!user.HostHeader || user.HostHeader.length === 0) {
throw new ApiError(404, 'No HostHeader record found for this user');
}
// Return stepper info along with user and host details
const hostHeader = user.HostHeader[0];
return {
statusCode: 200,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
},
body: JSON.stringify({
success: true,
message: 'Stepper information retrieved successfully',
data: {
user: {
id: user.id,
firstName: user.firstName,
lastName: user.lastName,
emailAddress: user.emailAddress,
roleXid: user.roleXid,
},
stepper: {
hostId: hostHeader.id,
currentStep: hostHeader.stepper,
stepperDescription: getStepperDescription(hostHeader.stepper),
},
},
}),
};
});
/**
* Get a human-readable description of the stepper value
*/
function getStepperDescription(stepper: number): string {
const stepDescriptions: { [key: number]: string } = {
1: 'Basic Company Information',
2: 'Company Documents & Verification',
3: 'Bank & Payment Details',
4: 'Activities Setup',
5: 'Pricing & Services',
6: 'Review & Approval',
7: 'Active & Live',
};
return stepDescriptions[stepper] || 'Unknown Step';
}

View File

@@ -0,0 +1,50 @@
import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
import { safeHandler } from '../../../common/utils/handlers/safeHandler';
import { PrismaService } from '../../../common/database/prisma.service';
import ApiError from '../../../common/utils/helper/ApiError';
import { verifyHostToken } from '../../../common/middlewares/jwt/authForHost';
import { HostService } from '../services/host.service';
const prismaService = new PrismaService();
const hostService = new HostService(prismaService);
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.');
}
// Verify token and get user info
const userInfo = await verifyHostToken(token);
const userId = Number(userInfo.id);
if (!userId || isNaN(userId)) {
throw new ApiError(400, 'Invalid user ID');
}
// Fetch user with their HostHeader stepper info
const host = await hostService.getHostById(userId);
if (!host) {
throw new ApiError(404, 'Host record not found');
}
return {
statusCode: 200,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
},
body: JSON.stringify({
success: true,
message: 'Stepper information retrieved successfully',
data: {
stepper: host.stepper,
},
}),
};
});

View File

@@ -35,7 +35,7 @@ export class HostService {
async getHostIdByUserXid(user_xid: number) {
const host = await this.prisma.hostHeader.findFirst({
where: { userXid: user_xid },
select: { id: true, companyName: true, countryXid: true },
select: { id: true, companyName: true, countryXid: true, stepper: true },
});
return host;
}

View File

@@ -50,36 +50,6 @@ export class MinglarService {
return this.prisma.user.findMany({ where: { roleXid: 3 } });
}
async getHostById(id: number) {
const host = await this.prisma.user.findUnique({
where: { id },
include: {
HostHeader: {
include: {
currencies: true,
cities: true,
states: true,
countries: true,
HostBankDetails: true,
HostDocuments: true,
HostSuggestion: true,
hostParent: true,
HostTrack: true,
Activities: true,
},
},
UserOtp: true,
Token: true,
},
});
if (!host || host.roleXid !== 4) {
throw new ApiError(404, 'Host not found');
}
return host;
}
async updateHost(id: number, data: UpdateMinglarDto) {
return this.prisma.user.update({
where: { id },
@@ -149,6 +119,7 @@ export class MinglarService {
if (!existingUser) {
throw new ApiError(404, 'User not found');
}
console.log(existingUser.roleXid);
if (existingUser.roleXid !== ROLE.MINGLAR_ADMIN || existingUser.roleXid !== ROLE.CO_ADMIN || existingUser.roleXid !== ROLE.ACCOUNT_MANAGER) {
throw new ApiError(403, 'Access denied.');