Add getSuggestionsForAM function and corresponding handler for retrieving suggestions based on host assignments. Update serverless configuration to include new API endpoint.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { verifyMinglarAdminToken } from '@/common/middlewares/jwt/authForMinglarAdmin';
|
||||
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 { MinglarService } from '../../../../minglaradmin/services/minglar.service';
|
||||
|
||||
const minglarService = new MinglarService(prismaClient);
|
||||
|
||||
/**
|
||||
* Get suggestions handler
|
||||
* Retrieves suggestions based on user's role and host assignments
|
||||
*/
|
||||
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
|
||||
await verifyMinglarAdminToken(token);
|
||||
|
||||
const hostXid = Number(event.pathParameters?.hostXid)
|
||||
|
||||
// Get suggestions using service
|
||||
const suggestions = await minglarService.getSuggestionsForAM(hostXid);
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: 'Suggestions retrieved successfully',
|
||||
data: suggestions,
|
||||
}),
|
||||
};
|
||||
});
|
||||
@@ -1423,6 +1423,25 @@ export class MinglarService {
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
async getSuggestionsForAM(hostXid: number) {
|
||||
const suggestions = await this.prisma.hostSuggestion.findMany({
|
||||
where: { hostXid: hostXid, isreviewed: false, isActive: true },
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
comments: true,
|
||||
isparent: true,
|
||||
isreviewed: true,
|
||||
reviewOn: true,
|
||||
},
|
||||
orderBy: {
|
||||
id: 'asc',
|
||||
},
|
||||
});
|
||||
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
async acceptHostApplication(host_xid: number, user_xid: number) {
|
||||
return await this.prisma.$transaction(async (tx) => {
|
||||
await this.prisma.hostHeader.update({
|
||||
|
||||
Reference in New Issue
Block a user