1
0
Fork 0
mirror of https://github.com/kou029w/_.git synced 2025-01-31 06:18:07 +00:00
_/frourio/server/service/tasks.ts

20 lines
679 B
TypeScript

import { PrismaClient } from '@prisma/client'
import { Task, TaskUpdateInput } from '$prisma/client'
import { depend } from 'velona'
const prisma = new PrismaClient()
export const getTasks = depend(
{ prisma: prisma as { task: { findMany(): Promise<Task[]> } } },
async ({ prisma }, limit?: number) =>
(await prisma.task.findMany()).slice(0, limit)
)
export const createTask = (label: Task['label']) =>
prisma.task.create({ data: { label } })
export const updateTask = (id: Task['id'], partialTask: TaskUpdateInput) =>
prisma.task.update({ where: { id }, data: partialTask })
export const deleteTask = (id: Task['id']) =>
prisma.task.delete({ where: { id } })