- Migrate due_date/next_occurrence columns from TIMESTAMPTZ to DATE - Update serializeRow() to distinguish DATE vs TIMESTAMPTZ serialization - Simplify frontend date parsing (no more timezone workarounds) - Add Vitest + Testing Library test infrastructure - Add initial date parsing/formatting unit tests - Update package.json with dev dependencies (vitest, testing-library, jsdom)
65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { Pool } from 'pg';
|
|
|
|
const pool = new Pool({
|
|
connectionString: process.env.DATABASE_URL || 'postgresql://vixtix:vixtix_secret@localhost:5433/vixtix',
|
|
});
|
|
|
|
function serializeRow(row: Record<string, any>): Record<string, any> {
|
|
const toCamel = (str: string) => str.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
const result: Record<string, any> = {};
|
|
for (const [key, value] of Object.entries(row)) {
|
|
const camelKey = toCamel(key);
|
|
if (value instanceof Date && !isNaN(value.getTime())) {
|
|
if (value.getUTCHours() === 0 && value.getUTCMinutes() === 0 && value.getUTCSeconds() === 0 && value.getUTCMilliseconds() === 0) {
|
|
const year = value.getUTCFullYear();
|
|
const month = String(value.getUTCMonth() + 1).padStart(2, '0');
|
|
const day = String(value.getUTCDate()).padStart(2, '0');
|
|
result[camelKey] = `${year}-${month}-${day}`;
|
|
} else {
|
|
result[camelKey] = value.toISOString();
|
|
}
|
|
} else {
|
|
result[camelKey] = value;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
export async function GET(request: NextRequest) {
|
|
const { searchParams } = new URL(request.url);
|
|
const projectId = searchParams.get('project');
|
|
|
|
try {
|
|
let whereClause = 'parent_task_id IS NULL';
|
|
let params: any[] = [];
|
|
let paramIndex = 1;
|
|
|
|
if (projectId) {
|
|
whereClause += ` AND project_id = $${paramIndex++}`;
|
|
params.push(projectId);
|
|
}
|
|
|
|
const result = await pool.query(
|
|
`SELECT t.*, p.color as project_color, p.name as project_name
|
|
FROM tasks t
|
|
LEFT JOIN projects p ON t.project_id = p.id
|
|
WHERE ${whereClause}
|
|
ORDER BY t.sort_order`,
|
|
params
|
|
);
|
|
|
|
const rows = result.rows.map(serializeRow);
|
|
const grouped = {
|
|
todo: rows.filter((t: any) => t.status === 'todo'),
|
|
in_progress: rows.filter((t: any) => t.status === 'in_progress'),
|
|
done: rows.filter((t: any) => t.status === 'done'),
|
|
};
|
|
|
|
return NextResponse.json(grouped);
|
|
} catch (error) {
|
|
console.error('Error fetching kanban data:', error);
|
|
return NextResponse.json({ error: 'Failed to fetch kanban data' }, { status: 500 });
|
|
}
|
|
}
|