From abe512b0c2284624dedbf1cbdf9e5b2f120dedde Mon Sep 17 00:00:00 2001 From: Mayank Mishra Date: Thu, 27 Nov 2025 19:35:24 +0530 Subject: [PATCH] made updateSuggestionAsReviewed lambda api --- serverless/functions/host.yml | 71 +++++++++++-------- .../OnBoarding/updateSuggestionAsReviewed.ts | 51 +++++++++++++ src/modules/host/services/host.service.ts | 16 +++++ .../minglaradmin/services/minglar.service.ts | 28 +++++++- 4 files changed, 135 insertions(+), 31 deletions(-) create mode 100644 src/modules/host/handlers/Activity_Hub/OnBoarding/updateSuggestionAsReviewed.ts diff --git a/serverless/functions/host.yml b/serverless/functions/host.yml index acc9c61..f7dbe3d 100644 --- a/serverless/functions/host.yml +++ b/serverless/functions/host.yml @@ -234,34 +234,34 @@ submitCompanyDetails: timeout: 30 package: patterns: - - 'src/modules/host/handlers/addCompanyDetails.*' - - 'src/modules/host/services/**' - - 'src/common/**' - - 'node_modules/@prisma/client/**' - - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' - # Only include specific AWS SDK modules needed for S3 - - 'node_modules/@aws-sdk/client-s3/**' - - 'node_modules/@aws-sdk/s3-request-presigner/**' - - 'node_modules/@aws-sdk/types/**' - - 'node_modules/@aws-sdk/middleware-logger/**' - - 'node_modules/@aws-sdk/util-utf8-node/**' - - 'node_modules/@aws-sdk/util-utf8-browser/**' - - 'node_modules/@smithy/**' - - 'node_modules/tslib/**' - # Remove these large/unnecessary packages: - - 'node_modules/fast-xml-parser/**' # Remove if not used - - 'node_modules/lambda-multipart-parser/**' # You're using busboy directly - - 'node_modules/busboy/**' - # Remove these AWS utility packages (included in main SDK): - - 'node_modules/@aws-crypto/**' - # - 'node_modules/uuid/**' # AWS SDK includes its own - # - 'node_modules/@aws/util-uri-escape/**' - # - 'node_modules/@aws/util-middleware/**' - - 'node_modules/@aws/smithy-client/**' - # - 'node_modules/@aws/lambda-invoke-store/**' + - 'src/modules/host/handlers/addCompanyDetails.*' + - 'src/modules/host/services/**' + - 'src/common/**' + - 'node_modules/@prisma/client/**' + - 'node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node' + # Only include specific AWS SDK modules needed for S3 + - 'node_modules/@aws-sdk/client-s3/**' + - 'node_modules/@aws-sdk/s3-request-presigner/**' + - 'node_modules/@aws-sdk/types/**' + - 'node_modules/@aws-sdk/middleware-logger/**' + - 'node_modules/@aws-sdk/util-utf8-node/**' + - 'node_modules/@aws-sdk/util-utf8-browser/**' + - 'node_modules/@smithy/**' + - 'node_modules/tslib/**' + # Remove these large/unnecessary packages: + - 'node_modules/fast-xml-parser/**' # Remove if not used + - 'node_modules/lambda-multipart-parser/**' # You're using busboy directly + - 'node_modules/busboy/**' + # Remove these AWS utility packages (included in main SDK): + - 'node_modules/@aws-crypto/**' + # - 'node_modules/uuid/**' # AWS SDK includes its own + # - 'node_modules/@aws/util-uri-escape/**' + # - 'node_modules/@aws/util-middleware/**' + - 'node_modules/@aws/smithy-client/**' + # - 'node_modules/@aws/lambda-invoke-store/**' events: - httpApi: - path: /host/Host_Admin/onboarding/add-company-details + path: /host/Host_Admin/onboarding/add-company-details method: patch submitPQQ_Answer: @@ -295,7 +295,7 @@ updatePQQ_LastAnswer: - httpApi: path: /host/Activity_Hub/OnBoarding/submit-final-pqq-answer method: post - + getAllPQQwithSubmittedAns: handler: src/modules/host/handlers/Activity_Hub/OnBoarding/getAllPQQwithSubmittedAns.handler memorySize: 512 @@ -309,4 +309,19 @@ getAllPQQwithSubmittedAns: events: - httpApi: path: /host/Activity_Hub/OnBoarding/get-all-pqq-ques-submited-ans - method: get \ No newline at end of file + method: get + +updateSuggestionAsReviewed: + handler: src/modules/host/handlers/Activity_Hub/OnBoarding/updateSuggestionAsReviewed.handler + memorySize: 512 + package: + patterns: + - 'src/modules/host/handlers/Activity_Hub/OnBoarding/**' + - ${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: /host/Activity_Hub/OnBoarding/update-suggestion-reviewed + method: patch diff --git a/src/modules/host/handlers/Activity_Hub/OnBoarding/updateSuggestionAsReviewed.ts b/src/modules/host/handlers/Activity_Hub/OnBoarding/updateSuggestionAsReviewed.ts new file mode 100644 index 0000000..1dd2df1 --- /dev/null +++ b/src/modules/host/handlers/Activity_Hub/OnBoarding/updateSuggestionAsReviewed.ts @@ -0,0 +1,51 @@ +import { verifyHostToken } from '@/common/middlewares/jwt/authForHost'; +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 { HostService } from '../../../services/host.service'; + +const prismaService = new PrismaService(); +const hostService = new HostService(prismaService); + +export const handler = safeHandler(async ( + event: APIGatewayProxyEvent, + context?: Context +): Promise => { + 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.'); + + const userInfo = await verifyHostToken(token); + + let body: any = {}; + try { + body = event.body ? JSON.parse(event.body) : {}; + } catch (err) { + throw new ApiError(400, 'Invalid JSON in request body'); + } + + const { activityPqqHeaderXid, activityPQQSuggestionId } = body; + + if (!activityPqqHeaderXid) { + throw new ApiError(400, 'activityPqqHeaderXid is required'); + } + + await hostService.markPQQSuggestionReviewed( + userInfo.id, + Number(activityPqqHeaderXid), + Number(activityPQQSuggestionId) + ); + + return { + statusCode: 201, + headers: { + 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', + }, + body: JSON.stringify({ + success: true, + message: 'Suggestion reviewed successfully', + data: null, + }), + }; +}); diff --git a/src/modules/host/services/host.service.ts b/src/modules/host/services/host.service.ts index 4a947af..be0d416 100644 --- a/src/modules/host/services/host.service.ts +++ b/src/modules/host/services/host.service.ts @@ -936,6 +936,22 @@ export class HostService { }); } + async markPQQSuggestionReviewed(user_xid: number, activityPqqHeaderXid: number, activityPQQSuggestionId: number) { + return await this.prisma.activityPQQSuggestions.update({ + where: { + id: activityPQQSuggestionId, + activityPqqHeaderXid: activityPqqHeaderXid, + isActive: true, + isReviewed: false + }, + data: { + isReviewed: true, + reviewedByXid: user_xid, + reviewedOn: new Date() + } + }) + } + async getAllPQQQuesAndSubmittedAns() { return await this.prisma.activityPQQheader.findMany({ where: { isActive: true }, diff --git a/src/modules/minglaradmin/services/minglar.service.ts b/src/modules/minglaradmin/services/minglar.service.ts index d4f325b..cf38303 100644 --- a/src/modules/minglaradmin/services/minglar.service.ts +++ b/src/modules/minglaradmin/services/minglar.service.ts @@ -1193,9 +1193,31 @@ export class MinglarService { return this.prisma.user.findUnique({ where: { id: id, isActive: true, userStatus: USER_STATUS.ACTIVE }, include: { - userAddressDetails: true, - userDocuments: true, - userRevenues: true, + userAddressDetails: { + select: { + id: true, + userXid: true, + address1: true, + address2: true, + locationAddress: true, + locationLat: true, + locationLong: true, + locationName: true, + } + }, + userDocuments: { + select: { + id: true, + fileName: true, + } + }, + userRevenues: { + select: { + id: true, + is_fixed_salary: true, + per_value: true + } + }, }, }); }