Files
canina/backend/src/admin/pets.service.ts
T
devops ddbf1ca026
Deploy Canina / deploy (push) Successful in 4m1s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 7s
test: comprehensive test suites and quality gates pass across backend, storefront and admin
- Backend (NestJS): 82 suites, 641 tests passing; 0 ESLint errors; 0 tsc errors. Hardened SSL cert/key matching, SSRF IP pinning, and eBank validation.
- Admin Panel (Vite/React): 48 suites, 300 tests passing; 0 ESLint errors; 0 tsc errors. Full coverage across all pages and settings.
- Storefront (Next.js): 62 suites, 368 tests passing; 0 ESLint errors; 0 tsc errors.
- Fixed unmount lifecycle guards, promise error handling, and component edge cases.
2026-10-13 16:01:00 +00:00

71 lines
1.7 KiB
TypeScript

import { Injectable, NotFoundException } from "@nestjs/common";
import { Prisma } from "@prisma/client";
import { PrismaService } from "../prisma/prisma.service";
export class PetQuery {
page?: number | string;
limit?: number | string;
search?: string;
}
@Injectable()
export class PetsService {
constructor(private prisma: PrismaService) {}
async getPets(query: PetQuery = {}) {
const page = Number(query.page) || 1;
const limit = Number(query.limit) || 10;
const skip = (page - 1) * limit;
const where: Prisma.PetWhereInput = query.search
? { name: { contains: query.search, mode: "insensitive" } }
: {};
const [data, total] = await Promise.all([
this.prisma.pet.findMany({
where,
skip,
take: limit,
orderBy: { createdAt: "desc" },
include: {
user: {
select: {
firstName: true,
lastName: true,
email: true,
mobile: true,
},
},
medicalConditions: true,
reminders: true,
healthLogs: {
orderBy: { createdAt: "desc" },
take: 10,
},
prescriptions: {
orderBy: { createdAt: "desc" },
take: 5,
},
},
}),
this.prisma.pet.count({ where }),
]);
return {
data,
meta: {
total,
page,
limit,
lastPage: Math.ceil(total / limit),
},
};
}
async deletePet(id: string) {
const pet = await this.prisma.pet.findUnique({ where: { id } });
if (!pet) throw new NotFoundException("Pet not found");
return this.prisma.pet.delete({ where: { id } });
}
}