Merge branch 'mayank' of http://git.wdipl.com/Mayank.Mishra/MinglarBackendNestJS into paritosh
This commit is contained in:
39
src/modules/minglaradmin/handlers/getAllCoadminAndAM.ts
Normal file
39
src/modules/minglaradmin/handlers/getAllCoadminAndAM.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 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,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -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
|
||||
// }
|
||||
// }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user