From 6ea2ebe5e14e34496253e2f4c4a97b3be52bccb7 Mon Sep 17 00:00:00 2001 From: Mayank Mishra Date: Tue, 7 Apr 2026 13:36:11 +0530 Subject: [PATCH] added the dataconsent flags --- prisma/schema.prisma | 52 ++++++++++--------- .../handlers/Host_Admin/onboarding/signUp.ts | 31 ++++++++--- 2 files changed, 50 insertions(+), 33 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 965b71d..313fc9c 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -2,7 +2,7 @@ generator client { provider = "prisma-client-js" binaryTargets = ["native", "rhel-openssl-3.0.x"] // Lambda Node 18/20 (Amazon Linux) target previewFeatures = ["multiSchema"] - engineType = "library" + engineType = "library" } datasource db { @@ -12,30 +12,32 @@ datasource db { } model User { - id Int @id @default(autoincrement()) - firstName String? @map("first_name") @db.VarChar(50) - lastName String? @map("last_name") @db.VarChar(50) - roleXid Int? @map("role_xid") - dateOfBirth DateTime? @map("date_of_birth") - genderName String? @map("gender_name") @db.VarChar(20) - role Roles? @relation(fields: [roleXid], references: [id], onDelete: Restrict) - emailAddress String? @unique @map("email_address") @db.VarChar(150) - isdCode String? @map("isd_code") @db.VarChar(6) // +91, +1, +971 etc. - mobileNumber String? @unique @map("mobile_number") @db.VarChar(15) // international safe limit - userPassword String? @map("user_password") @db.VarChar(255) // hashed passwords - userPasscode String? @map("user_passcode") @db.VarChar(255) // 4–6 digit passcode - profileImage String? @map("profile_image") @db.VarChar(500) // S3 key or URL - userLat String? @map("user_lat") @db.VarChar(20) // "-23.44444" - userLong String? @map("user_long") @db.VarChar(20) - userStatus String? @default("pending") @map("user_status") @db.VarChar(20) - isEmailVerfied Boolean? @default(false) @map("is_email_verified") - isMobileVerfied Boolean? @default(false) @map("is_mobile_verified") - isProfileUpdated Boolean? @default(false) @map("is_profile_updated") - userRefNumber String? @unique @map("user_ref_number") @db.VarChar(20) - 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") + id Int @id @default(autoincrement()) + firstName String? @map("first_name") @db.VarChar(50) + lastName String? @map("last_name") @db.VarChar(50) + roleXid Int? @map("role_xid") + dateOfBirth DateTime? @map("date_of_birth") + genderName String? @map("gender_name") @db.VarChar(20) + role Roles? @relation(fields: [roleXid], references: [id], onDelete: Restrict) + emailAddress String? @unique @map("email_address") @db.VarChar(150) + isdCode String? @map("isd_code") @db.VarChar(6) // +91, +1, +971 etc. + mobileNumber String? @unique @map("mobile_number") @db.VarChar(15) // international safe limit + userPassword String? @map("user_password") @db.VarChar(255) // hashed passwords + userPasscode String? @map("user_passcode") @db.VarChar(255) // 4–6 digit passcode + profileImage String? @map("profile_image") @db.VarChar(500) // S3 key or URL + userLat String? @map("user_lat") @db.VarChar(20) // "-23.44444" + userLong String? @map("user_long") @db.VarChar(20) + userStatus String? @default("pending") @map("user_status") @db.VarChar(20) + isEmailVerfied Boolean? @default(false) @map("is_email_verified") + isMobileVerfied Boolean? @default(false) @map("is_mobile_verified") + isProfileUpdated Boolean? @default(false) @map("is_profile_updated") + userRefNumber String? @unique @map("user_ref_number") @db.VarChar(20) + dataConsentAccepted Boolean? @default(false) @map("data_consent_accepted") + dataConsentAcceptedOn DateTime? @map("data_consent_accepted_on") + 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") // Relations UserOtp UserOtp[] diff --git a/src/modules/host/handlers/Host_Admin/onboarding/signUp.ts b/src/modules/host/handlers/Host_Admin/onboarding/signUp.ts index 8c79472..a67b26c 100644 --- a/src/modules/host/handlers/Host_Admin/onboarding/signUp.ts +++ b/src/modules/host/handlers/Host_Admin/onboarding/signUp.ts @@ -4,13 +4,9 @@ import { prismaClient } from '../../../../../common/database/prisma.lambda.servi import { ROLE } from '../../../../../common/utils/constants/common.constant'; import { safeHandler } from '../../../../../common/utils/handlers/safeHandler'; import ApiError from '../../../../../common/utils/helper/ApiError'; -import { encryptUserId } from '../../../../../common/utils/helper/CodeGenerator'; import { OtpGeneratorSixDigit } from '../../../../../common/utils/helper/OtpGenerator'; -import { HostService } from '../../../services/host.service'; import { sendOtpEmailForHost } from '@/modules/host/services/sendOTPEmail.service'; -const hostService = new HostService(prismaClient); - export async function generateHostRefNumber(tx: any) { const lastrecord = await tx.user.findFirst({ orderBy: { @@ -45,13 +41,23 @@ export const handler = safeHandler(async ( throw new ApiError(400, 'Email is required'); } - const emailToLowerCase = email.toLowerCase() + const emailToLowerCase = email.trim().toLowerCase(); + + if (!emailToLowerCase) { + throw new ApiError(400, 'Email is required'); + } // Use a single transaction for user creation/lookup and OTP storage const transactionResult = await prismaClient.$transaction(async (tx) => { const user = await tx.user.findUnique({ where: { emailAddress: emailToLowerCase }, - select: { emailAddress: true, id: true, userPassword: true }, + select: { + emailAddress: true, + id: true, + userPassword: true, + dataConsentAccepted: true, + dataConsentAcceptedOn: true, + }, }); if (user && user.userPassword) { @@ -93,9 +99,18 @@ export const handler = safeHandler(async ( }, }); - const encryptedId = encryptUserId(String(newUserLocal.id)); + await tx.user.update({ + where: { id: Number(newUserLocal.id) }, + data: { + dataConsentAccepted: true, + dataConsentAcceptedOn: + user?.dataConsentAccepted && user?.dataConsentAcceptedOn + ? user.dataConsentAcceptedOn + : new Date(), + }, + }); - return { newUser: newUserLocal, otp, encryptedId }; + return { newUser: newUserLocal, otp }; }); if (!transactionResult || !transactionResult.otp) {