Implement pagination in getAllOnboardingHostApplications handler and update MinglarService to support pagination options. Enhance response structure to include total count of applications.
This commit is contained in:
@@ -8,6 +8,7 @@ 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';
|
||||
import { paginationService } from '../../../../../common/utils/pagination/pagination.service';
|
||||
|
||||
const prismaService = new PrismaService();
|
||||
const minglarService = new MinglarService(prismaService);
|
||||
@@ -51,9 +52,23 @@ export const handler = safeHandler(
|
||||
(queryParams.q as string) ||
|
||||
undefined;
|
||||
|
||||
// Pagination
|
||||
const paginationParams = paginationService.getPaginationFromEvent(event);
|
||||
const paginationOptions =
|
||||
paginationService.parsePaginationParams(paginationParams);
|
||||
|
||||
// Get all host applications from service based on user role
|
||||
const hostApplications =
|
||||
await minglarService.getAllOnboardingHostApplications(search);
|
||||
const { data, totalCount } =
|
||||
await minglarService.getAllOnboardingHostApplications(
|
||||
paginationOptions,
|
||||
search,
|
||||
);
|
||||
|
||||
const paginatedResponse = paginationService.createPaginatedResponse(
|
||||
data,
|
||||
totalCount,
|
||||
paginationOptions,
|
||||
);
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
@@ -64,7 +79,7 @@ export const handler = safeHandler(
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: 'Host applications retrieved successfully',
|
||||
data: hostApplications,
|
||||
...paginatedResponse,
|
||||
}),
|
||||
};
|
||||
},
|
||||
|
||||
@@ -843,7 +843,10 @@ export class MinglarService {
|
||||
};
|
||||
}
|
||||
|
||||
async getAllOnboardingHostApplications(search?: string) {
|
||||
async getAllOnboardingHostApplications(
|
||||
paginationOptions?: PaginationOptions,
|
||||
search?: string,
|
||||
) {
|
||||
const where: any = {
|
||||
isActive: true,
|
||||
hostStatusInternal: { notIn: [HOST_STATUS_INTERNAL.DRAFT] },
|
||||
@@ -889,6 +892,8 @@ export class MinglarService {
|
||||
];
|
||||
}
|
||||
|
||||
const totalCount = await this.prisma.hostHeader.count({ where });
|
||||
|
||||
const onBoardingHostApp = await this.prisma.hostHeader.findMany({
|
||||
where,
|
||||
select: {
|
||||
@@ -924,6 +929,11 @@ export class MinglarService {
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'desc',
|
||||
},
|
||||
skip: paginationOptions?.skip ?? 0,
|
||||
take: paginationOptions?.limit ?? undefined,
|
||||
});
|
||||
|
||||
const bucket = config.aws.bucketName;
|
||||
@@ -943,7 +953,10 @@ export class MinglarService {
|
||||
}
|
||||
}
|
||||
|
||||
return onBoardingHostApp;
|
||||
return {
|
||||
data: onBoardingHostApp,
|
||||
totalCount,
|
||||
};
|
||||
}
|
||||
|
||||
async getAllOnboardingHostApplications_New(
|
||||
|
||||
Reference in New Issue
Block a user