81c70df78e
Complete household task management system behind task_users auth group: - Task CRUD with recurring schedules, assignees, tags, and optional difficulty - Blobcat SVG sticker rewards on completion, rarity weighted by difficulty - Sticker collection page with calendar view and progress tracking - Redesigned cards with left accent urgency strip, assignee PFP, round check button - Weekday-based due date labels for tasks within 7 days - Tasks link added to homepage LinksGrid
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import type { RequestHandler } from '@sveltejs/kit';
|
|
import { Task } from '$models/Task';
|
|
import { dbConnect } from '$utils/db';
|
|
import { error, json } from '@sveltejs/kit';
|
|
|
|
export const GET: RequestHandler = async ({ locals }) => {
|
|
const auth = await locals.auth();
|
|
if (!auth?.user?.nickname) throw error(401, 'Not logged in');
|
|
|
|
await dbConnect();
|
|
|
|
const tasks = await Task.find({ active: true })
|
|
.sort({ nextDueDate: 1 })
|
|
.lean();
|
|
|
|
return json({ tasks });
|
|
};
|
|
|
|
export const POST: RequestHandler = async ({ request, locals }) => {
|
|
const auth = await locals.auth();
|
|
if (!auth?.user?.nickname) throw error(401, 'Not logged in');
|
|
|
|
const data = await request.json();
|
|
const { title, description, assignees, tags, difficulty, isRecurring, frequency, nextDueDate } = data;
|
|
|
|
if (!title?.trim()) throw error(400, 'Title is required');
|
|
if (!nextDueDate) throw error(400, 'Due date is required');
|
|
if (isRecurring && !frequency?.type) throw error(400, 'Frequency is required for recurring tasks');
|
|
|
|
await dbConnect();
|
|
|
|
const task = await Task.create({
|
|
title: title.trim(),
|
|
description: description?.trim(),
|
|
assignees: assignees || [],
|
|
tags: tags || [],
|
|
difficulty: difficulty || undefined,
|
|
isRecurring: !!isRecurring,
|
|
frequency: isRecurring ? frequency : undefined,
|
|
nextDueDate: new Date(nextDueDate),
|
|
createdBy: auth.user.nickname,
|
|
active: true
|
|
});
|
|
|
|
return json({ task }, { status: 201 });
|
|
};
|