53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
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<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 verifyHostToken(token);
|
|
const userId = Number(userInfo.id);
|
|
|
|
const activityXid = event.pathParameters?.activityXid
|
|
if (!activityXid) {
|
|
throw new ApiError(400, 'activityXid is required in path parameters');
|
|
}
|
|
|
|
const hostId = await schedulingService.getHostIdByUserId(userId);
|
|
|
|
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,
|
|
}),
|
|
};
|
|
});
|