From 1377e0ba9a04268cf14130881925faea00ab919f Mon Sep 17 00:00:00 2001 From: Mayank Mishra Date: Sat, 22 Nov 2025 19:30:16 +0530 Subject: [PATCH] made the getbyid pqq question details api --- serverless.yml | 16 ++++++++ src/modules/host/handlers/getByIdPQQ.ts | 50 +++++++++++++++++++++++ src/modules/host/services/host.service.ts | 11 +++++ 3 files changed, 77 insertions(+) create mode 100644 src/modules/host/handlers/getByIdPQQ.ts diff --git a/serverless.yml b/serverless.yml index b37fc6d..1f80bcb 100644 --- a/serverless.yml +++ b/serverless.yml @@ -192,6 +192,22 @@ functions: path: /host/getById method: get + getPQQQuestionDetailsById: + handler: src/modules/host/handlers/getByIdPQQ.handler + package: + patterns: + - 'src/modules/host/handlers/getByIdPQQ.*' + - 'src/modules/host/services/**' + - 'common/**' + - 'src/common/**' + - 'node_modules/@prisma/client/**' + - 'node_modules/.prisma/**' + + events: + - httpApi: + path: /host/get-pqq-question-details + method: get + acceptMinglarAgreement: handler: src/modules/host/handlers/acceptAgreement.handler package: diff --git a/src/modules/host/handlers/getByIdPQQ.ts b/src/modules/host/handlers/getByIdPQQ.ts new file mode 100644 index 0000000..23c5db9 --- /dev/null +++ b/src/modules/host/handlers/getByIdPQQ.ts @@ -0,0 +1,50 @@ +import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda'; +import { safeHandler } from '../../../common/utils/handlers/safeHandler'; +import { PrismaService } from '../../../common/database/prisma.service'; +import ApiError from '../../../common/utils/helper/ApiError'; +import { verifyHostToken } from '../../../common/middlewares/jwt/authForHost'; +import { HostService } from '../services/host.service'; + +const prismaService = new PrismaService(); +const hostService = new HostService(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.'); + } + + // Verify token and get user info + const userInfo = await verifyHostToken(token); + const userId = Number(userInfo.id); + + let body: { question_xid: number, activity_xid: number }; + + try { + body = event.body ? JSON.parse(event.body) : {}; + } catch (error) { + throw new ApiError(400, 'Invalid JSON in request body'); + } + + const { question_xid, activity_xid } = body; + + // Fetch user with their HostHeader stepper info + const pqqQuestionDetails = await hostService.getPQQQuestionDetail(question_xid, activity_xid); + + return { + statusCode: 200, + headers: { + 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', + }, + body: JSON.stringify({ + success: true, + message: 'Stepper information retrieved successfully', + data: pqqQuestionDetails, + }), + }; +}); + diff --git a/src/modules/host/services/host.service.ts b/src/modules/host/services/host.service.ts index 3456ccd..306abec 100644 --- a/src/modules/host/services/host.service.ts +++ b/src/modules/host/services/host.service.ts @@ -235,6 +235,17 @@ export class HostService { }) } + async getPQQQuestionDetail(question_xid: number, activity_xid: number) { + return await this.prisma.activityPQQheader.findFirst({ + where: { activityXid: activity_xid, pqqQuestionXid: question_xid }, + select: { + pqqQuestionXid: true, + pqqAnswerXid: true, + ActivityPQQSupportings: true + } + }) + } + async addOrUpdateCompanyDetails( user_xid: number, companyData: HostCompanyDetailsInput,