made getAllInvitation Details api

This commit is contained in:
2025-11-17 12:17:06 +05:30
parent 4ee0819051
commit ce4af2ea3b
7 changed files with 219 additions and 17 deletions

View File

@@ -0,0 +1,39 @@
import { verifyOnlyMinglarAdminToken } from '@/common/middlewares/jwt/authForOnlyMinglarAdmin';
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 { MinglarService } from '../services/minglar.service';
const prismaService = new PrismaService();
const minglarService = new MinglarService(prismaService);
export const handler = safeHandler(async (
event: APIGatewayProxyEvent,
context?: Context
): Promise<APIGatewayProxyResult> => {
// Extract token from headers
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.');
}
// Authenticate user using the shared authForHost function
await verifyOnlyMinglarAdminToken(token);
const result = await minglarService.getAllInvitationDetails();
return {
statusCode: 200,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
},
body: JSON.stringify({
success: true,
message: 'Data retrieved successfully',
data: result,
}),
};
});

View File

@@ -106,7 +106,7 @@ export const handler = safeHandler(async (
await minglarService.createUserRevenue(user.id, isFixedSalary, perValue || 0);
// Create invite details - using service
await minglarService.createInviteDetails(user.id, adminUser.id, MINGLAR_INVITATION_STATUS.PENDING);
await minglarService.createInviteDetails(user.id, adminUser.id, MINGLAR_INVITATION_STATUS.INVITED);
await sendInvitationEmailForMinglarAdmin(emailAddress);

View File

@@ -329,5 +329,32 @@ export class MinglarService {
});
}
async getAllInvitationDetails() {
return await this.prisma.inviteDetails.findMany({
where: {
isMinglarInvitation: true,
isActive: true,
},
include: {
user: {
select: {
id: true,
firstName: true,
lastName: true,
emailAddress: true,
mobileNumber: true,
roleXid: true,
role: {
select: {
id: true,
roleName: true,
}
}
}
}
}
})
}
}