Merge branch 'mayank' of http://git.wdipl.com/Mayank.Mishra/MinglarBackendNestJS into paritosh
This commit is contained in:
@@ -194,10 +194,10 @@ functions:
|
|||||||
|
|
||||||
|
|
||||||
getStepperInfo:
|
getStepperInfo:
|
||||||
handler: src/modules/common/handlers/getStepperHandler
|
handler: src/modules/host/handlers/getStepper.handler
|
||||||
package:
|
package:
|
||||||
patterns:
|
patterns:
|
||||||
- "src/common/utils/handlers/getStepperHandler.*"
|
- "src/modules/host/handlers/getStepper.handler.*"
|
||||||
- "src/common/utils/handlers/safeHandler.*"
|
- "src/common/utils/handlers/safeHandler.*"
|
||||||
- "src/common/database/**"
|
- "src/common/database/**"
|
||||||
- "src/modules/host/services/**"
|
- "src/modules/host/services/**"
|
||||||
|
|||||||
@@ -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';
|
|
||||||
}
|
|
||||||
50
src/modules/host/handlers/getStepper.ts
Normal file
50
src/modules/host/handlers/getStepper.ts
Normal 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,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ 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 },
|
select: { id: true, companyName: true, countryXid: true, stepper: true },
|
||||||
});
|
});
|
||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,36 +50,6 @@ export class MinglarService {
|
|||||||
return this.prisma.user.findMany({ where: { roleXid: 3 } });
|
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) {
|
async updateHost(id: number, data: UpdateMinglarDto) {
|
||||||
return this.prisma.user.update({
|
return this.prisma.user.update({
|
||||||
where: { id },
|
where: { id },
|
||||||
@@ -149,6 +119,7 @@ export class MinglarService {
|
|||||||
if (!existingUser) {
|
if (!existingUser) {
|
||||||
throw new ApiError(404, 'User not found');
|
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) {
|
if (existingUser.roleXid !== ROLE.MINGLAR_ADMIN || existingUser.roleXid !== ROLE.CO_ADMIN || existingUser.roleXid !== ROLE.ACCOUNT_MANAGER) {
|
||||||
throw new ApiError(403, 'Access denied.');
|
throw new ApiError(403, 'Access denied.');
|
||||||
|
|||||||
Reference in New Issue
Block a user