Add new endpoints for activity types and frequencies, and implement email notifications for AM assignments
This commit is contained in:
47
src/modules/host/handlers/getActivity.ts
Normal file
47
src/modules/host/handlers/getActivity.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { verifyHostToken } from '@/common/middlewares/jwt/authForHost';
|
||||
import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
|
||||
import { PrismaService } from '../../../common/database/prisma.service';
|
||||
import { safeHandler } from '../../../common/utils/handlers/safeHandler';
|
||||
import ApiError from '../../../common/utils/helper/ApiError';
|
||||
import { HostService } from '../services/host.service';
|
||||
|
||||
const prismaService = new PrismaService();
|
||||
const hostService = new HostService(prismaService);
|
||||
|
||||
/**
|
||||
* Add suggestion handler for host applications
|
||||
* Allows Minglar Admin, Co_Admin, and Account Manager to add suggestions
|
||||
* Types: Setup Profile, Review Account, Add Payment Details, Agreement
|
||||
*/
|
||||
export const handler = safeHandler(async (
|
||||
event: APIGatewayProxyEvent,
|
||||
context?: Context
|
||||
): Promise<APIGatewayProxyResult> => {
|
||||
// Verify authentication token
|
||||
const token = event.headers['x-auth-token'] || event.headers['X-Auth-Token'];
|
||||
if (!token) {
|
||||
throw new ApiError(401, 'This is a protected route. Please provide a valid token.');
|
||||
}
|
||||
|
||||
// Verify token and get user info
|
||||
const userInfo = await verifyHostToken(token);
|
||||
|
||||
|
||||
// Read optional search query (supports ?search= or ?q=)
|
||||
const search = event.queryStringParameters?.search || event.queryStringParameters?.q || undefined;
|
||||
|
||||
const data = await hostService.getAllActivityTypesWithInterest(search);
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: 'Data retrieved successfully',
|
||||
data,
|
||||
}),
|
||||
};
|
||||
});
|
||||
@@ -550,4 +550,36 @@ export class HostService {
|
||||
});
|
||||
}
|
||||
|
||||
async getAllActivityTypesWithInterest(search?: string) {
|
||||
const where: any = {
|
||||
isActive: true,
|
||||
deletedAt: null,
|
||||
};
|
||||
|
||||
if (search && search.trim() !== '') {
|
||||
const q = search.trim();
|
||||
where.OR = [
|
||||
{ activityTypeName: { contains: q, mode: 'insensitive' } },
|
||||
{ interests: { interestName: { contains: q, mode: 'insensitive' } } },
|
||||
];
|
||||
}
|
||||
|
||||
return await this.prisma.activityTypes.findMany({
|
||||
where,
|
||||
select: {
|
||||
id: true,
|
||||
activityTypeName: true,
|
||||
interestXid: true,
|
||||
interests: {
|
||||
select: {
|
||||
id: true,
|
||||
interestName: true,
|
||||
displayOrder: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: { activityTypeName: 'asc' },
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user