62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import {
|
|
APIGatewayProxyEvent,
|
|
APIGatewayProxyResult,
|
|
Context,
|
|
} from 'aws-lambda';
|
|
|
|
import { prismaClient } from '../../../../common/database/prisma.lambda.service';
|
|
import { verifyHostToken } from '../../../../common/middlewares/jwt/authForHost';
|
|
import { paginationService } from '../../../../common/utils/pagination/pagination.service';
|
|
import { safeHandler } from '../../../../common/utils/handlers/safeHandler';
|
|
import ApiError from '../../../../common/utils/helper/ApiError';
|
|
import { HostMemberService } from '../../services/hostMember.service';
|
|
|
|
const hostMemberService = new HostMemberService(prismaClient);
|
|
|
|
export const handler = safeHandler(async (
|
|
event: APIGatewayProxyEvent,
|
|
context?: Context,
|
|
): Promise<APIGatewayProxyResult> => {
|
|
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 search = event.queryStringParameters?.search || '';
|
|
|
|
const paginationParams = paginationService.getPaginationFromEvent(event);
|
|
const paginationOptions =
|
|
paginationService.parsePaginationParams(paginationParams);
|
|
|
|
const { data, totalCount } =
|
|
await hostMemberService.getAllInvitedCoadminAndOperator({
|
|
hostUserXid: userInfo.id,
|
|
search,
|
|
paginationOptions,
|
|
});
|
|
|
|
const paginatedResponse = paginationService.createPaginatedResponse(
|
|
data,
|
|
totalCount,
|
|
paginationOptions,
|
|
);
|
|
|
|
return {
|
|
statusCode: 200,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Access-Control-Allow-Origin': '*',
|
|
},
|
|
body: JSON.stringify({
|
|
success: true,
|
|
message: 'Invited co-admin and operator members fetched successfully',
|
|
...paginatedResponse,
|
|
}),
|
|
};
|
|
});
|