From 4f9955d9f46be5634ecee0421307be84ff50439a Mon Sep 17 00:00:00 2001 From: paritosh18 Date: Wed, 24 Dec 2025 16:11:22 +0530 Subject: [PATCH] get and create suggestion api --- serverless/functions/host.yml | 16 + serverless/functions/minglaradmin.yml | 16 + .../onboarding/getAllActvitySuggestion.ts | 54 ++++ .../hosthub/hosts/addActivtiySuggestion.ts | 89 ++++++ .../minglaradmin/services/minglar.service.ts | 295 +++++++++++------- 5 files changed, 350 insertions(+), 120 deletions(-) create mode 100644 src/modules/host/handlers/Host_Admin/onboarding/getAllActvitySuggestion.ts create mode 100644 src/modules/minglaradmin/handlers/hosthub/hosts/addActivtiySuggestion.ts diff --git a/serverless/functions/host.yml b/serverless/functions/host.yml index 4b27789..6874df0 100644 --- a/serverless/functions/host.yml +++ b/serverless/functions/host.yml @@ -210,6 +210,22 @@ showSuggestion: path: /host/get-suggestion method: get +getAllActivitySuggestion: + handler: src/modules/host/handlers/Host_Admin/onboarding/getAllActvitySuggestion.handler + memorySize: 384 + package: + patterns: + - 'src/modules/host/handlers/Host_Admin/onboarding/getAllActvitySuggestion.handler.*' + - 'src/modules/host/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: /host/get-Activity-suggestion + method: get + getAllHostActivity: handler: src/modules/host/handlers/Activity_Hub/OnBoarding/getAllHostActivity.handler memorySize: 384 diff --git a/serverless/functions/minglaradmin.yml b/serverless/functions/minglaradmin.yml index c718cd8..b945d82 100644 --- a/serverless/functions/minglaradmin.yml +++ b/serverless/functions/minglaradmin.yml @@ -391,6 +391,22 @@ addPQQSuggestion: path: /minglaradmin/hosthub/hosts/add-Pqq-suggestion method: post +addActivitySuggestion: + handler: src/modules/minglaradmin/handlers/hosthub/hosts/addActivtiySuggestion.handler + memorySize: 384 + package: + patterns: + - 'src/modules/minglaradmin/handlers/hosthub/hosts/**' + - '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/hosts/add-Activity-suggestion + method: post + getAllPQPDetailsForAM: handler: src/modules/minglaradmin/handlers/hosthub/pqp/getAllPQPDetailsForAM.handler memorySize: 384 diff --git a/src/modules/host/handlers/Host_Admin/onboarding/getAllActvitySuggestion.ts b/src/modules/host/handlers/Host_Admin/onboarding/getAllActvitySuggestion.ts new file mode 100644 index 0000000..fb51e95 --- /dev/null +++ b/src/modules/host/handlers/Host_Admin/onboarding/getAllActvitySuggestion.ts @@ -0,0 +1,54 @@ +import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda'; +import { safeHandler } from '../../../../../common/utils/handlers/safeHandler'; +import { prismaClient } from '../../../../../common/database/prisma.lambda.service'; +import { MinglarService } from '../../../../minglaradmin/services/minglar.service'; +import ApiError from '../../../../../common/utils/helper/ApiError'; +import { verifyMinglarAdminHostToken } from '../../../../../common/middlewares/jwt/authForMinglarAdminHost'; + +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 extract user info + const userInfo = await verifyMinglarAdminHostToken(token); + + // ✅ Extract activityXid from query parameters + const activityXidParam = event.queryStringParameters?.activityXid; + if (!activityXidParam) { + throw new ApiError(400, 'Missing required query parameter: activityXid'); + } + + const activityXid = Number(activityXidParam); + if (isNaN(activityXid) || activityXid <= 0) { + throw new ApiError(400, 'Invalid activityXid provided. Must be a positive number.'); + } + + // ✅ Fetch suggestions from the service + const suggestions = await minglarService.getHostSuggestionsForActivity(activityXid); + + // ✅ Return response + 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/handlers/hosthub/hosts/addActivtiySuggestion.ts b/src/modules/minglaradmin/handlers/hosthub/hosts/addActivtiySuggestion.ts new file mode 100644 index 0000000..209a19c --- /dev/null +++ b/src/modules/minglaradmin/handlers/hosthub/hosts/addActivtiySuggestion.ts @@ -0,0 +1,89 @@ +import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda'; +import { prismaClient } from '../../../../../common/database/prisma.lambda.service'; +import { verifyMinglarAdminToken } from '../../../../../common/middlewares/jwt/authForMinglarAdmin'; +import { safeHandler } from '../../../../../common/utils/handlers/safeHandler'; +import ApiError from '../../../../../common/utils/helper/ApiError'; +import { MinglarService } from '../../../services/minglar.service'; +// import { HOST_SUGGESTION_TITLES } from '../../../../../common/utils/constants/minglar.constant'; + +const minglarService = new MinglarService(prismaClient); + +interface AddSuggestionBody { + title: string; + comments: string; + activity_xid:number +} + +/** + * Add suggestion handler for host applications + * Allows Minglar Admin, Co_Admin, and Account Manager to add suggestions + * Types: Setup Profile, Review Account, Add Payment Details, Agreement + */ +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 + const userInfo = await verifyMinglarAdminToken(token); + + // Get user details + const user = await prismaClient.user.findUnique({ + where: { id: userInfo.id }, + select: { id: true, roleXid: true } + }); + + if (!user) { + throw new ApiError(404, 'User not found'); + } + + // Parse request body + let body: AddSuggestionBody; + + try { + body = event.body ? JSON.parse(event.body) : {}; + } catch (error) { + throw new ApiError(400, 'Invalid JSON in request body'); + } + + const { title, comments , activity_xid} = body; + + if (!title) { + throw new ApiError(400, 'Title is required'); + } + + if (!comments) { + throw new ApiError(400, 'Comments are required'); + } + + if(!activity_xid){ + throw new ApiError(400 , "Activity Pqq HeaderXid Required"); + } + + // Validate title is one of the allowed types + // const allowedTitles = Object.values(HOST_SUGGESTION_TITLES); + // if (!allowedTitles.includes(title)) { + // throw new ApiError(400, `Invalid title. Allowed values: ${allowedTitles.join(', ')}`); + // } + + // Add suggestion using service + await minglarService.addActivtiySuggestion(title, comments, activity_xid,user.id); + + return { + statusCode: 200, + headers: { + 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', + }, + body: JSON.stringify({ + success: true, + message: 'Suggestion added successfully', + data: null, + }), + }; +}); diff --git a/src/modules/minglaradmin/services/minglar.service.ts b/src/modules/minglaradmin/services/minglar.service.ts index 6608294..088097a 100644 --- a/src/modules/minglaradmin/services/minglar.service.ts +++ b/src/modules/minglaradmin/services/minglar.service.ts @@ -35,7 +35,7 @@ const bucket = config.aws.bucketName; @Injectable() export class MinglarService { - constructor(private prisma: PrismaService | PrismaClient) { } + constructor(private prisma: PrismaService | PrismaClient) {} async createPassword(user_xid: number, password: string): Promise { // Find user by id @@ -138,15 +138,15 @@ export class MinglarService { async getHostXidByActivityId(activityId: number) { const activityDetails = await this.prisma.activities.findFirst({ - where: { id: activityId } - }) + where: { id: activityId }, + }); return activityDetails.hostXid; } async getUserDetails(id: number) { const hostDetail = await this.prisma.hostHeader.findFirst({ - where: { id: id } - }) + where: { id: id }, + }); const userDetails = await this.prisma.user.findUnique({ where: { id: hostDetail.userXid }, }); @@ -217,7 +217,7 @@ export class MinglarService { userStatus: true, profileImage: true, userPassword: true, - } + }, }); if (!existingUser) { @@ -241,8 +241,8 @@ export class MinglarService { } if (existingUser?.profileImage) { - const key = existingUser.profileImage.startsWith("http") - ? existingUser.profileImage.split(".com/")[1] + const key = existingUser.profileImage.startsWith('http') + ? existingUser.profileImage.split('.com/')[1] : existingUser.profileImage; existingUser.profileImage = await getPresignedUrl(bucket, key); @@ -269,7 +269,11 @@ export class MinglarService { }); } - async getAllHostActivityForMinglar(search?: string, hostXid?: number, paginationOptions?: { page: number; limit: number; skip: number }) { + async getAllHostActivityForMinglar( + search?: string, + hostXid?: number, + paginationOptions?: { page: number; limit: number; skip: number }, + ) { const whereClause: any = { isActive: true, activityInternalStatus: { notIn: [ACTIVITY_INTERNAL_STATUS.DRAFT_PQ] }, @@ -285,8 +289,8 @@ export class MinglarService { { activityTitle: { contains: term, mode: 'insensitive' } }, { activityType: { - activityTypeName: { contains: term, mode: 'insensitive' } - } + activityTypeName: { contains: term, mode: 'insensitive' }, + }, }, ]; } @@ -309,10 +313,10 @@ export class MinglarService { companyName: true, user: { select: { - userRefNumber: true - } - } - } + userRefNumber: true, + }, + }, + }, }, ActivityAmDetails: { select: { @@ -335,10 +339,10 @@ export class MinglarService { interests: { select: { id: true, - interestName: true - } - } - } + interestName: true, + }, + }, + }, }, }, skip: paginationOptions?.skip || 0, @@ -354,8 +358,8 @@ export class MinglarService { const am = activity.ActivityAmDetails?.[0]?.accountManager; if (am?.profileImage) { - const key = am.profileImage.startsWith("http") - ? am.profileImage.split(".com/")[1] + const key = am.profileImage.startsWith('http') + ? am.profileImage.split('.com/')[1] : am.profileImage; const presignedUrl = await getPresignedUrl(bucket, key); @@ -367,15 +371,16 @@ export class MinglarService { } } - const { paginationService } = require('@/common/utils/pagination/pagination.service'); + const { + paginationService, + } = require('@/common/utils/pagination/pagination.service'); return paginationService.createPaginatedResponse( hostActivities, totalCount, - paginationOptions || { page: 1, limit: 10, skip: 0 } + paginationOptions || { page: 1, limit: 10, skip: 0 }, ); } - async createUserRevenue( userXid: number, isFixedSalary: boolean, @@ -439,7 +444,7 @@ export class MinglarService { emailAddress: emailAddress, roleXid: roleXid, userStatus: USER_STATUS.INVITED, - userRefNumber: referenceNumber + userRefNumber: referenceNumber, }, }); @@ -488,7 +493,11 @@ export class MinglarService { cityXid?: number; pinCode?: string; }, - documents: Array<{ fileName: string; filePath: string, documentTypeName?: string }>, + documents: Array<{ + fileName: string; + filePath: string; + documentTypeName?: string; + }>, ) { try { return await this.prisma.$transaction(async (tx) => { @@ -736,7 +745,7 @@ export class MinglarService { userStatus?: string, paginationOptions?: PaginationOptions, roleFilter?: string, - applicationStatus?: string + applicationStatus?: string, ) { const filters: any = { isActive: true, @@ -807,7 +816,8 @@ export class MinglarService { /** USER STATUS FILTER **/ if ( userStatus && - userStatus.trim().toLowerCase() === MINGLAR_STATUS_DISPLAY.NEW.toLowerCase() + userStatus.trim().toLowerCase() === + MINGLAR_STATUS_DISPLAY.NEW.toLowerCase() ) { filters.adminStatusInternal = MINGLAR_STATUS_INTERNAL.ADMIN_TO_REVIEW; } @@ -831,7 +841,6 @@ export class MinglarService { }, }; - if (applicationStatus?.trim()) { const key = applicationStatus.trim(); const statusObj = APPLICATION_STATUS_MAP[key]; @@ -842,7 +851,6 @@ export class MinglarService { } } - /** ROLE-BASED FILTER **/ if (userRoleXid === ROLE.CO_ADMIN || userRoleXid === ROLE.ACCOUNT_MANAGER) { filters.accountManagerXid = userId; @@ -874,7 +882,7 @@ export class MinglarService { emailAddress: true, mobileNumber: true, userRefNumber: true, - profileImage: true + profileImage: true, }, }, accountManager: { @@ -885,11 +893,11 @@ export class MinglarService { emailAddress: true, mobileNumber: true, roleXid: true, - profileImage: true + profileImage: true, }, }, }, - orderBy: { createdAt: "desc" }, + orderBy: { createdAt: 'desc' }, skip: paginationOptions?.skip || 0, take: paginationOptions?.limit || 10, }); @@ -898,8 +906,8 @@ export class MinglarService { const am = user.accountManager; if (am?.profileImage) { - const key = am.profileImage.startsWith("http") - ? am.profileImage.split(".com/")[1] + const key = am.profileImage.startsWith('http') + ? am.profileImage.split('.com/')[1] : am.profileImage; am.profileImage = await getPresignedUrl(bucket, key); @@ -925,7 +933,6 @@ export class MinglarService { return { data: transformedData, totalCount }; } - async getAllOnboardingHostApplications( paginationOptions?: PaginationOptions, search?: string, @@ -1019,7 +1026,6 @@ export class MinglarService { take: paginationOptions?.limit ?? undefined, }); - /** --------------------------------- * Add presigned URL for AM profile * --------------------------------- */ @@ -1027,8 +1033,8 @@ export class MinglarService { const am = host.accountManager; if (am?.profileImage) { - const key = am.profileImage.startsWith("http") - ? am.profileImage.split(".com/")[1] + const key = am.profileImage.startsWith('http') + ? am.profileImage.split('.com/')[1] : am.profileImage; am.profileImage = await getPresignedUrl(bucket, key); @@ -1151,7 +1157,6 @@ export class MinglarService { take: paginationOptions?.limit ?? 10, }); - /** --------------------------------- * Add presigned URL for AM profile * --------------------------------- */ @@ -1177,13 +1182,15 @@ export class MinglarService { // Build search filter if search term is provided const searchFilter = search ? { - OR: [ - { email: { contains: search, mode: 'insensitive' as const } }, - { firstName: { contains: search, mode: 'insensitive' as const } }, - { lastName: { contains: search, mode: 'insensitive' as const } }, - { userRefNumber: { contains: search, mode: 'insensitive' as const } }, - ], - } + OR: [ + { email: { contains: search, mode: 'insensitive' as const } }, + { firstName: { contains: search, mode: 'insensitive' as const } }, + { lastName: { contains: search, mode: 'insensitive' as const } }, + { + userRefNumber: { contains: search, mode: 'insensitive' as const }, + }, + ], + } : {}; // 1. Fetch all required users (Admin, Co-Admin, AM) @@ -1439,6 +1446,37 @@ export class MinglarService { return true; } + async addActivtiySuggestion( + title: string, + comments: string, + activity_xid: number, + reviewedByXid: number, + ) { + // Check if host exists + const ActivityHeader = await this.prisma.activities.findUnique({ + where: { id: activity_xid, isActive: true }, + select: { id: true }, + }); + + if (!ActivityHeader) { + throw new ApiError(404, 'Host not found'); + } + + await this.prisma.activitySuggestions.create({ + data: { + title: title, + comments: comments, + isReviewed: false, + reviewedOn: new Date(), + isActive: true, + activityXid: activity_xid, + reviewedByXid: reviewedByXid, + }, + }); + + return true; + } + async getHostSuggestions(userId: number) { const hostDetail = await this.prisma.hostHeader.findFirst({ where: { userXid: userId, isActive: true }, @@ -1462,6 +1500,24 @@ export class MinglarService { return suggestions; } + async getHostSuggestionsForActivity(actvityXid: number) { + const suggestions = await this.prisma.activitySuggestions.findMany({ + where: { activityXid: actvityXid, isReviewed: false, isActive: true }, + select: { + id: true, + title: true, + comments: true, + isReviewed: true, + reviewedOn: true, + }, + orderBy: { + id: 'asc', + }, + }); + + return suggestions; + } + async getSuggestionsForAM(hostXid: number) { const suggestions = await this.prisma.hostSuggestion.findMany({ where: { hostXid: hostXid, isreviewed: false, isActive: true }, @@ -1519,7 +1575,8 @@ export class MinglarService { amountPerBooking: number, durationFrequency: string, payoutDurationNum: number, - payoutDurationFrequency: string,) { + payoutDurationFrequency: string, + ) { return await this.prisma.$transaction(async (tx) => { await this.prisma.hostHeader.update({ where: { @@ -1662,48 +1719,46 @@ export class MinglarService { country: { select: { id: true, - countryName: true - } + countryName: true, + }, }, cities: { select: { id: true, cityName: true, - } + }, }, states: { select: { id: true, - stateName: true - } - } - } + stateName: true, + }, + }, + }, }, userDocuments: { select: { id: true, fileName: true, - } + }, }, userRevenues: { select: { id: true, is_fixed_salary: true, - per_value: true - } + per_value: true, + }, }, }, }); - if (user.userDocuments?.length) { for (const media of user.userDocuments) { - if (!media.fileName) continue; // Extract S3 key if URL or keep raw key - const key = media.fileName.startsWith("http") - ? media.fileName.split(".com/")[1] + const key = media.fileName.startsWith('http') + ? media.fileName.split('.com/')[1] : media.fileName; media.fileName = await getPresignedUrl(bucket, key); @@ -1723,7 +1778,7 @@ export class MinglarService { async getBasicUserDetails(user_xid) { return await this.prisma.user.findFirst({ where: { - id: user_xid + id: user_xid, }, select: { id: true, @@ -1734,8 +1789,8 @@ export class MinglarService { isProfileUpdated: true, roleXid: true, role: true, - } - }) + }, + }); } async rejectPQQbyAM(activityId: number, user_xid: number) { @@ -1743,15 +1798,15 @@ export class MinglarService { await tx.activities.update({ where: { id: activityId, - isActive: true + isActive: true, }, data: { activityInternalStatus: ACTIVITY_INTERNAL_STATUS.PQ_TO_UPDATE, activityDisplayStatus: ACTIVITY_DISPLAY_STATUS.ENHANCING, amInternalStatus: ACTIVITY_AM_INTERNAL_STATUS.PQ_REJECTED, - amDisplayStatus: ACTIVITY_AM_DISPLAY_STATUS.ENHANCING - } - }) + amDisplayStatus: ACTIVITY_AM_DISPLAY_STATUS.ENHANCING, + }, + }); await tx.activityTrack.create({ data: { @@ -1760,10 +1815,10 @@ export class MinglarService { trackStatus: ACTIVITY_TRACK_STATUS.REJECTED_BY_AM, updatedByXid: user_xid, updatedByRole: ROLE_NAME.ACCOUNT_MANAGER, - updatedOn: new Date() - } - }) - }) + updatedOn: new Date(), + }, + }); + }); } async acceptPQByAM(activityId: number, user_xid: number) { @@ -1771,15 +1826,15 @@ export class MinglarService { await tx.activities.update({ where: { id: activityId, - isActive: true + isActive: true, }, data: { activityInternalStatus: ACTIVITY_INTERNAL_STATUS.PQ_APPROVED, activityDisplayStatus: ACTIVITY_DISPLAY_STATUS.PQ_APPROVED, amInternalStatus: ACTIVITY_AM_INTERNAL_STATUS.PQ_APPROVED, - amDisplayStatus: ACTIVITY_AM_DISPLAY_STATUS.PQ_APPROVED - } - }) + amDisplayStatus: ACTIVITY_AM_DISPLAY_STATUS.PQ_APPROVED, + }, + }); await tx.activityTrack.create({ data: { @@ -1788,10 +1843,10 @@ export class MinglarService { trackStatus: ACTIVITY_TRACK_STATUS.ACCEPTED_BY_AM, updatedByXid: user_xid, updatedByRole: ROLE_NAME.ACCOUNT_MANAGER, - updatedOn: new Date() - } - }) - }) + updatedOn: new Date(), + }, + }); + }); } async getHostDetailsById(host_xid) { @@ -1812,26 +1867,26 @@ export class MinglarService { filePath: true, documentName: true, documentTypeXid: true, - documentType: true - } + documentType: true, + }, }, cities: { select: { id: true, cityName: true, - } + }, }, countries: { select: { id: true, - countryName: true - } + countryName: true, + }, }, states: { select: { id: true, - stateName: true - } + stateName: true, + }, }, companyTypes: { select: { @@ -1839,7 +1894,7 @@ export class MinglarService { companyTypeName: true, }, }, - } + }, }, HostBankDetails: true, HostDocuments: { @@ -1857,7 +1912,7 @@ export class MinglarService { profileImage: true, userStatus: true, userRefNumber: true, - } + }, }, HostSuggestion: true, HostTrack: true, @@ -1868,9 +1923,7 @@ export class MinglarService { }, }); - if (host.HostDocuments?.length) { - for (const doc of host.HostDocuments) { if (doc.filePath) { const filePath = doc.filePath; @@ -1894,8 +1947,8 @@ export class MinglarService { } if (host.user.profileImage) { - const key = host.user.profileImage.startsWith("http") - ? host.user.profileImage.split(".com/")[1] + const key = host.user.profileImage.startsWith('http') + ? host.user.profileImage.split('.com/')[1] : host.user.profileImage; host.user.profileImage = await getPresignedUrl(bucket, key); @@ -1906,8 +1959,8 @@ export class MinglarService { // Parent company logo if (parent.logoPath) { - const key = parent.logoPath.startsWith("http") - ? parent.logoPath.split(".com/")[1] + const key = parent.logoPath.startsWith('http') + ? parent.logoPath.split('.com/')[1] : parent.logoPath; parent.logoPath = await getPresignedUrl(bucket, key); @@ -1917,8 +1970,8 @@ export class MinglarService { if (parent.HostParenetDocuments?.length) { for (const doc of parent.HostParenetDocuments) { if (doc.filePath) { - const key = doc.filePath.startsWith("http") - ? doc.filePath.split(".com/")[1] + const key = doc.filePath.startsWith('http') + ? doc.filePath.split('.com/')[1] : doc.filePath; (doc as any).presignedUrl = await getPresignedUrl(bucket, key); @@ -1955,10 +2008,10 @@ export class MinglarService { select: { id: true, categoryName: true, - displayOrder: true - } - } - } + displayOrder: true, + }, + }, + }, }, // 🔥 ALL ANSWER OPTIONS FOR THIS QUESTION @@ -1968,11 +2021,11 @@ export class MinglarService { id: true, answerName: true, answerPoints: true, - displayOrder: true + displayOrder: true, }, - orderBy: { displayOrder: "asc" } - } - } + orderBy: { displayOrder: 'asc' }, + }, + }, }, ActivityPQQSuggestions: { where: { isActive: true }, @@ -1980,19 +2033,19 @@ export class MinglarService { id: true, title: true, comments: true, - activityPqqHeaderXid: true - } + activityPqqHeaderXid: true, + }, }, ActivityPQQSupportings: { where: { isActive: true }, select: { id: true, mediaType: true, - mediaFileName: true - } + mediaFileName: true, + }, }, }, - orderBy: { id: "asc" } + orderBy: { id: 'asc' }, }); // ---------- GROUPING START ---------- @@ -2010,7 +2063,7 @@ export class MinglarService { categoryName: cat.categoryName, displayOrder: cat.displayOrder, activityPqqHeaderId: item.id, - pqqsubCategories: [] + pqqsubCategories: [], }; } else if (!grouped[cat.id].activityPqqHeaderId) { // Ensure header id is present at category level @@ -2025,7 +2078,7 @@ export class MinglarService { id: sub.id, subCategoryName: sub.subCategoryName, displayOrder: sub.displayOrder, - questions: [] + questions: [], }; category.pqqsubCategories.push(subCat); } @@ -2040,16 +2093,19 @@ export class MinglarService { displayOrder: q.displayOrder, allAnswerOptions: q.PQQAnswers || [], suggestions: item.ActivityPQQSuggestions, - supportings: item.ActivityPQQSupportings + supportings: item.ActivityPQQSupportings, }); } // ---------- SORTING ---------- - const sortedCategories: any = Object.values(grouped) - .sort((a: any, b: any) => a.displayOrder - b.displayOrder); + const sortedCategories: any = Object.values(grouped).sort( + (a: any, b: any) => a.displayOrder - b.displayOrder, + ); for (const cat of sortedCategories) { - cat.pqqsubCategories.sort((a: any, b: any) => a.displayOrder - b.displayOrder); + cat.pqqsubCategories.sort( + (a: any, b: any) => a.displayOrder - b.displayOrder, + ); for (const sub of cat.pqqsubCategories) { sub.questions.sort((a: any, b: any) => a.displayOrder - b.displayOrder); @@ -2064,8 +2120,8 @@ export class MinglarService { for (const doc of q.supportings) { if (doc.mediaFileName) { const filePath = doc.mediaFileName; - const key = filePath.startsWith("http") - ? filePath.split(".com/")[1] + const key = filePath.startsWith('http') + ? filePath.split('.com/')[1] : filePath; doc.presignedUrl = await getPresignedUrl(bucket, key); @@ -2078,6 +2134,5 @@ export class MinglarService { // ---------- RETURN GROUPED STRUCTURE ---------- return sortedCategories; - } }