added basic task endpoint
This commit is contained in:
parent
d7dcbb3560
commit
b0b6557464
|
|
@ -0,0 +1,31 @@
|
|||
import type { RequestHandler } from "./$types";
|
||||
|
||||
import { json, error } from "@sveltejs/kit"
|
||||
|
||||
import { Error401Cause } from "$lib/errors";
|
||||
|
||||
import db from "$lib/server/database"
|
||||
|
||||
enum StatusFilterValues {
|
||||
all,
|
||||
open,
|
||||
done,
|
||||
}
|
||||
|
||||
export const GET: RequestHandler = async ({ request, locals, url }) => {
|
||||
|
||||
const filter_param = url.searchParams.get("status")
|
||||
const filter = (filter_param && filter_param in StatusFilterValues)
|
||||
? StatusFilterValues[filter_param as keyof typeof StatusFilterValues]
|
||||
: StatusFilterValues.all
|
||||
|
||||
const tasks = await db.task.findMany({
|
||||
where: {
|
||||
userId: {
|
||||
equals: locals.user.id
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return json(tasks)
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
import type { RequestHandler } from "./$types";
|
||||
|
||||
import { json, error } from "@sveltejs/kit"
|
||||
|
||||
import db from "$lib/server/database"
|
||||
|
||||
export const POST: RequestHandler = async ({ request, locals }) => {
|
||||
|
||||
const data = await request.formData()
|
||||
|
||||
const content = data.get("content")
|
||||
|
||||
if (!content || typeof content !== "string") {
|
||||
return error(400, { message: "content must be specified" })
|
||||
}
|
||||
|
||||
const task = await db.task.create({
|
||||
data: {
|
||||
content: content,
|
||||
user: {
|
||||
connect: {
|
||||
id: locals.user.id
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return json(task)
|
||||
}
|
||||
Loading…
Reference in New Issue