first commit
This commit is contained in:
29
src/modules/applications/applications.service.ts
Normal file
29
src/modules/applications/applications.service.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
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 } },
|
||||
}),
|
||||
};
|
||||
Reference in New Issue
Block a user