made getall pqq question prepopulate

This commit is contained in:
2025-11-19 15:13:30 +05:30
parent 5e061f33a1
commit 99cbe55a70
3 changed files with 76 additions and 0 deletions

View File

@@ -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:

View File

@@ -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<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.');
}
// 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,
}),
};
});

View File

@@ -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' }
});
}
}