diff --git a/serverless.yml b/serverless.yml index d4bee9a..43491cc 100644 --- a/serverless.yml +++ b/serverless.yml @@ -208,6 +208,22 @@ functions: path: /host/get-pqq-question-details method: get + getLatestPQQQuestionDetails: + 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-latest-pqq-question-details + method: get + getActivityTypes: handler: src/modules/host/handlers/getActivity.handler package: diff --git a/src/modules/host/handlers/getLatestQuestionDetailsPQQ.ts b/src/modules/host/handlers/getLatestQuestionDetailsPQQ.ts new file mode 100644 index 0000000..91376f8 --- /dev/null +++ b/src/modules/host/handlers/getLatestQuestionDetailsPQQ.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: { activity_xid: number }; + + try { + body = event.body ? JSON.parse(event.body) : {}; + } catch (error) { + throw new ApiError(400, 'Invalid JSON in request body'); + } + + const { activity_xid } = body; + + // Fetch user with their HostHeader stepper info + const pqqQuestionDetails = await hostService.getLatestQuestionDetailsPQQ(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 aa0a381..0c92a10 100644 --- a/src/modules/host/services/host.service.ts +++ b/src/modules/host/services/host.service.ts @@ -237,7 +237,7 @@ export class HostService { async getPQQQuestionDetail(question_xid: number, activity_xid: number) { return await this.prisma.activityPQQheader.findFirst({ - where: { activityXid: activity_xid, pqqQuestionXid: question_xid }, + where: { activityXid: activity_xid, pqqQuestionXid: question_xid, isActive: true }, select: { pqqQuestionXid: true, pqqAnswerXid: true, @@ -246,6 +246,14 @@ export class HostService { }) } + async getLatestQuestionDetailsPQQ(activity_xid: number) { + return await this.prisma.activityPQQheader.findFirst({ + where: { activityXid: activity_xid, isActive: true }, + select: { pqqQuestionXid: true, pqqAnswerXid: true }, + orderBy: { id: 'desc' } + }) + } + async addOrUpdateCompanyDetails( user_xid: number, companyData: HostCompanyDetailsInput,