From cb92fbe4000bb5327b22ed85f525acefff7c0c49 Mon Sep 17 00:00:00 2001 From: Mayank Mishra Date: Mon, 2 Feb 2026 13:33:07 +0530 Subject: [PATCH] feat: refactor user ID handling and implement getHostIdByUserId method in SchedulingService --- .../Scheduling/getSchedulingOfAct.ts | 13 +++++++------ .../services/activityScheduling.service.ts | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/modules/host/handlers/Activity_Hub/Scheduling/getSchedulingOfAct.ts b/src/modules/host/handlers/Activity_Hub/Scheduling/getSchedulingOfAct.ts index 55c1740..a0f67bb 100644 --- a/src/modules/host/handlers/Activity_Hub/Scheduling/getSchedulingOfAct.ts +++ b/src/modules/host/handlers/Activity_Hub/Scheduling/getSchedulingOfAct.ts @@ -27,18 +27,20 @@ export const handler = safeHandler(async ( } const userInfo = await verifyMinglarAdminHostToken(token); - const hostId = Number(userInfo.id); + const userId = Number(userInfo.id); - if (!hostId) { - throw new ApiError(400, 'Host ID is required'); + if (!userId) { + throw new ApiError(400, 'User ID is required'); } - if (isNaN(hostId)) { - throw new ApiError(400, 'Invalid host ID format'); + if (isNaN(userId)) { + throw new ApiError(400, 'Invalid user ID format'); } // Get status filter from query parameters const status = event.queryStringParameters?.status as string | undefined; + + const hostId = await schedulingService.getHostIdByUserId(userId); // Validate status if provided const validStatuses = [ACTIVITY_INTERNAL_STATUS.ACTIVITY_APPROVED, ACTIVITY_INTERNAL_STATUS.ACTIVITY_UNLISTED, ACTIVITY_INTERNAL_STATUS.ACTIVITY_LISTED]; @@ -63,7 +65,6 @@ export const handler = safeHandler(async ( activities: activities, filter: { status: status || 'All', - hostId: hostId, }, }, }), diff --git a/src/modules/host/services/activityScheduling.service.ts b/src/modules/host/services/activityScheduling.service.ts index 772d530..c7672db 100644 --- a/src/modules/host/services/activityScheduling.service.ts +++ b/src/modules/host/services/activityScheduling.service.ts @@ -13,6 +13,24 @@ const bucket = config.aws.bucketName; export class SchedulingService { constructor(private prisma: PrismaClient) { } + async getHostIdByUserId(userId: number) { + const host = await this.prisma.hostHeader.findFirst({ + where: { + userXid: userId, + isActive: true + }, + select: { + id: true + } + }) + + if (!host) { + throw new ApiError(404, 'Host not found for the given user.'); + } + + return host.id; + } + async addSchedulingForActivity(data: ScheduleActivityDTO) { const { activityXid,