30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { prisma } from '@/lib/db/prisma';
|
|
import {
|
|
createApplicationSchema,
|
|
updateApplicationSchema,
|
|
type CreateApplicationInput,
|
|
type UpdateApplicationInput,
|
|
} from './applications.schema';
|
|
|
|
export const applicationsService = {
|
|
list: () => prisma.application.findMany({ orderBy: { name: 'asc' } }),
|
|
get: (id: string) => prisma.application.findUnique({ where: { id } }),
|
|
create: (input: CreateApplicationInput) =>
|
|
prisma.application.create({ data: createApplicationSchema.parse(input) }),
|
|
update: (id: string, input: UpdateApplicationInput) =>
|
|
prisma.application.update({ where: { id }, data: updateApplicationSchema.parse(input) }),
|
|
delete: (id: string) => prisma.application.delete({ where: { id } }),
|
|
|
|
linkToHost: (hostId: string, applicationId: string, notes?: string) =>
|
|
prisma.hostApplication.upsert({
|
|
where: { hostId_applicationId: { hostId, applicationId } },
|
|
update: { notes },
|
|
create: { hostId, applicationId, notes },
|
|
}),
|
|
|
|
unlinkFromHost: (hostId: string, applicationId: string) =>
|
|
prisma.hostApplication.delete({
|
|
where: { hostId_applicationId: { hostId, applicationId } },
|
|
}),
|
|
};
|