This commit is contained in:
paritosh18
2025-11-17 17:39:25 +05:30
6 changed files with 157 additions and 19 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 response = await minglarService.getAllCoadminAndAM();
return {
statusCode: 200,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
},
body: JSON.stringify({
success: true,
message: 'Data retrieved successfully',
data: response,
}),
};
});

View File

@@ -433,6 +433,53 @@ export class MinglarService {
accountManager: host.accountManager || null
}));
}
async getAllCoadminAndAM() {
return await this.prisma.user.findMany({
where: {
roleXid: {
in: [ROLE.CO_ADMIN, ROLE.ACCOUNT_MANAGER]
},
isActive: true,
// 🔥 Filter users who have at least ONE accepted invitation
inviteDetails: {
some: {
isMinglarInvitation: true,
is_accepted: true,
invitation_status: MINGLAR_INVITATION_STATUS.ACCEPTED,
isActive: true
}
}
},
include: {
role: {
select: {
id: true,
roleName: true,
},
},
// (Optional) to return only the accepted invitations
// inviteDetails: {
// where: {
// isMinglarInvitation: true,
// is_accepted: true,
// invitation_status: MINGLAR_INVITATION_STATUS.ACCEPTED,
// isActive: true
// },
// select: {
// id: true,
// invitedBy: true,
// invited_on: true,
// invitation_status: true,
// is_accepted: true
// }
// }
}
});
}
}