feat(pets): add admin pet health records query and paginated pet list endpoint [TASK-26.17]
This commit is contained in:
1 parent
d94b33f96d
commit
cbcff26e63
4 files changed
+119
-1
No files matched your search
@@ -31,6 +31,66 @@ export class PetsService {
|
||||
});
|
||||
}
|
||||
|
||||
async findAllAdmin(filters: PaginationDto) {
|
||||
const {
|
||||
search,
|
||||
page = 1,
|
||||
limit = 10,
|
||||
sortBy = 'createdAt',
|
||||
sortOrder = 'desc',
|
||||
} = filters;
|
||||
|
||||
const whereClause: any = {};
|
||||
if (search) {
|
||||
whereClause.OR = [
|
||||
{ name: { contains: search, mode: 'insensitive' } },
|
||||
{ breed: { contains: search, mode: 'insensitive' } },
|
||||
{ user: { firstName: { contains: search, mode: 'insensitive' } } },
|
||||
{ user: { lastName: { contains: search, mode: 'insensitive' } } },
|
||||
{ user: { mobile: { contains: search } } },
|
||||
];
|
||||
}
|
||||
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
const [data, total] = await Promise.all([
|
||||
this.prisma.pet.findMany({
|
||||
where: whereClause,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { [sortBy]: sortOrder },
|
||||
include: {
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
mobile: true,
|
||||
email: true,
|
||||
},
|
||||
},
|
||||
medicalConditions: true,
|
||||
reminders: true,
|
||||
healthLogs: {
|
||||
orderBy: { loggedDate: 'desc' },
|
||||
take: 10,
|
||||
},
|
||||
},
|
||||
}),
|
||||
this.prisma.pet.count({ where: whereClause }),
|
||||
]);
|
||||
|
||||
return {
|
||||
data,
|
||||
meta: {
|
||||
total,
|
||||
page,
|
||||
lastPage: Math.ceil(total / limit),
|
||||
limit,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async findAllByUser(userId: string, filters: PaginationDto) {
|
||||
const {
|
||||
search,
|
||||
@@ -56,6 +116,7 @@ export class PetsService {
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { [sortBy]: sortOrder },
|
||||
include: { medicalConditions: true, reminders: true, healthLogs: true },
|
||||
}),
|
||||
this.prisma.pet.count({ where: whereClause }),
|
||||
]);
|
||||
|
||||
Reference in new issue
Block a user