creates application

This commit is contained in:
simon.franken
2026-02-16 10:15:27 +01:00
parent 791c661395
commit 7d678c1c4d
65 changed files with 10389 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
import { prisma } from '../prisma/client';
import type { CreateClientInput, UpdateClientInput } from '../types';
export class ClientService {
async findAll(userId: string) {
return prisma.client.findMany({
where: { userId },
orderBy: { name: 'asc' },
});
}
async findById(id: string, userId: string) {
return prisma.client.findFirst({
where: { id, userId },
});
}
async create(userId: string, data: CreateClientInput) {
return prisma.client.create({
data: {
...data,
userId,
},
});
}
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;
}
return prisma.client.update({
where: { id },
data,
});
}
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;
}
await prisma.client.delete({
where: { id },
});
}
}