Add new endpoint to retrieve the latest PQQ question details and implement corresponding handler. Update HostService to include method for fetching latest question details with active status filtering.
This commit is contained in:
@@ -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:
|
||||
|
||||
50
src/modules/host/handlers/getLatestQuestionDetailsPQQ.ts
Normal file
50
src/modules/host/handlers/getLatestQuestionDetailsPQQ.ts
Normal file
@@ -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<APIGatewayProxyResult> => {
|
||||
// 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,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user