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 } })
|