improvements

This commit is contained in:
2026-02-16 19:54:15 +01:00
parent 81b4a8ead2
commit 64fd134044
9 changed files with 163 additions and 137 deletions

View File

@@ -1,11 +1,12 @@
import { prisma } from '../prisma/client';
import type { CreateClientInput, UpdateClientInput } from '../types';
import { prisma } from "../prisma/client";
import { NotFoundError } from "../errors/AppError";
import type { CreateClientInput, UpdateClientInput } from "../types";
export class ClientService {
async findAll(userId: string) {
return prisma.client.findMany({
where: { userId },
orderBy: { name: 'asc' },
orderBy: { name: "asc" },
});
}
@@ -27,9 +28,7 @@ export class ClientService {
async update(id: string, userId: string, data: UpdateClientInput) {
const client = await this.findById(id, userId);
if (!client) {
const error = new Error('Client not found') as Error & { statusCode: number };
error.statusCode = 404;
throw error;
throw new NotFoundError("Client not found");
}
return prisma.client.update({
@@ -41,13 +40,11 @@ export class ClientService {
async delete(id: string, userId: string) {
const client = await this.findById(id, userId);
if (!client) {
const error = new Error('Client not found') as Error & { statusCode: number };
error.statusCode = 404;
throw error;
throw new NotFoundError("Client not found");
}
await prisma.client.delete({
where: { id },
});
}
}
}