wasp/waspc/examples/todoApp/ext/actions.js

26 lines
575 B
JavaScript
Raw Normal View History

import HttpError from '@wasp/core/HttpError.js'
2020-09-19 17:11:09 +03:00
import Prisma from '@prisma/client'
2020-09-19 17:11:09 +03:00
const prisma = new Prisma.PrismaClient()
export const createTask = async (task, context) => {
/*
if (Math.random() < 0.5) {
throw new HttpError(400, 'Failed to create task, random error!')
}
*/
2020-09-19 17:11:09 +03:00
const newTask = await prisma.task.create({
data: {
description: task.description
}
})
}
export const updateTaskIsDone = async ({taskId, newIsDoneVal}, context) => {
await prisma.task.update({
where: { id: taskId },
data: { isDone: newIsDoneVal }
})
}