From 46c8432582b1715e1c966618b59aec82f42baa3e Mon Sep 17 00:00:00 2001 From: paritosh18 Date: Fri, 30 Jan 2026 15:30:45 +0530 Subject: [PATCH] feat: implement setPasscodeForMobile functionality - Added a new API endpoint to set a user passcode with validation. - Created SetPasscodeDTO for passcode input validation. - Implemented setUserPasscode method in UserService to handle passcode setting. - Updated user.yml to include the new set-passcode endpoint. - Created setPasscodeForMobile handler to manage the passcode setting logic. - Removed unused test-stepper-handler.ts file. - Deleted Dockerfile, docker-compose.yml, init.sql, and serverless.yml.backup files as part of cleanup. --- Dockerfile | 62 -- docker-compose.yml | 86 -- init.sql | 19 - serverless.yml.backup | 764 ------------------ serverless/functions/user.yml | 16 + src/modules/user/dto/user.dto.ts | 10 + .../authentication/setPasscodeForMobile.ts | 65 ++ src/modules/user/services/user.service.ts | 26 +- test-stepper-handler.ts | 122 --- 9 files changed, 116 insertions(+), 1054 deletions(-) delete mode 100644 Dockerfile delete mode 100644 docker-compose.yml delete mode 100644 init.sql delete mode 100644 serverless.yml.backup create mode 100644 src/modules/user/handlers/authentication/setPasscodeForMobile.ts delete mode 100644 test-stepper-handler.ts diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index f9e941e..0000000 --- a/Dockerfile +++ /dev/null @@ -1,62 +0,0 @@ -# Multi-stage build for NestJS Serverless Application -FROM node:18-alpine AS builder - -# Set working directory -WORKDIR /app - -# Copy package files -COPY package*.json ./ -COPY prisma ./prisma/ - -# Install dependencies -RUN npm ci --only=production && npm cache clean --force - -# Copy source code -COPY . . - -# Generate Prisma client -RUN npx prisma generate - -# Build the application -RUN npm run build - -# Production stage -FROM node:18-alpine AS production - -# Set working directory -WORKDIR /app - -# Install serverless framework globally -RUN npm install -g serverless - -# Copy package files -COPY package*.json ./ - -# Install production dependencies -RUN npm ci --only=production && npm cache clean --force - -# Copy built application -COPY --from=builder /app/dist ./dist -COPY --from=builder /app/prisma ./prisma -COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma - -# Copy serverless configuration -COPY serverless*.yml ./ - -# Create non-root user -RUN addgroup -g 1001 -S nodejs -RUN adduser -S nestjs -u 1001 - -# Change ownership -RUN chown -R nestjs:nodejs /app -USER nestjs - -# Expose port -EXPOSE 3000 - -# Health check -HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ - CMD curl -f http://localhost:3000/health || exit 1 - -# Start the application -CMD ["npm", "run", "start:prod"] diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index cfde064..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,86 +0,0 @@ -version: '3.8' - -services: - # PostgreSQL Database - postgres: - image: postgres:15-alpine - container_name: nestjs-postgres - restart: unless-stopped - environment: - POSTGRES_DB: nestjs_user_crud - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - ports: - - "5432:5432" - volumes: - - postgres_data:/var/lib/postgresql/data - - ./init.sql:/docker-entrypoint-initdb.d/init.sql - networks: - - nestjs-network - - # Redis for caching (optional) - redis: - image: redis:7-alpine - container_name: nestjs-redis - restart: unless-stopped - ports: - - "6379:6379" - volumes: - - redis_data:/data - networks: - - nestjs-network - - # NestJS Application - app: - build: - context: . - dockerfile: Dockerfile - target: production - container_name: nestjs-app - restart: unless-stopped - ports: - - "3000:3000" - environment: - NODE_ENV: development - DATABASE_URL: postgresql://postgres:postgres@postgres:5432/nestjs_user_crud?schema=public - JWT_SECRET: docker-jwt-secret-key - JWT_EXPIRES_IN: 7d - API_PREFIX: api/v1 - API_VERSION: 1.0.0 - THROTTLE_TTL: 60 - THROTTLE_LIMIT: 10 - CORS_ORIGIN: http://localhost:3000 - depends_on: - - postgres - - redis - networks: - - nestjs-network - volumes: - - ./src:/app/src - - ./prisma:/app/prisma - - # Prisma Studio - prisma-studio: - image: node:18-alpine - container_name: nestjs-prisma-studio - restart: unless-stopped - ports: - - "5555:5555" - environment: - DATABASE_URL: postgresql://postgres:postgres@postgres:5432/nestjs_user_crud?schema=public - working_dir: /app - volumes: - - .:/app - command: sh -c "npm install && npx prisma generate && npx prisma studio --hostname 0.0.0.0" - depends_on: - - postgres - networks: - - nestjs-network - -volumes: - postgres_data: - redis_data: - -networks: - nestjs-network: - driver: bridge diff --git a/init.sql b/init.sql deleted file mode 100644 index b0ba128..0000000 --- a/init.sql +++ /dev/null @@ -1,19 +0,0 @@ --- Initialize database for NestJS Serverless Application --- This file is executed when the PostgreSQL container starts - --- Create database if it doesn't exist -SELECT 'CREATE DATABASE nestjs_user_crud' -WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'nestjs_user_crud')\gexec - --- Connect to the database -\c nestjs_user_crud; - --- Create extensions if needed -CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; - --- Set timezone -SET timezone = 'UTC'; - --- Create a user for the application (optional) --- CREATE USER nestjs_user WITH PASSWORD 'nestjs_password'; --- GRANT ALL PRIVILEGES ON DATABASE nestjs_user_crud TO nestjs_user; diff --git a/serverless.yml.backup b/serverless.yml.backup deleted file mode 100644 index 8036020..0000000 --- a/serverless.yml.backup +++ /dev/null @@ -1,764 +0,0 @@ -service: minglarDev - -provider: - name: aws - runtime: nodejs22.x - region: ap-south-1 - versionFunctions: false - memorySize: 512 # Default memory for all functions (can be overridden per function) - apiGateway: - binaryMediaTypes: - - '*/*' - minimumCompressionSize: 1024 - - environment: - DATABASE_URL: ${env:DATABASE_URL} - DB_USERNAME: ${env:DB_USERNAME} - DB_PASSWORD: ${env:DB_PASSWORD} - DB_DATABASE_NAME: ${env:DB_DATABASE_NAME} - DB_HOSTNAME: ${env:DB_HOSTNAME} - DB_PORT: ${env:DB_PORT} - BY_PASS_EMAIL: ${env:BY_PASS_EMAIL} - BYPASS_OTP: ${env:BYPASS_OTP} - BREVO_EMAIL_API_KEY: ${env:BREVO_EMAIL_API_KEY} - BREVO_API_BASEURL: ${env:BREVO_API_BASEURL} - BREVO_FROM_EMAIL: ${env:BREVO_FROM_EMAIL} - BREVO_SMTP_HOST: ${env:BREVO_SMTP_HOST} - BREVO_SMTP_PORT: ${env:BREVO_SMTP_PORT} - BREVO_SMTP_USER: ${env:BREVO_SMTP_USER} - BREVO_SMTP_PASS: ${env:BREVO_SMTP_PASS} - REFRESH_TOKEN_SECRET: ${env:REFRESH_TOKEN_SECRET} - JWT_SECRET: ${env:JWT_SECRET} - SALT_ROUNDS: ${env:SALT_ROUNDS} - NODE_ENV: ${env:NODE_ENV} - S3_BUCKET_NAME: ${env:S3_BUCKET_NAME} - MINGLAR_ADMIN_NAME: ${env:MINGLAR_ADMIN_NAME} - MINGLAR_ADMIN_EMAIL: ${env:MINGLAR_ADMIN_EMAIL} - - iam: - role: - statements: - - Effect: Allow - Action: - - s3:PutObject - - s3:GetObject - - s3:DeleteObject - - s3:ListBucket - Resource: - - 'arn:aws:s3:::${env:S3_BUCKET_NAME}' - - 'arn:aws:s3:::${env:S3_BUCKET_NAME}/*' - -custom: - esbuild: - bundle: true - minify: true - sourcemap: false - target: node20 - platform: node - concurrency: 5 - external: - - '@prisma/client' - - '.prisma' - exclude: - - 'aws-sdk' - -package: - individually: true - patterns: - - '!node_modules/**' - - '!**/*.test.js' - - '!**/*.spec.js' - - '!**/test/**' - - '!**/__tests__/**' - - '!package-lock.json' - - '!yarn.lock' - - '!README.md' - - '!*.config.js' - - '!.git/**' - - '!.github/**' - -functions: - getHosts: - handler: src/modules/host/handlers/host.handler - memorySize: 384 # Lower memory for simple GET operations - package: - patterns: - - 'src/modules/host/handlers/host.*' - - 'src/modules/host/services/**' - - 'src/common/**' - - 'common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /host - method: get - - verifyOtp: - handler: src/modules/host/handlers/verifyOtp.handler - memorySize: 384 - package: - patterns: - - 'src/modules/host/handlers/verifyOtp.*' - - 'src/modules/host/services/**' - - 'src/common/**' - - 'common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /host/verify-otp - method: post - - loginForHost: - handler: src/modules/host/handlers/loginForHost.handler - memorySize: 384 - package: - patterns: - - 'src/modules/host/handlers/loginForHost.*' - - 'src/modules/host/services/**' - - 'src/common/**' - - 'common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /host/login - method: post - - registrationOfHost: - handler: src/modules/host/handlers/registration.handler - memorySize: 384 - package: - patterns: - - 'src/modules/host/handlers/registration.*' - - 'src/modules/host/services/**' - - 'src/common/**' - - 'common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /host/registration - method: post - - createPasswordForHost: - handler: src/modules/host/handlers/createPassword.handler - memorySize: 384 - package: - patterns: - - 'src/modules/host/handlers/createPassword.*' - - 'src/modules/host/services/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /host/create-password - method: post - - addPaymentDetailsForHost: - handler: src/modules/host/handlers/addPaymentDetails.handler - memorySize: 384 - package: - patterns: - - 'src/modules/host/handlers/addPaymentDetails.*' - - 'src/modules/host/services/**' - - 'src/common/**' - - 'common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /host/add-payment-details - method: post - - addActivity: - handler: src/modules/host/handlers/addActivity.handler - memorySize: 384 - package: - patterns: - - 'src/modules/host/handlers/addActivity.*' - - 'src/modules/host/services/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /host/add-activity - method: post - - getHostById: - handler: src/modules/host/handlers/getbyidhandler.handler - memorySize: 384 - package: - patterns: - - 'src/modules/host/handlers/getbyidhandler.*' - - 'src/modules/host/services/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /host/getById - method: get - - getPQQQuestionDetailsById: - handler: src/modules/host/handlers/getByIdPQQ.handler - memorySize: 384 - package: - patterns: - - 'src/modules/host/handlers/getByIdPQQ.*' - - 'src/modules/host/services/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /host/get-pqq-question-details - method: get - - getLatestPQQQuestionDetails: - handler: src/modules/host/handlers/getLatestQuestionDetailsPQQ.handler - memorySize: 384 - package: - patterns: - - 'src/modules/host/handlers/getLatestQuestionDetailsPQQ.*' - - 'src/modules/host/services/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /host/get-latest-pqq-question-details - method: get - - getActivityTypes: - handler: src/modules/host/handlers/getActivity.handler - memorySize: 384 - package: - patterns: - - 'src/modules/host/handlers/getActivity.*' - - 'src/modules/host/services/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /host/get-activity - method: get - - acceptMinglarAgreement: - handler: src/modules/host/handlers/acceptAgreement.handler - memorySize: 384 - package: - patterns: - - 'src/modules/host/handlers/acceptAgreement.*' - - 'src/modules/host/services/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /host/accept-agreement - method: patch - - getStepperInfo: - handler: src/modules/host/handlers/getStepper.handler - memorySize: 384 - package: - patterns: - - 'src/modules/host/handlers/getStepper.*' - - 'src/common/utils/handlers/safeHandler.*' - - 'src/common/database/**' - - 'src/modules/host/services/**' - - 'common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /stepper - method: get - - getSuggestion: - handler: src/modules/minglaradmin/handlers/getSuggestion.handler - memorySize: 384 - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /minglaradmin/get-suggestion - method: get - - minglarRegistration: - handler: src/modules/minglaradmin/handlers/registration.handler - memorySize: 384 - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /minglaradmin/registration - method: post - - minglarLoginForAdmin: - handler: src/modules/minglaradmin/handlers/loginForMinglar.handler - memorySize: 384 - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /minglaradmin/login - method: post - - minglarCreatePassword: - handler: src/modules/minglaradmin/handlers/createPassword.handler - memorySize: 384 - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /minglaradmin/create-password - method: post - - # Functions using AWS SDK - KEEP AS IS with higher memory - updateMinglarProfile: - handler: src/modules/minglaradmin/handlers/updateProfile.handler - memorySize: 512 # Higher memory for AWS SDK operations - timeout: 30 - package: - patterns: - - 'src/modules/minglaradmin/handlers/updateProfile.*' - - 'src/modules/minglaradmin/services/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - - 'node_modules/@aws-sdk/**' - - 'node_modules/@smithy/**' - - 'node_modules/tslib/**' - - 'node_modules/fast-xml-parser/**' - events: - - httpApi: - path: /minglaradmin/update-profile - method: patch - - prepopulateTeammate: - handler: src/modules/minglaradmin/handlers/prepopulateTeammate.handler - memorySize: 384 - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /minglaradmin/prepopulate-Roles - method: get - - inviteTeammate: - handler: src/modules/minglaradmin/handlers/inviteTeammate.handler - memorySize: 384 - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /minglaradmin/invite-teammate - method: post - - getAllHostApplication: - handler: src/modules/minglaradmin/handlers/getAllHostApplication.handler - memorySize: 512 # Higher memory for data-intensive operations - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /minglaradmin/get-all-host-applications-am - method: get - - getAllOnboardingHostApplications: - handler: src/modules/minglaradmin/handlers/getAllOnboardingHosts.handler - memorySize: 512 # Higher memory for data-intensive operations - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /minglaradmin/get-all-host-applications-admin - method: get - - getAllOnboardingHostApplications_New: - handler: src/modules/minglaradmin/handlers/getOnboardingNewApplications.handler - memorySize: 512 # Higher memory for data-intensive operations - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /minglaradmin/get-all-host-applications-admin-new - method: get - - getAllInvitationDetails: - handler: src/modules/minglaradmin/handlers/getAllInvitationDetails.handler - memorySize: 512 - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /minglaradmin/get-all-invitation-details - method: get - - addSuggestion: - handler: src/modules/minglaradmin/handlers/addSuggestion.handler - memorySize: 384 - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /minglaradmin/add-suggestion - method: post - - getAllCoadminAndAMDetails: - handler: src/modules/minglaradmin/handlers/getAllCoadminAndAM.handler - memorySize: 512 - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /minglaradmin/get-all-coadmin-and-am-details - method: get - - getAllInvitedCoadminAndAMDetails: - handler: src/modules/minglaradmin/handlers/getAllInvitedCoadminAndAM.handler - memorySize: 512 - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /minglaradmin/get-all-invited-coadmin-and-am - method: get - - getAllBankAndCurrencyDetails: - handler: src/modules/prepopulate/handlers/getAllBankDetails.handler - memorySize: 384 - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /prepopulate/get-all-bank-currency-details - method: get - - getCityByState: - handler: src/modules/prepopulate/handlers/getCityByState.handler - memorySize: 384 - package: - patterns: - - 'src/modules/prepopulate/handlers/getCityByState.*' - - 'src/modules/prepopulate/services/**' - - 'src/common/**' - - 'common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /prepopulate/get-city-by-state - method: get - - getBranchByBankXid: - handler: src/modules/prepopulate/handlers/getBranchByBank.handler - memorySize: 384 - package: - patterns: - - 'src/modules/prepopulate/handlers/getBranchByBank.*' - - 'src/modules/prepopulate/services/**' - - 'src/common/**' - - 'common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /prepopulate/get-branch-by-bank - method: get - - getAllDocumentCountryStateCityDetails: - handler: src/modules/prepopulate/handlers/getAllDocTypeWithCountryState.handler - memorySize: 512 - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /prepopulate/get-all-doc-country - method: get - - getAllPqqQuesAns: - handler: src/modules/prepopulate/handlers/getAllPQQQuesWithAns.handler - memorySize: 512 - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /prepopulate/get-all-pqq-ques-ans - method: get - - getFrequenciesOfActivity: - handler: src/modules/prepopulate/handlers/getAllFrequencies.handler - memorySize: 384 - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /prepopulate/get-all-Frequencies - method: get - - assignAMToHost: - handler: src/modules/minglaradmin/handlers/assignAM.handler - memorySize: 384 - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /minglaradmin/assign-am-to-host - method: patch - - editAgreementDetails: - handler: src/modules/minglaradmin/handlers/editAgreementDetails.handler - memorySize: 384 - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /minglaradmin/edit-agreement-details - method: patch - - acceptHostApplication: - handler: src/modules/minglaradmin/handlers/acceptHostApplication.handler - memorySize: 384 - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /minglaradmin/accept-host-application - method: patch - - acceptHostApplicationMinglar: - handler: src/modules/minglaradmin/handlers/acceptHostAppMinglar.handler - memorySize: 384 - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /minglaradmin/accept-host-application-minglar - method: patch - - rejectHostApplication: - handler: src/modules/minglaradmin/handlers/rejectHostApplication.handler - memorySize: 384 - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /minglaradmin/reject-host-application - method: patch - - rejectHostApplicationAM: - handler: src/modules/minglaradmin/handlers/rejectHostApplicationAM.handler - memorySize: 384 - package: - patterns: - - 'src/modules/minglaradmin/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - events: - - httpApi: - path: /minglaradmin/reject-host-application-am - method: patch - - # Functions using AWS SDK and S3 - KEEP AS IS with higher memory - addCompanyDetails: - handler: src/modules/host/handlers/addCompanyDetails.handler - memorySize: 512 - timeout: 30 - package: - patterns: - - 'src/modules/host/handlers/addCompanyDetails.*' - - 'src/modules/host/services/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - # Only include specific AWS SDK modules needed for S3 - - 'node_modules/@aws-sdk/client-s3/**' - - 'node_modules/@aws-sdk/s3-request-presigner/**' - - 'node_modules/@aws-sdk/types/**' - - 'node_modules/@aws-sdk/middleware-logger/**' - - 'node_modules/@aws-sdk/util-utf8-node/**' - - 'node_modules/@aws-sdk/util-utf8-browser/**' - - 'node_modules/@smithy/**' - - 'node_modules/tslib/**' - # Remove these large/unnecessary packages: - - 'node_modules/fast-xml-parser/**' # Remove if not used - - 'node_modules/lambda-multipart-parser/**' # You're using busboy directly - - 'node_modules/busboy/**' - # Remove these AWS utility packages (included in main SDK): - - 'node_modules/@aws-crypto/**' - # - 'node_modules/uuid/**' # AWS SDK includes its own - # - 'node_modules/@aws/util-uri-escape/**' - # - 'node_modules/@aws/util-middleware/**' - - 'node_modules/@aws/smithy-client/**' - # - 'node_modules/@aws/lambda-invoke-store/**' - events: - - httpApi: - path: /host/add-company-details - method: patch - - submitPqqAnswer: - handler: src/modules/host/handlers/submitPqqAns.handler - memorySize: 512 - timeout: 30 - package: - patterns: - - 'src/modules/host/handlers/submitPqqAns.*' - - 'src/modules/host/services/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - - 'node_modules/@aws-sdk/**' - - 'node_modules/@smithy/**' - - 'node_modules/tslib/**' - - 'node_modules/fast-xml-parser/**' - - 'node_modules/lambda-multipart-parser/**' - - 'node_modules/busboy/**' - - 'node_modules/@aws-crypto/**' - - 'node_modules/uuid/**' - - 'node_modules/@aws/util-uri-escape/**' - - 'node_modules/@aws/util-middleware/**' - - 'node_modules/@aws/smithy-client/**' - - 'node_modules/@aws/lambda-invoke-store/**' - events: - - httpApi: - path: /host/submit-pqq-ans - method: patch - - submitFinalPqqAnswer: - handler: src/modules/host/handlers/getPQQScore.handler - memorySize: 512 - timeout: 30 - package: - patterns: - - 'src/modules/host/handlers/getPQQScore.*' - - 'src/modules/host/services/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - - 'node_modules/@aws-sdk/**' - - 'node_modules/@smithy/**' - - 'node_modules/tslib/**' - - 'node_modules/fast-xml-parser/**' - - 'node_modules/lambda-multipart-parser/**' - - 'node_modules/busboy/**' - - 'node_modules/@aws-crypto/**' - - 'node_modules/uuid/**' - - 'node_modules/@aws/util-uri-escape/**' - - 'node_modules/@aws/util-middleware/**' - - 'node_modules/@aws/smithy-client/**' - - 'node_modules/@aws/lambda-invoke-store/**' - events: - - httpApi: - path: /host/submit-final-pqq-ans - method: patch - - addPQQSuggestion: - handler: src/modules/minglar/handlers/addPQQSuggestion.handler - memorySize: 384 - package: - patterns: - - 'src/modules/minglaradmin/handlers/addPQQSuggestion.*' - - 'src/modules/minglaradmin/services/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/**' - events: - - httpApi: - path: /minglar/add-Pqq-suggestion - method: post diff --git a/serverless/functions/user.yml b/serverless/functions/user.yml index 5c75753..958d7cc 100644 --- a/serverless/functions/user.yml +++ b/serverless/functions/user.yml @@ -45,3 +45,19 @@ verifyOtpForUser: - httpApi: path: /user/verify-otp method: post + + +setPasscodeForMobile: + handler: src/modules/user/handlers/authentication/setPasscodeForMobile.handler + memorySize: 384 + package: + patterns: + - 'src/modules/user/**' + - ${file(./serverless/patterns/base.yml):pattern1} + - ${file(./serverless/patterns/base.yml):pattern2} + - ${file(./serverless/patterns/base.yml):pattern3} + - ${file(./serverless/patterns/base.yml):pattern4} + events: + - httpApi: + path: /user/set-passcode + method: post \ No newline at end of file diff --git a/src/modules/user/dto/user.dto.ts b/src/modules/user/dto/user.dto.ts index 74776e0..46c26be 100644 --- a/src/modules/user/dto/user.dto.ts +++ b/src/modules/user/dto/user.dto.ts @@ -10,4 +10,14 @@ export class AddPersonalInfoDTO { this.genderName = genderName; this.dateOfBirth = dateOfBirth; } +} + +export class SetPasscodeDTO { + userPasscode: string; + confirmPasscode: string; + + constructor(userPasscode: string, confirmPasscode: string) { + this.userPasscode = userPasscode; + this.confirmPasscode = confirmPasscode; + } } \ No newline at end of file diff --git a/src/modules/user/handlers/authentication/setPasscodeForMobile.ts b/src/modules/user/handlers/authentication/setPasscodeForMobile.ts new file mode 100644 index 0000000..520e8b1 --- /dev/null +++ b/src/modules/user/handlers/authentication/setPasscodeForMobile.ts @@ -0,0 +1,65 @@ +import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda'; +import { prismaClient } from '../../../../common/database/prisma.lambda.service'; +import { verifyUserToken } from '../../../../common/middlewares/jwt/authForUser'; +import { safeHandler } from '../../../../common/utils/handlers/safeHandler'; +import ApiError from '../../../../common/utils/helper/ApiError'; +import { UserService } from '../../services/user.service'; + +const userService = new UserService(prismaClient); + +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 verifyUserToken + const userInfo = await verifyUserToken(token); + const userId = userInfo.id; + + if (Number.isNaN(userId)) { + throw new ApiError(400, 'User id must be a number'); + } + + const user = await userService.getUserById(userId); + if (!user) { + throw new ApiError(404, 'User not found'); + } + + // Parse request body + let body: { userPasscode?: string; }; + + try { + body = event.body ? JSON.parse(event.body) : {}; + } catch (error) { + throw new ApiError(400, 'Invalid JSON in request body'); + } + + const { userPasscode } = body; + + // Validate required fields + if (!userPasscode ) { + throw new ApiError(400, 'userPasscode is required'); + } + + + // Set the passcode + await userService.setUserPasscode(userId, userPasscode); + + return { + statusCode: 200, + headers: { + 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', + }, + body: JSON.stringify({ + success: true, + message: 'Passcode set successfully', + data: null, + }), + }; +}); \ 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 b16d4c3..e3f50c3 100644 --- a/src/modules/user/services/user.service.ts +++ b/src/modules/user/services/user.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; import { PrismaClient, User } from '@prisma/client'; -import { AddPersonalInfoDTO } from '../dto/user.dto'; +import { AddPersonalInfoDTO, SetPasscodeDTO } from '../dto/user.dto'; import ApiError from '@/common/utils/helper/ApiError'; import * as bcrypt from 'bcryptjs'; @Injectable() @@ -77,4 +77,28 @@ export class UserService { return true; } + + async setUserPasscode(userId: number, userPasscode: string): Promise { + // Validate passcode format (6 digits) + if (!userPasscode || userPasscode.length !== 6 || !/^\d{6}$/.test(userPasscode)) { + throw new ApiError(400, 'Passcode must be exactly 6 digits'); + } + + // Hash the passcode + const hashedPasscode = await bcrypt.hash(userPasscode, 10); + + // Update user with passcode + const updatedUser = await this.prisma.user.update({ + where: { id: userId }, + data: { + userPasscode: hashedPasscode, + }, + }); + + if (!updatedUser) { + throw new ApiError(400, 'Failed to set passcode'); + } + + return updatedUser; + } } \ No newline at end of file diff --git a/test-stepper-handler.ts b/test-stepper-handler.ts deleted file mode 100644 index 8084753..0000000 --- a/test-stepper-handler.ts +++ /dev/null @@ -1,122 +0,0 @@ -/** - * Test script for stepper handler - * Run with: npx ts-node test-stepper-handler.ts - */ - -import { PrismaClient } from '@prisma/client'; -import * as jwt from 'jsonwebtoken'; - -const prisma = new PrismaClient(); - -async function testStepperHandler() { - console.log('๐Ÿงช Testing Stepper Handler...\n'); - - try { - // 1. Find a host user with HostHeader data - console.log('๐Ÿ“ Step 1: Finding host user with HostHeader...'); - const hostUser = await prisma.user.findFirst({ - where: { roleXid: 4 }, - include: { - HostHeader: { - select: { - id: true, - stepper: true, - hostRefNumber: true, - companyName: true, - }, - }, - }, - }); - - if (!hostUser) { - console.log('โŒ No host user found (roleXid=4) in database.'); - return; - } - - if (!hostUser.HostHeader || hostUser.HostHeader.length === 0) { - console.log('โš ๏ธ Host user found but no HostHeader records.'); - console.log(` User ID: ${hostUser.id}, Email: ${hostUser.emailAddress}`); - return; - } - - const hostHeader = hostUser.HostHeader[0]; - console.log(`โœ… Found host user and HostHeader\n`); - console.log(` User ID: ${hostUser.id}`); - console.log(` Email: ${hostUser.emailAddress}`); - console.log(` First Name: ${hostUser.firstName}`); - console.log(` Host ID: ${hostHeader.id}`); - console.log(` Company: ${hostHeader.companyName}`); - console.log(` Ref Number: ${hostHeader.hostRefNumber}`); - console.log(` Current Stepper: ${hostHeader.stepper}\n`); - - // 2. Simulate what the handler returns - console.log('๐Ÿ“ Step 2: Simulating handler response...\n'); - - const stepDescriptions: { [key: number]: string } = { - 1: 'Basic Company Information', - 2: 'Company Documents & Verification', - 3: 'Bank & Payment Details', - 4: 'Activities Setup', - 5: 'Pricing & Services', - 6: 'Review & Approval', - 7: 'Active & Live', - }; - - const stepperDescription = - stepDescriptions[hostHeader.stepper] || 'Unknown Step'; - - const response = { - success: true, - message: 'Stepper information retrieved successfully', - data: { - user: { - id: hostUser.id, - firstName: hostUser.firstName, - lastName: hostUser.lastName, - emailAddress: hostUser.emailAddress, - roleXid: hostUser.roleXid, - }, - stepper: { - hostId: hostHeader.id, - currentStep: hostHeader.stepper, - stepperDescription: stepperDescription, - }, - }, - }; - - console.log('โœ… Handler Response:\n'); - console.log(JSON.stringify(response, null, 2)); - - // 3. Verify stepper value is numeric - console.log('\n๐Ÿ“ Step 3: Validation checks...\n'); - - if (typeof hostHeader.stepper !== 'number') { - console.log('โŒ Stepper is not a number'); - return; - } - console.log('โœ… Stepper is numeric:', hostHeader.stepper); - - if (hostHeader.stepper < 1 || hostHeader.stepper > 7) { - console.log( - 'โš ๏ธ Stepper value is out of expected range (1-7):', - hostHeader.stepper - ); - } else { - console.log('โœ… Stepper value in valid range (1-7)'); - } - - if (!stepperDescription.includes('Unknown')) { - console.log('โœ… Stepper description found:', stepperDescription); - } else { - console.log('โš ๏ธ Unknown stepper value'); - } - - console.log('\nโœ… Test passed! Handler is working correctly.'); - } catch (error) { - console.error('โŒ Test error:', error); - } finally { - await prisma.$disconnect(); - } -} - -testStepperHandler();