add host and minglar admin APIs for registration, login, and retrieval of host details
This commit is contained in:
50
src/modules/host/handlers/getbyidhandler.ts
Normal file
50
src/modules/host/handlers/getbyidhandler.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 { HostService } from '../services/host.service';
|
||||
import ApiError from '../../../common/utils/helper/ApiError';
|
||||
import { verifyHostToken } from '@/common/middlewares/jwt/authForHost';
|
||||
|
||||
const prismaService = new PrismaService();
|
||||
const hostService = new HostService(prismaService);
|
||||
|
||||
export const handler = safeHandler(async (
|
||||
event: APIGatewayProxyEvent,
|
||||
context?: Context
|
||||
): Promise<APIGatewayProxyResult> => {
|
||||
// Get host ID from path parameters
|
||||
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.');
|
||||
}
|
||||
|
||||
const userInfo = await verifyHostToken(token);
|
||||
const id = Number(userInfo.id)
|
||||
|
||||
if (!id) {
|
||||
throw new ApiError(400, 'Host ID is required');
|
||||
}
|
||||
|
||||
if (isNaN(id)) {
|
||||
throw new ApiError(400, 'Invalid host ID format');
|
||||
}
|
||||
|
||||
const hostDetails = await hostService.getHostById(id);
|
||||
|
||||
if (!hostDetails) {
|
||||
throw new ApiError(404, 'Host not found');
|
||||
}
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: 'Host details retrieved successfully',
|
||||
data: hostDetails,
|
||||
}),
|
||||
};
|
||||
});
|
||||
@@ -44,7 +44,7 @@ export const handler = safeHandler(async (
|
||||
newUser = user;
|
||||
} else {
|
||||
// ✅ No user found → create new one
|
||||
newUser = await hostService.createHostUser(email);
|
||||
newUser = await hostService.createMinglarUser(email);
|
||||
}
|
||||
|
||||
const otpResult = await generateOtpHelper(
|
||||
|
||||
@@ -19,10 +19,71 @@ export class HostService {
|
||||
}
|
||||
|
||||
async getHostById(id: number) {
|
||||
const host = await this.prisma.user.findUnique({ where: { id } });
|
||||
const host = await this.prisma.user.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
HostHeader: {
|
||||
select: {
|
||||
id: true,
|
||||
companyName: true,
|
||||
hostRefNumber: true,
|
||||
address1: true,
|
||||
address2: true,
|
||||
cityXid: true,
|
||||
stateXid: true,
|
||||
countryXid: true,
|
||||
pinCode: true,
|
||||
logoPath: true,
|
||||
isSubsidairy: true,
|
||||
registrationNumber: true,
|
||||
panNumber: true,
|
||||
gstNumber: true,
|
||||
formationDate: true,
|
||||
companyType: true,
|
||||
websiteUrl: true,
|
||||
instagramUrl: true,
|
||||
facebookUrl: true,
|
||||
linkedinUrl: true,
|
||||
twitterUrl: true,
|
||||
currencyXid: true,
|
||||
stepper: true,
|
||||
hostStatusInternal: true,
|
||||
hostStatusDisplay: true,
|
||||
adminStatusInternal: true,
|
||||
adminStatusDisplay: true,
|
||||
amStatus: true,
|
||||
agreementAccepted: true,
|
||||
accountManagerXid: true,
|
||||
isApproved: true,
|
||||
agreementStartDate: true,
|
||||
durationNumber: true,
|
||||
durationFrequency: true,
|
||||
isCommisionBase: true,
|
||||
commisionPer: true,
|
||||
amountPerBooking: true,
|
||||
isActive: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
deletedAt: true,
|
||||
currencies: true,
|
||||
cities: true,
|
||||
states: true,
|
||||
countries: true,
|
||||
HostBankDetails: true,
|
||||
HostDocuments: true,
|
||||
HostSuggestion: true,
|
||||
hostParent: true,
|
||||
HostTrack: true,
|
||||
Activities: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!host || host.roleXid !== 4) {
|
||||
throw new ApiError(404, 'Host not found');
|
||||
}
|
||||
|
||||
return host;
|
||||
}
|
||||
|
||||
@@ -108,9 +169,9 @@ export class HostService {
|
||||
return existingUser;
|
||||
}
|
||||
|
||||
async createHostUser(email: string) {
|
||||
async createMinglarUser(email: string) {
|
||||
const newUser = await this.prisma.user.create({
|
||||
data: { emailAddress: email, roleXid: 4 },
|
||||
data: { emailAddress: email, roleXid: 1 },
|
||||
});
|
||||
return newUser;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user