From 0da18b18f71238b4bdd03c77ad7680609fdc5393 Mon Sep 17 00:00:00 2001 From: Mayank Mishra Date: Tue, 16 Dec 2025 12:07:42 +0530 Subject: [PATCH] Add getSuggestionsForAM function and corresponding handler for retrieving suggestions based on host assignments. Update serverless configuration to include new API endpoint. --- serverless/functions/minglaradmin.yml | 17 +++++++ .../hosthub/onboarding/showSuggestionToAM.ts | 44 +++++++++++++++++++ .../minglaradmin/services/minglar.service.ts | 19 ++++++++ 3 files changed, 80 insertions(+) create mode 100644 src/modules/minglaradmin/handlers/hosthub/onboarding/showSuggestionToAM.ts diff --git a/serverless/functions/minglaradmin.yml b/serverless/functions/minglaradmin.yml index c660469..33ed1ba 100644 --- a/serverless/functions/minglaradmin.yml +++ b/serverless/functions/minglaradmin.yml @@ -406,3 +406,20 @@ getAllPQPDetailsForAM: - httpApi: path: /minglaradmin/hosthub/pqp/pqp-details-for-am/{activityXid} method: get + + +getSuggestionsForAM: + handler: src/modules/minglaradmin/handlers/hosthub/pqp/getAllPQPDetailsForAM.handler + memorySize: 384 + package: + patterns: + - 'src/modules/minglaradmin/handlers/hosthub/onboarding/showSuggestionToAM**' + - 'src/modules/minglaradmin/services/**' + - ${file(./serverless/patterns/base.yml):pattern1} + - ${file(./serverless/patterns/base.yml):pattern2} + - ${file(./serverless/patterns/base.yml):pattern3} + - ${file(./serverless/patterns/base.yml):pattern4} + events: + - httpApi: + path: /minglaradmin/hosthub/onboarding/show-suggestion-to-am/{hostXid} + method: get diff --git a/src/modules/minglaradmin/handlers/hosthub/onboarding/showSuggestionToAM.ts b/src/modules/minglaradmin/handlers/hosthub/onboarding/showSuggestionToAM.ts new file mode 100644 index 0000000..7202228 --- /dev/null +++ b/src/modules/minglaradmin/handlers/hosthub/onboarding/showSuggestionToAM.ts @@ -0,0 +1,44 @@ +import { verifyMinglarAdminToken } from '@/common/middlewares/jwt/authForMinglarAdmin'; +import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda'; +import { prismaClient } from '../../../../../common/database/prisma.lambda.service'; +import { safeHandler } from '../../../../../common/utils/handlers/safeHandler'; +import ApiError from '../../../../../common/utils/helper/ApiError'; +import { MinglarService } from '../../../../minglaradmin/services/minglar.service'; + +const minglarService = new MinglarService(prismaClient); + +/** + * Get suggestions handler + * Retrieves suggestions based on user's role and host assignments + */ +export const handler = safeHandler(async ( + event: APIGatewayProxyEvent, + context?: Context +): Promise => { + // Verify authentication token + const token = event.headers['x-auth-token'] || event.headers['X-Auth-Token']; + if (!token) { + throw new ApiError(401, 'This is a protected route. Please provide a valid token.'); + } + + // Verify token and get user info + await verifyMinglarAdminToken(token); + + const hostXid = Number(event.pathParameters?.hostXid) + + // Get suggestions using service + const suggestions = await minglarService.getSuggestionsForAM(hostXid); + + return { + statusCode: 200, + headers: { + 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', + }, + body: JSON.stringify({ + success: true, + message: 'Suggestions retrieved successfully', + data: suggestions, + }), + }; +}); diff --git a/src/modules/minglaradmin/services/minglar.service.ts b/src/modules/minglaradmin/services/minglar.service.ts index 2623f2a..973f12e 100644 --- a/src/modules/minglaradmin/services/minglar.service.ts +++ b/src/modules/minglaradmin/services/minglar.service.ts @@ -1423,6 +1423,25 @@ export class MinglarService { return suggestions; } + async getSuggestionsForAM(hostXid: number) { + const suggestions = await this.prisma.hostSuggestion.findMany({ + where: { hostXid: hostXid, isreviewed: false, isActive: true }, + select: { + id: true, + title: true, + comments: true, + isparent: true, + isreviewed: true, + reviewOn: true, + }, + orderBy: { + id: 'asc', + }, + }); + + return suggestions; + } + async acceptHostApplication(host_xid: number, user_xid: number) { return await this.prisma.$transaction(async (tx) => { await this.prisma.hostHeader.update({