wasp/examples/tutorials/TodoApp/ext/actions.js

22 lines
565 B
JavaScript
Raw Normal View History

import HttpError from '@wasp/core/HttpError.js'
2020-10-12 16:03:07 +03:00
export const createTask = async ({ description }, context) => {
if (!context.user) { throw new HttpError(403) }
2020-10-12 16:03:07 +03:00
return context.entities.Task.create({
data: {
description,
user: { connect: { id: context.user.id } }
}
2020-10-12 16:03:07 +03:00
})
}
export const updateTask = async ({ taskId, data }, context) => {
if (!context.user) { throw new HttpError(403) }
return context.entities.Task.updateMany({
where: { id: taskId, user: { id: context.user.id } },
2020-10-12 23:07:36 +03:00
data: {
isDone: data.isDone
2020-10-12 23:07:36 +03:00
}
2020-10-12 16:03:07 +03:00
})
}