2026-01-28 16:24:40 +05:30
|
|
|
import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
|
|
|
|
|
import { prismaClient } from '../../../../../common/database/prisma.lambda.service';
|
|
|
|
|
import { verifyMinglarAdminHostToken } from '../../../../../common/middlewares/jwt/authForMinglarAdminHost';
|
|
|
|
|
import { safeHandler } from '../../../../../common/utils/handlers/safeHandler';
|
|
|
|
|
import ApiError from '../../../../../common/utils/helper/ApiError';
|
|
|
|
|
import { SchedulingService } from '../../../services/activityScheduling.service';
|
2026-01-28 17:58:05 +05:30
|
|
|
import { ACTIVITY_INTERNAL_STATUS } from '../../../../../common/utils/constants/host.constant';
|
2026-01-28 16:24:40 +05:30
|
|
|
|
|
|
|
|
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<APIGatewayProxyResult> => {
|
|
|
|
|
// 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 verifyMinglarAdminHostToken(token);
|
2026-02-02 13:33:07 +05:30
|
|
|
const userId = Number(userInfo.id);
|
2026-01-28 16:24:40 +05:30
|
|
|
|
|
|
|
|
// Get status filter from query parameters
|
|
|
|
|
const status = event.queryStringParameters?.status as string | undefined;
|
2026-02-02 13:33:07 +05:30
|
|
|
|
|
|
|
|
const hostId = await schedulingService.getHostIdByUserId(userId);
|
2026-01-28 16:24:40 +05:30
|
|
|
|
|
|
|
|
// Validate status if provided
|
2026-01-28 17:58:05 +05:30
|
|
|
const validStatuses = [ACTIVITY_INTERNAL_STATUS.ACTIVITY_APPROVED, ACTIVITY_INTERNAL_STATUS.ACTIVITY_UNLISTED, ACTIVITY_INTERNAL_STATUS.ACTIVITY_LISTED];
|
2026-01-28 16:24:40 +05:30
|
|
|
if (status && !validStatuses.includes(status)) {
|
|
|
|
|
throw new ApiError(400, `Invalid status. Must be one of: ${validStatuses.join(', ')}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get activities from service
|
|
|
|
|
const activities = await schedulingService.getActivitiesByStatus(hostId, status);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
statusCode: 200,
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Access-Control-Allow-Origin': '*',
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
success: true,
|
|
|
|
|
message: 'Activities retrieved successfully',
|
|
|
|
|
data: {
|
|
|
|
|
total: activities.length,
|
|
|
|
|
activities: activities,
|
|
|
|
|
filter: {
|
|
|
|
|
status: status || 'All',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
};
|
|
|
|
|
});
|