From ee38391d1eea3232184a0b7087625dd5b1f013fe Mon Sep 17 00:00:00 2001 From: Mayank Mishra Date: Tue, 18 Nov 2025 17:44:51 +0530 Subject: [PATCH] add payment details modified and making seeder of pqq --- prisma/schema.prisma | 94 ++-- prisma/seed.ts | 463 +++++++++++++++++- .../host/addPaymentDetails.validation.ts | 9 + src/modules/host/dto/host.dto.ts | 3 +- .../host/handlers/addPaymentDetails.ts | 2 +- .../prepopulate/handlers/getAllBankDetails.ts | 47 ++ .../services/prepopulate.service.ts | 35 ++ 7 files changed, 590 insertions(+), 63 deletions(-) create mode 100644 src/modules/prepopulate/handlers/getAllBankDetails.ts create mode 100644 src/modules/prepopulate/services/prepopulate.service.ts diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 12e500a..aaee557 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -30,11 +30,11 @@ model User { updatedAt DateTime? @updatedAt @map("updated_at") deletedAt DateTime? @map("deleted_at") UserOtp UserOtp[] - Connections Connections? @relation(fields: [connectionsId], references: [id]) - connectionsId Int? - EnergyLevels EnergyLevels? @relation(fields: [energyLevelsId], references: [id]) + Connections Connections? @relation(fields: [connectionsXid], references: [id]) + connectionsXid Int? @map("connections_xid") + EnergyLevels EnergyLevels? @relation(fields: [energyLevelsXid], references: [id]) isBiometric Boolean? @default(false) @map("is_biometric") - energyLevelsId Int? + energyLevelsXid Int? @map("energy_levels_xid") hostHeaders HostHeader[] @relation("HostUser") managedHostHeaders HostHeader[] @relation("AccountManager") Token Token[] @@ -226,17 +226,18 @@ model Countries { } model Currencies { - id Int @id @default(autoincrement()) - countryXid Int @map("country_xid") - country Countries @relation(fields: [countryXid], references: [id], onDelete: Restrict) - currencyName String @unique @map("currency_name") - currencySymbol String @unique @map("currency_symbol") - 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") - HostHeader HostHeader[] - Activities Activities[] + id Int @id @default(autoincrement()) + countryXid Int @map("country_xid") + country Countries @relation(fields: [countryXid], references: [id], onDelete: Restrict) + currencyName String @unique @map("currency_name") + currencySymbol String @unique @map("currency_symbol") + 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") + HostHeader HostHeader[] + Activities Activities[] + hostBankDetails HostBankDetails[] @@map("currencies") @@schema("mst") @@ -371,6 +372,7 @@ model DocumentType { id Int @id @default(autoincrement()) documentTypeName String @unique @map("document_type_name") isVisible Boolean @default(true) @map("is_visible") + displayOrder Int @map("display_order") isActive Boolean @default(true) @map("is_active") createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") @@ -474,33 +476,49 @@ model TransportModes { } model PQQCategories { - id Int @id @default(autoincrement()) - categoryName String @unique @map("category_name") - subCategoryName String @map("sub_category_name") - categoryTitle String @map("category_title") - displayOrder Int @map("display_order") - 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") - PQQQuestions PQQQuestions[] + id Int @id @default(autoincrement()) + categoryName String @unique @map("category_name") + displayOrder Int @map("display_order") + 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") + pqqsubCategories PQQSubCategories[] @@map("pqq_categories") @@schema("mst") } +model PQQSubCategories { + id Int @id @default(autoincrement()) + categoryXid Int @map("category_xid") + category PQQCategories @relation(fields: [categoryXid], references: [id], onDelete: Cascade) + subCategoryName String @map("sub_category_name") + displayOrder Int @map("display_order") + 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") + + questions PQQQuestions[] + + @@map("pqq_sub_categories") + @@schema("mst") +} + model PQQQuestions { - id Int @id @default(autoincrement()) - pqqCategoryXid Int @map("pqq_category_xid") - pqqCategories PQQCategories @relation(fields: [pqqCategoryXid], references: [id], onDelete: Cascade) - questionName String @unique @map("question_name") - displayOrder Int @map("display_order") - 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") - PQQAnswers PQQAnswers[] - ActivityPQQheader ActivityPQQheader[] + id Int @id @default(autoincrement()) + pqqSubCategoryXid Int @map("pqq_sub_category_xid") + pqqSubCategories PQQSubCategories @relation(fields: [pqqSubCategoryXid], references: [id], onDelete: Cascade) + questionName String @unique @map("question_name") + maxPoints Int @map("max_points") + displayOrder Int @map("display_order") + 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") + PQQAnswers PQQAnswers[] + ActivityPQQheader ActivityPQQheader[] @@map("pqq_questions") @@schema("mst") @@ -511,7 +529,7 @@ model PQQAnswers { pqqQuestionXid Int @map("pqq_question_xid") pqqQuestions PQQQuestions @relation(fields: [pqqQuestionXid], references: [id], onDelete: Cascade) answerName String @map("answer_name") - answerScore String @map("answer_score") + answerPoints Int @map("answer_points") displayOrder Int @map("display_order") isActive Boolean @default(true) @map("is_active") createdAt DateTime @default(now()) @map("created_at") @@ -689,6 +707,8 @@ model HostBankDetails { accountHolderName String @map("account_holder_name") accountNumber String @unique @map("account_number") ifscCode String @map("ifsc_code") + currencyXid Int @map("currency_xid") + currencies Currencies @relation(fields: [currencyXid], references: [id], onDelete: Restrict) isActive Boolean @default(true) @map("is_active") createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") diff --git a/prisma/seed.ts b/prisma/seed.ts index 93d5cbf..d3d9c75 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -241,42 +241,457 @@ async function main() { }); // ✅ PQQ Categories + Questions + Answers - const category = await prisma.pQQCategories.upsert({ - where: { categoryName: 'General' }, - update: {}, - create: { - categoryName: 'General', - subCategoryName: 'Basic', - categoryTitle: 'General Information', + + // const PQQCategories = await prisma.pQQCategories.upsert({ + // where: { categoryName: "Sustainability" }, + // update: {}, + // create: { + // categoryName: "Sustainability", + // displayOrder: 1, + // isActive: true, + + // pqqsubCategories: { + // create: [ + // // ----------------------------------------------------- + // // SUBCATEGORY 1: Environmental Practices + // // ----------------------------------------------------- + // { + // subCategoryName: "Environmental Practices", + // displayOrder: 1, + // isActive: true, + + // questions: { + // create: [ + // // QUESTION 1 + // { + // questionName: 'What waste management practices do you have in place to minimize environmental impact? Examples: Recycling bins, composting organic waste, reducing single-use plastics.', + // maxPoints: 10, + // displayOrder: 1, + // PQQAnswers: { + // create: [ + // { answerName: 'We do not have specific waste management practices.', answerPoints: 0, displayOrder: 1 }, + // { answerName: 'We separate waste and recycle basic items like paper and plastic.', answerPoints: 5, displayOrder: 2 }, + // { answerName: 'We have a comprehensive recycling program including composting organic waste.', answerPoints: 8, displayOrder: 3 }, + // { answerName: 'We actively reduce waste at the source and partner with local recycling organizations.', answerPoints: 10, displayOrder: 4 }, + // ], + // }, + // }, + + // // QUESTION 2 + // { + // questionName: 'Can you provide examples of energy-efficient appliances or renewable energy sources you use? Examples: Solar panels, energy-efficient lighting, renewable energy certificates.', + // maxPoints: 10, + // displayOrder: 2, + // PQQAnswers: { + // create: [ + // { answerName: 'We do not use energy-efficient appliances or renewable energy sources.', answerPoints: 0, displayOrder: 1 }, + // { answerName: 'We use energy-efficient light bulbs and appliances.', answerPoints: 5, displayOrder: 2 }, + // { answerName: 'We have solar panels and energy-efficient heating/cooling systems.', answerPoints: 8, displayOrder: 3 }, + // { answerName: 'We utilize a combination of renewable energy sources and advanced energy-saving technologies.', answerPoints: 10, displayOrder: 4 }, + // ], + // }, + // }, + // { + // questionName: 'What measures do you take to conserve water? Examples: Low-flow fixtures, rainwater harvesting, greywater recycling.', + // maxPoints: 10, + // displayOrder: 3, + // PQQAnswers: { + // create: [ + // { answerName: 'We do not have specific water conservation measures.', answerPoints: 0, displayOrder: 1 }, + // { answerName: 'We encourage guests to limit water use.', answerPoints: 5, displayOrder: 2 }, + // { answerName: 'We have low-flow fixtures and water-saving appliances installed.', answerPoints: 8, displayOrder: 3 }, + // { answerName: 'We implement rainwater harvesting and greywater recycling systems.', answerPoints: 10, displayOrder: 4 }, + // ], + // }, + // }, + // { + // questionName: 'How do you monitor and reduce your carbon footprint? Examples: Carbon audits, offsetting emissions, energy-saving initiatives.', + // maxPoints: 10, + // displayOrder: 4, + // PQQAnswers: { + // create: [ + // { answerName: 'We do not monitor or take steps to reduce our carbon footprint.', answerPoints: 0, displayOrder: 1 }, + // { answerName: 'We track our energy usage and try to minimize it.', answerPoints: 5, displayOrder: 2 }, + // { answerName: 'We have set carbon reduction targets and regularly monitor our progress.', answerPoints: 8, displayOrder: 3 }, + // { answerName: 'We offset our carbon emissions through verified programs and continually improve our sustainability practices.', answerPoints: 10, displayOrder: 4 }, + // ], + // }, + // }, + // { + // questionName: 'Do you source products and materials sustainably? Can you provide examples? Examples: Local, organic, fair-trade products.', + // maxPoints: 10, + // displayOrder: 5, + // PQQAnswers: { + // create: [ + // { answerName: 'We do not prioritize sustainable sourcing.', answerPoints: 0, displayOrder: 1 }, + // { answerName: 'We source some products locally and sustainably.', answerPoints: 5, displayOrder: 2 }, + // { answerName: 'We prioritize local, organic, and fair-trade products.', answerPoints: 8, displayOrder: 3 }, + // { answerName: 'We have strict sourcing policies that ensure all products are sustainable and ethically produced.', answerPoints: 10, displayOrder: 4 }, + // ], + // }, + // }, + // ] + // } + // }, + + // // ----------------------------------------------------- + // // SUBCATEGORY 2: Community Impact + // // ----------------------------------------------------- + // { + // subCategoryName: "Community Impact", + // displayOrder: 2, + // isActive: true, + + // questions: { + // create: [ + // // QUESTION 1 + // { + // questionName: + // "How do you support local employment and engage with the community? Examples: Hiring local staff, partnering with community organizations, participating in local events.", + // maxPoints: 10, + // displayOrder: 1, + + // PQQAnswers: { + // create: [ + // { answerName: "We do not have specific practices to support local employment or community engagement.", answerPoints: 0, displayOrder: 1 }, + // { answerName: "We hire local staff but do not have formal community engagement programs.", answerPoints: 5, displayOrder: 2 }, + // { answerName: "We actively employ local residents and participate in community events.", answerPoints: 8, displayOrder: 3 }, + // { answerName: "We have partnerships with local organizations and invest in community development projects.", answerPoints: 10, displayOrder: 4 } + // ] + // } + // }, + // // QUESTION 2 + // { + // questionName: + // "Are you involved in any community projects or cultural preservation activities? Examples: Supporting local artisans, sponsoring cultural festivals, contributing to community development.", + // maxPoints: 10, + // displayOrder: 2, + + // PQQAnswers: { + // create: [ + // { answerName: "We are not involved in any community or cultural preservation projects.", answerPoints: 0, displayOrder: 1 }, + // { answerName: "We support community projects through donations.", answerPoints: 5, displayOrder: 2 }, + // { answerName: "We participate in and organize community events and cultural preservation activities.", answerPoints: 8, displayOrder: 3 }, + // { answerName: "We lead major community development initiatives and cultural preservation projects.", answerPoints: 10, displayOrder: 4 } + // ] + // } + // }, + // // QUESTION 3 + // { + // questionName: + // "Can you provide examples of how your business benefits the local community? Examples: Providing jobs, sourcing local products, investing in local infrastructure.", + // maxPoints: 10, + // displayOrder: 3, + + // PQQAnswers: { + // create: [ + // { answerName: "We do not have specific examples.", answerPoints: 0, displayOrder: 1 }, + // { answerName: "We provide employment opportunities for local residents.", answerPoints: 5, displayOrder: 2 }, + // { answerName: "We support local businesses by sourcing products and services locally.", answerPoints: 8, displayOrder: 3 }, + // { answerName: "We invest in local infrastructure and educational programs.", answerPoints: 10, displayOrder: 4 } + // ] + // } + // }, + // ] + // } + // }, + // // ----------------------------------------------------- + // //SUBCATEGORY 3 : Sustainable Tourism Certification + // // ----------------------------------------------------- + // { + // subCategoryName: "Sustainable Tourism Certification", + // displayOrder: 2, + // isActive: true, + + // questions: { + // create: [ + // // QUESTION 1 + // { + // questionName: + // "Do you have any recognized sustainable tourism certifications (e.g., Green Globe, EarthCheck, Travelife)? Please provide details. Examples: Certification names and details, certificates.", + // maxPoints: 10, + // displayOrder: 1, + + // PQQAnswers: { + // create: [ + // { answerName: "We do not have any sustainable tourism certifications.", answerPoints: 0, displayOrder: 1 }, + // { answerName: "We are in the process of obtaining a certification.", answerPoints: 5, displayOrder: 2 }, + // { answerName: "We have one recognized sustainable tourism certification.", answerPoints: 8, displayOrder: 3 }, + // { answerName: "We hold multiple recognized sustainable tourism certifications and regularly audit our practices.", answerPoints: 10, displayOrder: 4 } + // { answerName: "Not applicable", answerPoints: 0, displayOrder: 5 } + // ] + // } + // } + // ] + // } + // }, + // ] + // } + // }, + + // include: { + // pqqsubCategories: { + // include: { + // questions: { + // include: { + // PQQAnswers: true + // } + // } + // } + // } + // } + // }); + const categoriesData = [ + { + categoryName: "Sustainability", displayOrder: 1, isActive: true, - PQQQuestions: { + + pqqsubCategories: { create: [ + // ----------------------------------------------------- + // SUBCATEGORY 1: Environmental Practices + // ----------------------------------------------------- { - questionName: 'Do you have insurance?', + subCategoryName: "Environmental Practices", displayOrder: 1, - PQQAnswers: { + isActive: true, + + questions: { create: [ - { answerName: 'Yes', answerScore: '10', displayOrder: 1 }, - { answerName: 'No', answerScore: '0', displayOrder: 2 }, - ], - }, + // QUESTION 1 + { + questionName: 'What waste management practices do you have in place to minimize environmental impact? Examples: Recycling bins, composting organic waste, reducing single-use plastics.', + maxPoints: 10, + displayOrder: 1, + PQQAnswers: { + create: [ + { answerName: 'We do not have specific waste management practices.', answerPoints: 0, displayOrder: 1 }, + { answerName: 'We separate waste and recycle basic items like paper and plastic.', answerPoints: 5, displayOrder: 2 }, + { answerName: 'We have a comprehensive recycling program including composting organic waste.', answerPoints: 8, displayOrder: 3 }, + { answerName: 'We actively reduce waste at the source and partner with local recycling organizations.', answerPoints: 10, displayOrder: 4 }, + ], + }, + }, + + // QUESTION 2 + { + questionName: 'Can you provide examples of energy-efficient appliances or renewable energy sources you use? Examples: Solar panels, energy-efficient lighting, renewable energy certificates.', + maxPoints: 10, + displayOrder: 2, + PQQAnswers: { + create: [ + { answerName: 'We do not use energy-efficient appliances or renewable energy sources.', answerPoints: 0, displayOrder: 1 }, + { answerName: 'We use energy-efficient light bulbs and appliances.', answerPoints: 5, displayOrder: 2 }, + { answerName: 'We have solar panels and energy-efficient heating/cooling systems.', answerPoints: 8, displayOrder: 3 }, + { answerName: 'We utilize a combination of renewable energy sources and advanced energy-saving technologies.', answerPoints: 10, displayOrder: 4 }, + ], + }, + }, + { + questionName: 'What measures do you take to conserve water? Examples: Low-flow fixtures, rainwater harvesting, greywater recycling.', + maxPoints: 10, + displayOrder: 3, + PQQAnswers: { + create: [ + { answerName: 'We do not have specific water conservation measures.', answerPoints: 0, displayOrder: 1 }, + { answerName: 'We encourage guests to limit water use.', answerPoints: 5, displayOrder: 2 }, + { answerName: 'We have low-flow fixtures and water-saving appliances installed.', answerPoints: 8, displayOrder: 3 }, + { answerName: 'We implement rainwater harvesting and greywater recycling systems.', answerPoints: 10, displayOrder: 4 }, + ], + }, + }, + { + questionName: 'How do you monitor and reduce your carbon footprint? Examples: Carbon audits, offsetting emissions, energy-saving initiatives.', + maxPoints: 10, + displayOrder: 4, + PQQAnswers: { + create: [ + { answerName: 'We do not monitor or take steps to reduce our carbon footprint.', answerPoints: 0, displayOrder: 1 }, + { answerName: 'We track our energy usage and try to minimize it.', answerPoints: 5, displayOrder: 2 }, + { answerName: 'We have set carbon reduction targets and regularly monitor our progress.', answerPoints: 8, displayOrder: 3 }, + { answerName: 'We offset our carbon emissions through verified programs and continually improve our sustainability practices.', answerPoints: 10, displayOrder: 4 }, + ], + }, + }, + { + questionName: 'Do you source products and materials sustainably? Can you provide examples? Examples: Local, organic, fair-trade products.', + maxPoints: 10, + displayOrder: 5, + PQQAnswers: { + create: [ + { answerName: 'We do not prioritize sustainable sourcing.', answerPoints: 0, displayOrder: 1 }, + { answerName: 'We source some products locally and sustainably.', answerPoints: 5, displayOrder: 2 }, + { answerName: 'We prioritize local, organic, and fair-trade products.', answerPoints: 8, displayOrder: 3 }, + { answerName: 'We have strict sourcing policies that ensure all products are sustainable and ethically produced.', answerPoints: 10, displayOrder: 4 }, + ], + }, + }, + ] + } }, + + // ----------------------------------------------------- + // SUBCATEGORY 2: Community Impact + // ----------------------------------------------------- { - questionName: 'Do you have ISO certification?', + subCategoryName: "Community Impact", displayOrder: 2, - PQQAnswers: { + isActive: true, + + questions: { create: [ - { answerName: 'Yes', answerScore: '20', displayOrder: 1 }, - { answerName: 'No', answerScore: '0', displayOrder: 2 }, - ], - }, + // QUESTION 1 + { + questionName: + "How do you support local employment and engage with the community? Examples: Hiring local staff, partnering with community organizations, participating in local events.", + maxPoints: 10, + displayOrder: 1, + + PQQAnswers: { + create: [ + { answerName: "We do not have specific practices to support local employment or community engagement.", answerPoints: 0, displayOrder: 1 }, + { answerName: "We hire local staff but do not have formal community engagement programs.", answerPoints: 5, displayOrder: 2 }, + { answerName: "We actively employ local residents and participate in community events.", answerPoints: 8, displayOrder: 3 }, + { answerName: "We have partnerships with local organizations and invest in community development projects.", answerPoints: 10, displayOrder: 4 } + ] + } + }, + // QUESTION 2 + { + questionName: + "Are you involved in any community projects or cultural preservation activities? Examples: Supporting local artisans, sponsoring cultural festivals, contributing to community development.", + maxPoints: 10, + displayOrder: 2, + + PQQAnswers: { + create: [ + { answerName: "We are not involved in any community or cultural preservation projects.", answerPoints: 0, displayOrder: 1 }, + { answerName: "We support community projects through donations.", answerPoints: 5, displayOrder: 2 }, + { answerName: "We participate in and organize community events and cultural preservation activities.", answerPoints: 8, displayOrder: 3 }, + { answerName: "We lead major community development initiatives and cultural preservation projects.", answerPoints: 10, displayOrder: 4 } + ] + } + }, + // QUESTION 3 + { + questionName: + "Can you provide examples of how your business benefits the local community? Examples: Providing jobs, sourcing local products, investing in local infrastructure.", + maxPoints: 10, + displayOrder: 3, + + PQQAnswers: { + create: [ + { answerName: "We do not have specific examples.", answerPoints: 0, displayOrder: 1 }, + { answerName: "We provide employment opportunities for local residents.", answerPoints: 5, displayOrder: 2 }, + { answerName: "We support local businesses by sourcing products and services locally.", answerPoints: 8, displayOrder: 3 }, + { answerName: "We invest in local infrastructure and educational programs.", answerPoints: 10, displayOrder: 4 } + ] + } + }, + ] + } }, - ], - }, + // ----------------------------------------------------- + //SUBCATEGORY 3 : Sustainable Tourism Certification + // ----------------------------------------------------- + { + subCategoryName: "Sustainable Tourism Certification", + displayOrder: 2, + isActive: true, + + questions: { + create: [ + // QUESTION 1 + { + questionName: + "Do you have any recognized sustainable tourism certifications (e.g., Green Globe, EarthCheck, Travelife)? Please provide details. Examples: Certification names and details, certificates.", + maxPoints: 10, + displayOrder: 1, + + PQQAnswers: { + create: [ + { answerName: "We do not have any sustainable tourism certifications.", answerPoints: 0, displayOrder: 1 }, + { answerName: "We are in the process of obtaining a certification.", answerPoints: 5, displayOrder: 2 }, + { answerName: "We have one recognized sustainable tourism certification.", answerPoints: 8, displayOrder: 3 }, + { answerName: "We hold multiple recognized sustainable tourism certifications and regularly audit our practices.", answerPoints: 10, displayOrder: 4 }, + { answerName: "Not applicable", answerPoints: 0, displayOrder: 5 } + ] + } + } + ] + } + }, + ] + } }, - include: { PQQQuestions: true }, - }); + + // ---------------------------------------- + // ADD MORE CATEGORIES HERE + // Example: + // ---------------------------------------- + { + categoryName: "Safety", + displayOrder: 2, + subCategories: [ + { + subCategoryName: "General Safety Protocols", + displayOrder: 1, + questions: [ + { + questionName: "What safety measures do you have in place for your activities? Examples: Safety briefings, emergency exits, safety equipment.", + maxPoints: 10, + displayOrder: 1, + answers: [ + { name: "We do not have specific safety measures.", points: 0 }, + { name: "Basic fire extinguishers installed.", points: 5 }, + { name: "Full fire safety system installed.", points: 10 } + ] + } + ] + } + ] + } + + ]; + + for (const category of categoriesData) { + await prisma.pQQCategories.upsert({ + where: { categoryName: category.categoryName }, + update: {}, + create: { + categoryName: category.categoryName, + displayOrder: category.displayOrder, + isActive: true, + + pqqsubCategories: { + create: category.subCategories.map((sub) => ({ + subCategoryName: sub.subCategoryName, + displayOrder: sub.displayOrder, + isActive: true, + + questions: { + create: sub.questions.map((q) => ({ + questionName: q.questionName, + maxPoints: q.maxPoints, + displayOrder: q.displayOrder, + + PQQAnswers: { + create: q.answers.map((ans, i) => ({ + answerName: ans.name, + answerPoints: ans.points, + displayOrder: i + 1 + })) + } + })) + } + })) + } + } + }); + } + + console.log('✅ Seed data inserted successfully!'); } diff --git a/src/common/utils/validation/host/addPaymentDetails.validation.ts b/src/common/utils/validation/host/addPaymentDetails.validation.ts index 846b83d..7bdd7f3 100644 --- a/src/common/utils/validation/host/addPaymentDetails.validation.ts +++ b/src/common/utils/validation/host/addPaymentDetails.validation.ts @@ -6,6 +6,10 @@ export const hostBankDetailsSchema = z.object({ .string() .nonempty("Account number is required"), + confirmAccountNumber: z + .string() + .nonempty("Confirm account number is required"), + accountHolderName: z .string() .nonempty("Account holder name is required") @@ -30,6 +34,11 @@ export const hostBankDetailsSchema = z.object({ .number() .int({ message: "Bank branch ID must be an integer" }) .positive({ message: "Bank branch ID must be a positive number" }), + + currencyXid: z + .number() + .int({ message: "Currency ID must be an integer" }) + .positive({ message: "Currency ID must be a positive number" }), }); export type HostBankDetailsSchema = z.infer; diff --git a/src/modules/host/dto/host.dto.ts b/src/modules/host/dto/host.dto.ts index 16096ca..e07e110 100644 --- a/src/modules/host/dto/host.dto.ts +++ b/src/modules/host/dto/host.dto.ts @@ -81,8 +81,9 @@ export class AddPaymentDetailsDTO { accountHolderName: string; ifscCode: string; hostXid: number; + currencyXid: number; - constructor(bankXid: number, bankBranchXid: number, accountNumber: string, accountHolderName: string, ifscCode: string, hostXid: number) { + constructor(bankXid: number, bankBranchXid: number, accountNumber: string, accountHolderName: string, ifscCode: string, hostXid: number, currencyXid: number) { this.bankXid = bankXid; this.bankBranchXid = bankBranchXid; this.accountNumber = accountNumber; diff --git a/src/modules/host/handlers/addPaymentDetails.ts b/src/modules/host/handlers/addPaymentDetails.ts index 24be6ab..480fd56 100644 --- a/src/modules/host/handlers/addPaymentDetails.ts +++ b/src/modules/host/handlers/addPaymentDetails.ts @@ -33,7 +33,7 @@ export const handler = safeHandler(async ( } // Parse request body - let body: { bankXid?: number; bankBranchXid?: number; accountNumber?: string; accountHolderName?: string; ifscCode?: string }; + let body: { bankXid?: number; bankBranchXid?: number; accountNumber?: string; confirmAccountNumber?: string; accountHolderName?: string; ifscCode?: string; currencyXid?: number }; try { body = event.body ? JSON.parse(event.body) : {}; diff --git a/src/modules/prepopulate/handlers/getAllBankDetails.ts b/src/modules/prepopulate/handlers/getAllBankDetails.ts new file mode 100644 index 0000000..d0db47e --- /dev/null +++ b/src/modules/prepopulate/handlers/getAllBankDetails.ts @@ -0,0 +1,47 @@ +import { verifyOnlyMinglarAdminToken } from '@/common/middlewares/jwt/authForOnlyMinglarAdmin'; +import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda'; +import { PrismaService } from '../../../common/database/prisma.service'; +import { safeHandler } from '../../../common/utils/handlers/safeHandler'; +import ApiError from '../../../common/utils/helper/ApiError'; +import { PrePopulateService } from '../services/prepopulate.service'; +import { verifyHostToken } from '@/common/middlewares/jwt/authForHost'; + +const prismaService = new PrismaService(); +const prePopulateService = new PrePopulateService(prismaService); + +export const handler = safeHandler(async ( + event: APIGatewayProxyEvent, + context?: Context +): Promise => { + // 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 verifyHostToken(token); + + const bankDetails = await prePopulateService.getAllBankDetails(); + + const currencyDetails = await prePopulateService.getAllCurrencyDetails(); + + const result = { + banks: bankDetails, + currencies: currencyDetails, + } + + return { + statusCode: 200, + headers: { + 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', + }, + body: JSON.stringify({ + success: true, + message: 'Data retrieved successfully', + data: result, + }), + }; +}); + diff --git a/src/modules/prepopulate/services/prepopulate.service.ts b/src/modules/prepopulate/services/prepopulate.service.ts new file mode 100644 index 0000000..b22053b --- /dev/null +++ b/src/modules/prepopulate/services/prepopulate.service.ts @@ -0,0 +1,35 @@ +import { Injectable } from '@nestjs/common'; +import { PrismaService } from '../../../common/database/prisma.service'; + + +@Injectable() +export class PrePopulateService { + constructor(private prisma: PrismaService) { } + + async getAllBankDetails() { + return await this.prisma.banks.findMany({ + where: { + isActive: true, + deletedAt: null, + }, + include: { + BankBranches: { + select: { + id: true, + } + } + } + }) + } + + async getAllCurrencyDetails() { + return await this.prisma.currencies.findMany({ + where: { + isActive: true, + deletedAt: null, + }, + }) + } + + +}