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

21 lines
679 B
TypeScript
Raw Normal View History

2020-10-12 13:35:33 +09:00
import { PrismaClient } from '@prisma/client'
2020-11-19 16:16:33 +09:00
import { Task, TaskUpdateInput } from '$prisma/client'
import { depend } from 'velona'
2020-10-12 13:35:33 +09:00
const prisma = new PrismaClient()
2020-11-19 16:16:33 +09:00
export const getTasks = depend(
{ prisma: prisma as { task: { findMany(): Promise<Task[]> } } },
async ({ prisma }, limit?: number) =>
(await prisma.task.findMany()).slice(0, limit)
)
2020-10-12 13:35:33 +09:00
export const createTask = (label: Task['label']) =>
prisma.task.create({ data: { label } })
2020-11-19 16:16:33 +09:00
export const updateTask = (id: Task['id'], partialTask: TaskUpdateInput) =>
prisma.task.update({ where: { id }, data: partialTask })
2020-10-12 13:35:33 +09:00
export const deleteTask = (id: Task['id']) =>
prisma.task.delete({ where: { id } })