chore: prettier everywhere
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { dailyService } from '@/services/task-management/daily';
|
||||
import { getToday, parseDate, isValidAPIDate, createDateFromParts } from '@/lib/date-utils';
|
||||
import {
|
||||
getToday,
|
||||
parseDate,
|
||||
isValidAPIDate,
|
||||
createDateFromParts,
|
||||
} from '@/lib/date-utils';
|
||||
|
||||
/**
|
||||
* API route pour récupérer la vue daily (hier + aujourd'hui)
|
||||
@@ -8,33 +13,36 @@ import { getToday, parseDate, isValidAPIDate, createDateFromParts } from '@/lib/
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
|
||||
|
||||
const action = searchParams.get('action');
|
||||
const date = searchParams.get('date');
|
||||
|
||||
|
||||
if (action === 'history') {
|
||||
// Récupérer l'historique
|
||||
const limit = parseInt(searchParams.get('limit') || '30');
|
||||
const history = await dailyService.getCheckboxHistory(limit);
|
||||
return NextResponse.json(history);
|
||||
}
|
||||
|
||||
|
||||
if (action === 'search') {
|
||||
// Recherche dans les checkboxes
|
||||
const query = searchParams.get('q') || '';
|
||||
const limit = parseInt(searchParams.get('limit') || '20');
|
||||
|
||||
|
||||
if (!query.trim()) {
|
||||
return NextResponse.json({ error: 'Query parameter required' }, { status: 400 });
|
||||
return NextResponse.json(
|
||||
{ error: 'Query parameter required' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
const checkboxes = await dailyService.searchCheckboxes(query, limit);
|
||||
return NextResponse.json(checkboxes);
|
||||
}
|
||||
|
||||
|
||||
// Vue daily pour une date donnée (ou aujourd'hui par défaut)
|
||||
let targetDate: Date;
|
||||
|
||||
|
||||
if (date) {
|
||||
if (!isValidAPIDate(date)) {
|
||||
return NextResponse.json(
|
||||
@@ -46,10 +54,9 @@ export async function GET(request: Request) {
|
||||
} else {
|
||||
targetDate = getToday();
|
||||
}
|
||||
|
||||
|
||||
const dailyView = await dailyService.getDailyView(targetDate);
|
||||
return NextResponse.json(dailyView);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Erreur lors de la récupération du daily:', error);
|
||||
return NextResponse.json(
|
||||
@@ -65,7 +72,7 @@ export async function GET(request: Request) {
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
|
||||
|
||||
// Validation des données
|
||||
if (!body.date || !body.text) {
|
||||
return NextResponse.json(
|
||||
@@ -73,7 +80,7 @@ export async function POST(request: Request) {
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Parser la date de façon plus robuste
|
||||
let date: Date;
|
||||
if (typeof body.date === 'string') {
|
||||
@@ -83,27 +90,26 @@ export async function POST(request: Request) {
|
||||
} else {
|
||||
date = parseDate(body.date);
|
||||
}
|
||||
|
||||
|
||||
if (isNaN(date.getTime())) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Format de date invalide. Utilisez YYYY-MM-DD' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
const checkbox = await dailyService.addCheckbox({
|
||||
date,
|
||||
text: body.text,
|
||||
type: body.type,
|
||||
taskId: body.taskId,
|
||||
order: body.order,
|
||||
isChecked: body.isChecked
|
||||
isChecked: body.isChecked,
|
||||
});
|
||||
|
||||
|
||||
return NextResponse.json(checkbox, { status: 201 });
|
||||
|
||||
} catch (error) {
|
||||
console.error('Erreur lors de l\'ajout de la checkbox:', error);
|
||||
console.error("Erreur lors de l'ajout de la checkbox:", error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Erreur interne du serveur' },
|
||||
{ status: 500 }
|
||||
|
||||
Reference in New Issue
Block a user