first commit

This commit is contained in:
Stefan Hacker
2026-01-29 01:16:54 +01:00
commit e209e9bbca
12105 changed files with 2480672 additions and 0 deletions
+79
View File
@@ -0,0 +1,79 @@
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
export async function getAllProviders(includeInactive = false) {
const where = includeInactive ? {} : { isActive: true };
return prisma.provider.findMany({
where,
orderBy: { name: 'asc' },
include: {
tariffs: {
where: includeInactive ? {} : { isActive: true },
orderBy: { name: 'asc' },
},
_count: {
select: { contracts: true, tariffs: true },
},
},
});
}
export async function getProviderById(id: number) {
return prisma.provider.findUnique({
where: { id },
include: {
tariffs: {
orderBy: { name: 'asc' },
},
_count: {
select: { contracts: true },
},
},
});
}
export async function createProvider(data: {
name: string;
portalUrl?: string;
usernameFieldName?: string;
passwordFieldName?: string;
}) {
return prisma.provider.create({
data: {
...data,
isActive: true,
},
});
}
export async function updateProvider(
id: number,
data: {
name?: string;
portalUrl?: string;
usernameFieldName?: string;
passwordFieldName?: string;
isActive?: boolean;
}
) {
return prisma.provider.update({
where: { id },
data,
});
}
export async function deleteProvider(id: number) {
// Check if provider is used by any contracts
const count = await prisma.contract.count({
where: { providerId: id },
});
if (count > 0) {
throw new Error(
`Anbieter kann nicht gelöscht werden, da er von ${count} Verträgen verwendet wird`
);
}
return prisma.provider.delete({ where: { id } });
}