made getAllInvitation Details api
This commit is contained in:
39
src/modules/minglaradmin/handlers/getAllInvitationDetails.ts
Normal file
39
src/modules/minglaradmin/handlers/getAllInvitationDetails.ts
Normal 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,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user