This commit is contained in:
paritosh18
2025-11-14 15:04:44 +05:30
8 changed files with 171 additions and 100 deletions

View File

@@ -33,7 +33,8 @@ model User {
EnergyLevels EnergyLevels? @relation(fields: [energyLevelsId], references: [id])
isBiometric Boolean? @default(false) @map("is_biometric")
energyLevelsId Int?
HostHeader HostHeader[]
hostHeaders HostHeader[] @relation("HostUser")
managedHostHeaders HostHeader[] @relation("AccountManager")
Token Token[]
ReviewedSuggestions HostSuggestion[] @relation("UserReviewedSuggestions")
hostTrack HostTrack[]
@@ -47,6 +48,13 @@ model User {
ActivitySOSDetails ActivitySOSDetails[]
ActivityFeedbacks ActivityFeedbacks[]
ItineraryDetails ItineraryDetails[]
inviteDetails InviteDetails[] @relation("InvitedUser")
invitedInviteDetails InviteDetails[] @relation("InviterUser")
userRevenues UserRevenue[]
userInterests UserInterests[]
connectDetails ConnectDetails[]
friends Friends[]
friendOf Friends[] @relation("FriendUser")
@@map("users")
@@schema("usr")
@@ -71,6 +79,86 @@ model UserOtp {
@@schema("usr")
}
model InviteDetails {
id Int @id @default(autoincrement())
userXid Int @map("user_xid")
user User @relation("InvitedUser", fields: [userXid], references: [id], onDelete: Cascade)
is_invited Boolean @default(false) @map("is_invited")
invited_by Int @map("invited_by")
invitedBy User @relation("InviterUser", fields: [invited_by], references: [id], onDelete: Restrict)
invited_on DateTime @default(now()) @map("invited_on")
is_accepted Boolean @default(false) @map("is_accepted")
accepted_on DateTime? @map("accepted_on")
invitation_status String @default("pending") @map("invitation_status")
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")
@@map("invite_details")
@@schema("usr")
}
model UserRevenue {
id Int @id @default(autoincrement())
userXid Int @map("user_xid")
user User @relation(fields: [userXid], references: [id], onDelete: Cascade)
is_fixed_salary Boolean @default(false) @map("is_fixed_salary")
per_value Float @map("per_value")
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")
@@map("user_revenue")
@@schema("usr")
}
model ConnectDetails {
id Int @id @default(autoincrement())
userXid Int @map("user_xid")
user User @relation(fields: [userXid], references: [id], onDelete: Cascade)
connectXid Int @map("connect_xid")
connect Connections @relation(fields: [connectXid], references: [id], onDelete: Cascade)
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")
@@map("connect_details")
@@schema("usr")
}
model Friends {
id Int @id @default(autoincrement())
userXid Int @map("user_xid")
user User @relation(fields: [userXid], references: [id], onDelete: Cascade)
friendXid Int @map("friend_xid")
friend User @relation("FriendUser", fields: [friendXid], references: [id], onDelete: Cascade)
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")
@@map("friends")
@@schema("usr")
}
model UserInterests {
id Int @id @default(autoincrement())
userXid Int @map("user_xid")
user User @relation(fields: [userXid], references: [id], onDelete: Cascade)
interestXid Int @map("interest_xid")
interest Interests @relation(fields: [interestXid], references: [id], onDelete: Cascade)
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")
@@map("user_interests")
@@schema("usr")
}
model Countries {
id Int @id @default(autoincrement())
countryName String @unique @map("country_name")
@@ -210,6 +298,7 @@ model Interests {
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")
ActivityTypes ActivityTypes[]
userInterests UserInterests[]
@@map("interests")
@@schema("mst")
@@ -233,7 +322,6 @@ model ActivityTypes {
model DocumentType {
id Int @id @default(autoincrement())
documentTypeName String @unique @map("document_type_name")
displayOrder Int @map("display_order")
isVisible Boolean @default(true) @map("is_visible")
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
@@ -246,6 +334,30 @@ model DocumentType {
@@schema("mst")
}
model FoodCuisines {
id Int @id @default(autoincrement())
cuisineName String @unique @map("cuisine_name")
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")
@@map("food_cuisines")
@@schema("mst")
}
model CompanyTypes {
id Int @id @default(autoincrement())
companyTypeName String @unique @map("company_type_name")
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")
@@map("company_types")
@@schema("mst")
}
model Amenities {
id Int @id @default(autoincrement())
amenitiesName String @unique @map("amenities_name")
@@ -414,6 +526,7 @@ model Connections {
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")
User User[]
connectDetails ConnectDetails[]
@@map("connections")
@@schema("mst")
@@ -459,6 +572,8 @@ model Token {
model HostHeader {
id Int @id @default(autoincrement())
userXid Int @map("user_xid")
user User @relation("HostUser", fields: [userXid], references: [id], onDelete: Cascade)
companyName String @map("company_name")
hostRefNumber String @map("host_ref_number")
address1 String @map("address_1")
@@ -492,7 +607,7 @@ model HostHeader {
amStatus String @default("pending") @map("am_status")
agreementAccepted Boolean @default(false) @map("agreement_accepted")
accountManagerXid Int? @map("account_manager_xid")
accountManager User? @relation(fields: [accountManagerXid], references: [id], onDelete: Restrict)
accountManager User? @relation("AccountManager", fields: [accountManagerXid], references: [id], onDelete: Restrict)
isApproved Boolean @default(false) @map("is_approved")
agreementStartDate DateTime? @map("agreement_start_date")
durationNumber Int? @map("duration_number")
@@ -524,7 +639,7 @@ model HostBankDetails {
bankBranchXid Int @map("bank_branch_xid")
bankBranches BankBranches @relation(fields: [bankBranchXid], references: [id], onDelete: Restrict)
accountHolderName String @map("account_holder_name")
accountNumber Int @unique @map("account_number")
accountNumber String @unique @map("account_number")
ifscCode String @map("ifsc_code")
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at")

View File

@@ -189,7 +189,7 @@ functions:
events:
- httpApi:
path: /host
path: /host/getById
method: get

View File

@@ -3,9 +3,8 @@ import { z } from "zod";
export const hostBankDetailsSchema = z.object({
accountNumber: z
.number()
.int({ message: "Account number must be an integer" })
.positive({ message: "Account number must be a positive number" }),
.string()
.nonempty("Account number is required"),
accountHolderName: z
.string()

View File

@@ -16,7 +16,7 @@ async function bootstrap() {
app.enableCors({
origin: [
'http://localhost:3000', // Local Swagger UI
'http://localhost:3006', // Local Frontend
'http://localhost:5173', // Local Frontend
'https://editor.swagger.io', // Swagger Editor
'https://klc-admin.wdiprojects.com',
'https://admin-uat.klc.betadelivery.com',

View File

@@ -77,12 +77,12 @@ export class GetHostLoginResponseDTO {
export class AddPaymentDetailsDTO {
bankXid: number;
bankBranchXid: number;
accountNumber: number;
accountNumber: string;
accountHolderName: string;
ifscCode: string;
hostXid: number;
constructor(bankXid: number, bankBranchXid: number, accountNumber: number, accountHolderName: string, ifscCode: string, hostXid: number) {
constructor(bankXid: number, bankBranchXid: number, accountNumber: string, accountHolderName: string, ifscCode: string, hostXid: number) {
this.bankXid = bankXid;
this.bankBranchXid = bankBranchXid;
this.accountNumber = accountNumber;

View File

@@ -213,7 +213,7 @@ export const handler = safeHandler(async (event: APIGatewayProxyEvent): Promise<
}
// 14) Persist using hostService (we updated service to accept optional parent info)
const created = await hostService.addCompanyDetails(parsedCompany, uploadedHostDocs, parsedParentCompany, uploadedParentDocs);
const created = await hostService.addCompanyDetails(userInfo.id, parsedCompany, uploadedHostDocs, parsedParentCompany, uploadedParentDocs);
if (!created) throw new ApiError(400, 'Failed to add company details.');
// 15) Success

View File

@@ -27,6 +27,11 @@ export const handler = safeHandler(async (
throw new ApiError(400, 'Host id must be a number');
}
const host = await hostService.getHostIdByUserXid(hostId);
if (!host) {
throw new ApiError(404, 'Host not found');
}
// Parse request body
let body: { bankXid?: number; bankBranchXid?: number; accountNumber?: string; accountHolderName?: string; ifscCode?: string };
@@ -39,7 +44,7 @@ export const handler = safeHandler(async (
// ✅ Validate payload using Zod
const validationResult = hostBankDetailsSchema.safeParse({
...(body as object),
hostXid: hostId, // inject hostId from token (not from user input)
hostXid: host.id, // inject hostId from token (not from user input)
});
if (!validationResult.success) {
@@ -49,7 +54,7 @@ export const handler = safeHandler(async (
const validatedData = validationResult.data;
await hostService.addPaymentDetails(hostId, validatedData);
await hostService.addPaymentDetails(validatedData);
return {
statusCode: 200,

View File

@@ -32,70 +32,28 @@ export class HostService {
return this.prisma.user.findMany({ where: { roleXid: 3 } });
}
async getHostIdByUserXid(user_xid: number) {
const host = await this.prisma.hostHeader.findFirst({
where: { userXid: user_xid },
select: { id: true, companyName: true, countryXid: true },
});
return host;
}
async getHostById(id: number) {
const host = await this.prisma.user.findUnique({
where: { id },
const host = await this.prisma.hostHeader.findFirst({
where: { userXid: 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,
hostParent: 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');
if (!host) {
throw new ApiError(404, 'Host record not found.');
}
return host;
@@ -219,15 +177,7 @@ export class HostService {
return true;
}
async addPaymentDetails(id: number, data: AddPaymentDetailsDTO): Promise<AddPaymentDetailsDTO> {
const existingUser = await this.prisma.user.findUnique({
where: { id },
});
if (!existingUser) {
throw new ApiError(404, 'User not found');
}
async addPaymentDetails(data: AddPaymentDetailsDTO): Promise<AddPaymentDetailsDTO> {
const addedPaymentDetails = await this.prisma.hostBankDetails.create({
data,
});
@@ -240,6 +190,7 @@ export class HostService {
}
async addCompanyDetails(
user_xid: number,
companyData: HostCompanyDetailsInput,
documents: HostDocumentInput[], // host documents with S3 URLs
parentCompanyData?: any | null, // optional parent company object
@@ -257,6 +208,7 @@ export class HostService {
// 2) Create host header record
const createdHost = await tx.hostHeader.create({
data: {
userXid: user_xid,
companyName: companyData.companyName,
hostRefNumber: companyData.hostRefNumber,
address1: companyData.address1,