mirror of
https://github.com/felipegcoutinho/openmonetis.git
synced 2026-05-09 11:01:45 +00:00
refactor(dashboard): reorganizar módulos em subdiretórios e nova arquitetura de widgets
Arquivos de queries, helpers e controllers dispersos na raiz de dashboard/ foram movidos para subdiretórios temáticos (bills/, invoices/, notes/, notifications/, overview/, payments/, goals-progress/, categories/). ~25 widgets monolíticos obsoletos removidos em favor de nova arquitetura baseada em widget-registry com components/widgets/. Novos componentes: category-breakdown-chart/list, goals-progress-item, percentage-change-indicator. Imports atualizados em fetch-dashboard-data e transaction-filters limpos. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
52
src/features/dashboard/notes/notes-queries.ts
Normal file
52
src/features/dashboard/notes/notes-queries.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { notes } from "@/db/schema";
|
||||
import { db } from "@/shared/lib/db";
|
||||
|
||||
export type DashboardTask = {
|
||||
id: string;
|
||||
text: string;
|
||||
completed: boolean;
|
||||
};
|
||||
|
||||
export type DashboardNote = {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
type: "nota" | "tarefa";
|
||||
tasks?: DashboardTask[];
|
||||
archived: boolean;
|
||||
createdAt: string;
|
||||
};
|
||||
|
||||
function parseTasks(value: string | null): DashboardTask[] | undefined {
|
||||
if (!value) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(value);
|
||||
return Array.isArray(parsed) ? parsed : undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchDashboardNotes(
|
||||
userId: string,
|
||||
): Promise<DashboardNote[]> {
|
||||
const noteRows = await db.query.notes.findMany({
|
||||
where: and(eq(notes.userId, userId), eq(notes.archived, false)),
|
||||
orderBy: (note, { desc }) => [desc(note.createdAt)],
|
||||
limit: 5,
|
||||
});
|
||||
|
||||
return noteRows.map((note) => ({
|
||||
id: note.id,
|
||||
title: (note.title ?? "").trim(),
|
||||
description: (note.description ?? "").trim(),
|
||||
type: (note.type ?? "nota") as "nota" | "tarefa",
|
||||
tasks: parseTasks(note.tasks),
|
||||
archived: note.archived,
|
||||
createdAt: note.createdAt.toISOString(),
|
||||
}));
|
||||
}
|
||||
Reference in New Issue
Block a user