made getall pqq question prepopulate
This commit is contained in:
@@ -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:
|
||||
|
||||
40
src/modules/prepopulate/handlers/getAllPQQQuesWithAns.ts
Normal file
40
src/modules/prepopulate/handlers/getAllPQQQuesWithAns.ts
Normal 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,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -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' }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user