fixed minor issues
This commit is contained in:
@@ -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.getAllInvitedCoadminAndAM();
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: 'Data retrieved successfully',
|
||||
data: response,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -494,7 +494,7 @@ export class MinglarService {
|
||||
notIn: [ROLE.CO_ADMIN, ROLE.ACCOUNT_MANAGER]
|
||||
},
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Add search filter if search query is provided
|
||||
if (search && search.trim() !== '') {
|
||||
@@ -585,7 +585,7 @@ export class MinglarService {
|
||||
companyName: host.companyName || null,
|
||||
city: host.cities || null,
|
||||
state: host.states || null,
|
||||
country: host.countries || null,
|
||||
country: host.countries || null,
|
||||
assignedOn: host.assignedOn || null,
|
||||
}));
|
||||
}
|
||||
@@ -644,6 +644,32 @@ export class MinglarService {
|
||||
}));
|
||||
}
|
||||
|
||||
async getAllInvitedCoadminAndAM() {
|
||||
return await this.prisma.user.findMany({
|
||||
where: {
|
||||
roleXid: {
|
||||
in: [
|
||||
ROLE.MINGLAR_ADMIN, // Admin
|
||||
ROLE.CO_ADMIN, // Co-Admin
|
||||
ROLE.ACCOUNT_MANAGER // AM
|
||||
]
|
||||
},
|
||||
isActive: true,
|
||||
userStatus: {
|
||||
not: USER_STATUS.DE_ACTIVATED // Exclude DE_ACTIVATED status
|
||||
},
|
||||
},
|
||||
include: {
|
||||
role: {
|
||||
select: {
|
||||
id: true,
|
||||
roleName: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async assignAMToHost(userId: number, hostXid: number, accountManagerXid: number) {
|
||||
const hostDetails = await this.prisma.hostHeader.findFirst({
|
||||
@@ -685,8 +711,8 @@ export class MinglarService {
|
||||
if (!accountManagerXid) return false;
|
||||
|
||||
const amUser = await this.prisma.user.findUnique({
|
||||
where: { id: accountManagerXid ,isActive:true},
|
||||
select: { emailAddress: true},
|
||||
where: { id: accountManagerXid, isActive: true },
|
||||
select: { emailAddress: true },
|
||||
});
|
||||
|
||||
if (!amUser || !amUser.emailAddress) {
|
||||
|
||||
Reference in New Issue
Block a user