diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 3bf0505..afa4f72 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -22,7 +22,7 @@ model User { 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(10) // 4–6 digit passcode + 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) diff --git a/src/common/utils/validation/user/addPersonalInfo.validation.ts b/src/common/utils/validation/user/addPersonalInfo.validation.ts index b2475b6..47bfc21 100644 --- a/src/common/utils/validation/user/addPersonalInfo.validation.ts +++ b/src/common/utils/validation/user/addPersonalInfo.validation.ts @@ -16,7 +16,10 @@ export const userPersonalInfoSchema = z.object({ dateOfBirth: z .string() - .nonempty("Date of birth is required"), + .nonempty("Date of birth is required") + .refine(val => !isNaN(Date.parse(val)), { + message: "Date of birth must be a valid ISO date (YYYY-MM-DD)", + }), }); diff --git a/src/modules/user/dto/user.dto.ts b/src/modules/user/dto/user.dto.ts index 46c26be..aef14a1 100644 --- a/src/modules/user/dto/user.dto.ts +++ b/src/modules/user/dto/user.dto.ts @@ -1,17 +1,3 @@ -export class AddPersonalInfoDTO { - firstName: string; - lastName?: string; - genderName: string; - dateOfBirth: string; - - constructor(firstName: string, genderName: string, dateOfBirth: string, lastName?: string) { - this.firstName = firstName; - this.lastName = lastName; - this.genderName = genderName; - this.dateOfBirth = dateOfBirth; - } -} - export class SetPasscodeDTO { userPasscode: string; confirmPasscode: string; diff --git a/src/modules/user/handlers/authentication/submitPersonalInfo.ts b/src/modules/user/handlers/authentication/submitPersonalInfo.ts index c1cbb77..6b2e14b 100644 --- a/src/modules/user/handlers/authentication/submitPersonalInfo.ts +++ b/src/modules/user/handlers/authentication/submitPersonalInfo.ts @@ -52,10 +52,12 @@ export const handler = safeHandler(async ( const validatedData = validationResult.data; - await userService.addPersonalInfo({ + await userService.addPersonalInfo(userId, { ...validatedData }); + const interests = await userService.getAllInterestDetails(); + return { statusCode: 200, headers: { @@ -65,6 +67,7 @@ export const handler = safeHandler(async ( body: JSON.stringify({ success: true, message: 'Personal Info added successfully', + data: interests }), }; }); \ No newline at end of file diff --git a/src/modules/user/services/user.service.ts b/src/modules/user/services/user.service.ts index a0b99a7..b38de5d 100644 --- a/src/modules/user/services/user.service.ts +++ b/src/modules/user/services/user.service.ts @@ -1,8 +1,8 @@ import { Injectable } from '@nestjs/common'; import { PrismaClient, User } from '@prisma/client'; -import { AddPersonalInfoDTO } from '../dto/user.dto'; import ApiError from '@/common/utils/helper/ApiError'; import * as bcrypt from 'bcryptjs'; +import { UserPersonalInfoSchema } from '@/common/utils/validation/user/addPersonalInfo.validation'; @Injectable() export class UserService { constructor(private prisma: PrismaClient) { } @@ -13,19 +13,39 @@ export class UserService { }); } - async addPersonalInfo(data: AddPersonalInfoDTO) { + async addPersonalInfo(userId: number, data: UserPersonalInfoSchema) { return await this.prisma.$transaction(async (tx) => { - - const addPersonalInfo = await tx.user.create({ - data, + const updatedUser = await tx.user.update({ + where: { id: userId }, + data: { + firstName: data.firstName, + lastName: data.lastName ?? null, + genderName: data.genderName, + dateOfBirth: data.dateOfBirth + ? new Date(data.dateOfBirth) + : null, + isProfileUpdated: true, + }, }); - if (!addPersonalInfo) { - throw new ApiError(400, 'Failed to add personal info'); + return updatedUser; + }); + } + + async getAllInterestDetails() { + return await this.prisma.interests.findMany({ + where: { isActive: true }, + select: { + id: true, + interestName: true, + interestColor: true, + interestImage: true, + displayOrder: true } }) } + async getUserByMobileNumber(mobileNumber: string): Promise { return this.prisma.user.findFirst({ where: { mobileNumber: mobileNumber, isActive: true },