made a pagination service
This commit is contained in:
@@ -4,13 +4,13 @@ import { PrismaService } from '../../../../../common/database/prisma.service';
|
||||
import { MinglarService } from '../../../services/minglar.service';
|
||||
import ApiError from '../../../../../common/utils/helper/ApiError';
|
||||
import { verifyMinglarAdminToken } from '../../../../../common/middlewares/jwt/authForMinglarAdmin';
|
||||
import { paginationService } from '../../../../../common/utils/pagination/pagination.service';
|
||||
|
||||
const prismaService = new PrismaService();
|
||||
const minglarService = new MinglarService(prismaService);
|
||||
|
||||
/**
|
||||
* Get all host applications handler
|
||||
* Returns host details with status, submission date, and account manager info
|
||||
* Get all host applications handler with pagination
|
||||
*/
|
||||
export const handler = safeHandler(async (
|
||||
event: APIGatewayProxyEvent,
|
||||
@@ -35,13 +35,29 @@ export const handler = safeHandler(async (
|
||||
throw new ApiError(404, 'User not found');
|
||||
}
|
||||
|
||||
// Get search query from query parameters
|
||||
// Get query parameters
|
||||
const search = event.queryStringParameters?.search || '';
|
||||
// Extract userStatus (e.g. 'new') from query parameters
|
||||
const userStatus = event.queryStringParameters?.userStatus || '';
|
||||
|
||||
// Parse pagination parameters
|
||||
const paginationParams = paginationService.getPaginationFromEvent(event);
|
||||
const paginationOptions = paginationService.parsePaginationParams(paginationParams);
|
||||
|
||||
// Get all host applications from service based on user role
|
||||
const hostApplications = await minglarService.getAllHostApplications(user.id, Number(user.roleXid), search, userStatus);
|
||||
// Get paginated host applications
|
||||
const { data, totalCount } = await minglarService.getAllHostApplications(
|
||||
user.id,
|
||||
Number(user.roleXid),
|
||||
search,
|
||||
userStatus,
|
||||
paginationOptions
|
||||
);
|
||||
|
||||
// Create paginated response
|
||||
const paginatedResponse = paginationService.createPaginatedResponse(
|
||||
data,
|
||||
totalCount,
|
||||
paginationOptions
|
||||
);
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
@@ -52,7 +68,7 @@ export const handler = safeHandler(async (
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: 'Host applications retrieved successfully',
|
||||
data: hostApplications,
|
||||
...paginatedResponse,
|
||||
}),
|
||||
};
|
||||
});
|
||||
});
|
||||
@@ -26,6 +26,7 @@ import { CreateMinglarDto, UpdateMinglarDto } from '../dto/minglar.dto';
|
||||
import { sendAMEmailForHostAssign } from './AMEmail.service';
|
||||
import { getPresignedUrl } from '@/common/middlewares/aws/getPreSignedUrl';
|
||||
import config from '@/config/config';
|
||||
import { PaginationOptions } from '@/common/utils/pagination/pagination.types';
|
||||
|
||||
@Injectable()
|
||||
export class MinglarService {
|
||||
@@ -636,11 +637,13 @@ export class MinglarService {
|
||||
});
|
||||
}
|
||||
|
||||
// Update your MinglarService method
|
||||
async getAllHostApplications(
|
||||
userId: number,
|
||||
userRoleXid: number,
|
||||
search?: string,
|
||||
userStatus?: string,
|
||||
paginationOptions?: PaginationOptions,
|
||||
) {
|
||||
const filters: any = {
|
||||
isActive: true,
|
||||
@@ -693,7 +696,14 @@ export class MinglarService {
|
||||
}
|
||||
|
||||
/** -----------------------------------
|
||||
* MAIN QUERY
|
||||
* COUNT TOTAL RECORDS
|
||||
* ----------------------------------- */
|
||||
const totalCount = await this.prisma.hostHeader.count({
|
||||
where: filters,
|
||||
});
|
||||
|
||||
/** -----------------------------------
|
||||
* MAIN QUERY WITH PAGINATION
|
||||
* ----------------------------------- */
|
||||
const results = await this.prisma.hostHeader.findMany({
|
||||
where: filters,
|
||||
@@ -732,12 +742,14 @@ export class MinglarService {
|
||||
},
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
skip: paginationOptions?.skip || 0,
|
||||
take: paginationOptions?.limit || 10,
|
||||
});
|
||||
|
||||
/** -----------------------------------
|
||||
* TRANSFORM RESPONSE
|
||||
* ----------------------------------- */
|
||||
return results.map((h) => ({
|
||||
const transformedData = results.map((h) => ({
|
||||
hostId: h.id,
|
||||
host: h.user,
|
||||
hostStatusDisplay: h.hostStatusDisplay,
|
||||
@@ -752,6 +764,11 @@ export class MinglarService {
|
||||
country: h.countries || null,
|
||||
assignedOn: h.assignedOn || null,
|
||||
}));
|
||||
|
||||
return {
|
||||
data: transformedData,
|
||||
totalCount,
|
||||
};
|
||||
}
|
||||
|
||||
async getAllOnboardingHostApplications() {
|
||||
|
||||
Reference in New Issue
Block a user