diff --git a/serverless/functions/host.yml b/serverless/functions/host.yml index 815d1a4..377fe38 100644 --- a/serverless/functions/host.yml +++ b/serverless/functions/host.yml @@ -476,4 +476,20 @@ getActivitiesByStatus: events: - httpApi: path: /scheduling/get-all-activities + method: get + +getVenueDurationByAct: + handler: src/modules/host/handlers/Activity_Hub/Scheduling/getVenueDurationByAct.handler + memorySize: 384 + package: + patterns: + - 'src/modules/host/handlers/Activity_Hub/Scheduling/getVenueDurationByAct.*' + - '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: /scheduling/get-venue-duration/{activityXid} method: get \ No newline at end of file diff --git a/src/modules/host/handlers/Activity_Hub/Scheduling/getSchedulingOfAct.ts b/src/modules/host/handlers/Activity_Hub/Scheduling/getSchedulingOfAct.ts index 6753507..55c1740 100644 --- a/src/modules/host/handlers/Activity_Hub/Scheduling/getSchedulingOfAct.ts +++ b/src/modules/host/handlers/Activity_Hub/Scheduling/getSchedulingOfAct.ts @@ -4,6 +4,7 @@ import { verifyMinglarAdminHostToken } from '../../../../../common/middlewares/j import { safeHandler } from '../../../../../common/utils/handlers/safeHandler'; import ApiError from '../../../../../common/utils/helper/ApiError'; import { SchedulingService } from '../../../services/activityScheduling.service'; +import { ACTIVITY_INTERNAL_STATUS } from '../../../../../common/utils/constants/host.constant'; const schedulingService = new SchedulingService(prismaClient); @@ -40,7 +41,7 @@ export const handler = safeHandler(async ( const status = event.queryStringParameters?.status as string | undefined; // Validate status if provided - const validStatuses = ['Listed', 'Unlisted', 'Not_Listed']; + const validStatuses = [ACTIVITY_INTERNAL_STATUS.ACTIVITY_APPROVED, ACTIVITY_INTERNAL_STATUS.ACTIVITY_UNLISTED, ACTIVITY_INTERNAL_STATUS.ACTIVITY_LISTED]; if (status && !validStatuses.includes(status)) { throw new ApiError(400, `Invalid status. Must be one of: ${validStatuses.join(', ')}`); } diff --git a/src/modules/host/handlers/Activity_Hub/Scheduling/getVenueDurationByAct.ts b/src/modules/host/handlers/Activity_Hub/Scheduling/getVenueDurationByAct.ts new file mode 100644 index 0000000..637ba17 --- /dev/null +++ b/src/modules/host/handlers/Activity_Hub/Scheduling/getVenueDurationByAct.ts @@ -0,0 +1,58 @@ +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 { SchedulingService } from '../../../services/activityScheduling.service'; +import { verifyHostToken } from '../../../../../common/middlewares/jwt/authForHost'; + +const schedulingService = new SchedulingService(prismaClient); + +/** + * GET /activities + * Query Parameters: + * - status: Listed | Unlisted | Not_Listed (optional - if not provided, returns all) + * - hostId: ID of host (required from token) + * + * Returns activities based on status filter + */ +export const handler = safeHandler(async ( + event: APIGatewayProxyEvent, + context?: Context +): Promise => { + // Get and verify token + 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.'); + } + + const userInfo = await verifyHostToken(token); + const hostId = Number(userInfo.id); + + if (!hostId) { + throw new ApiError(400, 'Host ID is required'); + } + + if (isNaN(hostId)) { + throw new ApiError(400, 'Invalid host ID format'); + } + + const activityXid = event.pathParameters?.activityXid + if (!activityXid) { + throw new ApiError(400, 'activityXid is required in path parameters'); + } + + const result = await schedulingService.getVenueDurationByAct(Number(activityXid), Number(hostId)); + + return { + statusCode: 200, + headers: { + 'Content-Type': 'application/json', + 'Access-Control-Allow-Origin': '*', + }, + body: JSON.stringify({ + success: true, + message: 'Details retrieved successfully', + data: result, + }), + }; +}); diff --git a/src/modules/host/services/activityScheduling.service.ts b/src/modules/host/services/activityScheduling.service.ts index 4ec5cc4..5cfbce2 100644 --- a/src/modules/host/services/activityScheduling.service.ts +++ b/src/modules/host/services/activityScheduling.service.ts @@ -226,12 +226,12 @@ export class SchedulingService { in: [ACTIVITY_INTERNAL_STATUS.ACTIVITY_APPROVED, ACTIVITY_INTERNAL_STATUS.ACTIVITY_UNLISTED, ACTIVITY_INTERNAL_STATUS.ACTIVITY_LISTED] } }; - + // Add status filter if provided if (status) { whereClause.activityInternalStatus = status; } - + // Query activities const activities = await this.prisma.activities.findMany({ where: whereClause, @@ -254,7 +254,7 @@ export class SchedulingService { createdAt: 'desc', }, }); - + // Transform response return activities.map((activity) => ({ activityId: activity.id, @@ -266,4 +266,22 @@ export class SchedulingService { media: activity.ActivitiesMedia, })); } + + async getVenueDurationByAct(activityXid: number, hostId: number) { + const result = await this.prisma.activities.findUnique({ + where: { id: activityXid, hostXid: hostId, isActive: true }, + select: { + id: true, + activityDurationMins: true, + ActivityVenues: { + select: { + id: true, + venueName: true, + venueLabel: true, + } + } + } + }) + return result; + } } \ No newline at end of file