made a pagination service

This commit is contained in:
2025-11-29 12:04:50 +05:30
parent e0b841b437
commit 264f2fa29c
6 changed files with 149 additions and 18 deletions

View File

@@ -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() {