From 99cbe55a707e15ce4a3cf62b44e01b2bc15a62d1 Mon Sep 17 00:00:00 2001 From: Mayank Mishra Date: Wed, 19 Nov 2025 15:13:30 +0530 Subject: [PATCH] made getall pqq question prepopulate --- serverless.yml | 16 ++++++++ .../handlers/getAllPQQQuesWithAns.ts | 40 +++++++++++++++++++ .../services/prepopulate.service.ts | 20 ++++++++++ 3 files changed, 76 insertions(+) create mode 100644 src/modules/prepopulate/handlers/getAllPQQQuesWithAns.ts diff --git a/serverless.yml b/serverless.yml index 6b37a50..dad67aa 100644 --- a/serverless.yml +++ b/serverless.yml @@ -400,6 +400,22 @@ functions: method: get + getAllPqqQuesAns: + handler: src/modules/prepopulate/handlers/getAllPQQQuesWithAns.handler + package: + patterns: + - "src/modules/minglaradmin/**" + - "common/**" + - "src/common/**" + - "node_modules/@prisma/client/**" + - "node_modules/.prisma/**" + + events: + - httpApi: + path: /prepopulate/get-all-pqq-ques-ans + method: get + + assignAMToHost: handler: src/modules/minglaradmin/handlers/assignAM.handler package: diff --git a/src/modules/prepopulate/handlers/getAllPQQQuesWithAns.ts b/src/modules/prepopulate/handlers/getAllPQQQuesWithAns.ts new file mode 100644 index 0000000..cfee25c --- /dev/null +++ b/src/modules/prepopulate/handlers/getAllPQQQuesWithAns.ts @@ -0,0 +1,40 @@ +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 result = await prePopulateService.getAllPQQQuesAndAns(); + + 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 index 4918e70..0b4e862 100644 --- a/src/modules/prepopulate/services/prepopulate.service.ts +++ b/src/modules/prepopulate/services/prepopulate.service.ts @@ -33,5 +33,25 @@ export class PrePopulateService { }) } + async getAllPQQQuesAndAns() { + return await this.prisma.pQQCategories.findMany({ + where: { isActive: true }, + include: { + pqqsubCategories: { + include: { + questions: { + include: { + PQQAnswers: true + } + } + } + } + }, + orderBy: { displayOrder: 'asc' } + }); + } + + + }