refactor: migrate from ESLint to Biome and extract SQL queries to data.ts
- Replace ESLint with Biome for linting and formatting - Configure Biome with tabs, double quotes, and organized imports - Move all SQL/Drizzle queries from page.tsx files to data.ts files - Create new data.ts files for: ajustes, dashboard, relatorios/categorias - Update existing data.ts files: extrato, fatura (add lancamentos queries) - Remove all drizzle-orm imports from page.tsx files - Update README.md with new tooling info Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,149 +1,149 @@
|
||||
"use server";
|
||||
|
||||
import { and, eq, inArray } from "drizzle-orm";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { z } from "zod";
|
||||
import { inboxItems } from "@/db/schema";
|
||||
import { handleActionError } from "@/lib/actions/helpers";
|
||||
import type { ActionResult } from "@/lib/actions/types";
|
||||
import { getUser } from "@/lib/auth/server";
|
||||
import { db } from "@/lib/db";
|
||||
import { and, eq, inArray } from "drizzle-orm";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { z } from "zod";
|
||||
|
||||
const markProcessedSchema = z.object({
|
||||
inboxItemId: z.string().uuid("ID do item inválido"),
|
||||
inboxItemId: z.string().uuid("ID do item inválido"),
|
||||
});
|
||||
|
||||
const discardInboxSchema = z.object({
|
||||
inboxItemId: z.string().uuid("ID do item inválido"),
|
||||
inboxItemId: z.string().uuid("ID do item inválido"),
|
||||
});
|
||||
|
||||
const bulkDiscardSchema = z.object({
|
||||
inboxItemIds: z.array(z.string().uuid()).min(1, "Selecione ao menos um item"),
|
||||
inboxItemIds: z.array(z.string().uuid()).min(1, "Selecione ao menos um item"),
|
||||
});
|
||||
|
||||
function revalidateInbox() {
|
||||
revalidatePath("/pre-lancamentos");
|
||||
revalidatePath("/lancamentos");
|
||||
revalidatePath("/dashboard");
|
||||
revalidatePath("/pre-lancamentos");
|
||||
revalidatePath("/lancamentos");
|
||||
revalidatePath("/dashboard");
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark an inbox item as processed after a lancamento was created
|
||||
*/
|
||||
export async function markInboxAsProcessedAction(
|
||||
input: z.infer<typeof markProcessedSchema>,
|
||||
input: z.infer<typeof markProcessedSchema>,
|
||||
): Promise<ActionResult> {
|
||||
try {
|
||||
const user = await getUser();
|
||||
const data = markProcessedSchema.parse(input);
|
||||
try {
|
||||
const user = await getUser();
|
||||
const data = markProcessedSchema.parse(input);
|
||||
|
||||
// Verificar se item existe e pertence ao usuário
|
||||
const [item] = await db
|
||||
.select()
|
||||
.from(inboxItems)
|
||||
.where(
|
||||
and(
|
||||
eq(inboxItems.id, data.inboxItemId),
|
||||
eq(inboxItems.userId, user.id),
|
||||
eq(inboxItems.status, "pending"),
|
||||
),
|
||||
)
|
||||
.limit(1);
|
||||
// Verificar se item existe e pertence ao usuário
|
||||
const [item] = await db
|
||||
.select()
|
||||
.from(inboxItems)
|
||||
.where(
|
||||
and(
|
||||
eq(inboxItems.id, data.inboxItemId),
|
||||
eq(inboxItems.userId, user.id),
|
||||
eq(inboxItems.status, "pending"),
|
||||
),
|
||||
)
|
||||
.limit(1);
|
||||
|
||||
if (!item) {
|
||||
return { success: false, error: "Item não encontrado ou já processado." };
|
||||
}
|
||||
if (!item) {
|
||||
return { success: false, error: "Item não encontrado ou já processado." };
|
||||
}
|
||||
|
||||
// Marcar item como processado
|
||||
await db
|
||||
.update(inboxItems)
|
||||
.set({
|
||||
status: "processed",
|
||||
processedAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.where(eq(inboxItems.id, data.inboxItemId));
|
||||
// Marcar item como processado
|
||||
await db
|
||||
.update(inboxItems)
|
||||
.set({
|
||||
status: "processed",
|
||||
processedAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.where(eq(inboxItems.id, data.inboxItemId));
|
||||
|
||||
revalidateInbox();
|
||||
revalidateInbox();
|
||||
|
||||
return { success: true, message: "Item processado com sucesso!" };
|
||||
} catch (error) {
|
||||
return handleActionError(error);
|
||||
}
|
||||
return { success: true, message: "Item processado com sucesso!" };
|
||||
} catch (error) {
|
||||
return handleActionError(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function discardInboxItemAction(
|
||||
input: z.infer<typeof discardInboxSchema>,
|
||||
input: z.infer<typeof discardInboxSchema>,
|
||||
): Promise<ActionResult> {
|
||||
try {
|
||||
const user = await getUser();
|
||||
const data = discardInboxSchema.parse(input);
|
||||
try {
|
||||
const user = await getUser();
|
||||
const data = discardInboxSchema.parse(input);
|
||||
|
||||
// Verificar se item existe e pertence ao usuário
|
||||
const [item] = await db
|
||||
.select()
|
||||
.from(inboxItems)
|
||||
.where(
|
||||
and(
|
||||
eq(inboxItems.id, data.inboxItemId),
|
||||
eq(inboxItems.userId, user.id),
|
||||
eq(inboxItems.status, "pending"),
|
||||
),
|
||||
)
|
||||
.limit(1);
|
||||
// Verificar se item existe e pertence ao usuário
|
||||
const [item] = await db
|
||||
.select()
|
||||
.from(inboxItems)
|
||||
.where(
|
||||
and(
|
||||
eq(inboxItems.id, data.inboxItemId),
|
||||
eq(inboxItems.userId, user.id),
|
||||
eq(inboxItems.status, "pending"),
|
||||
),
|
||||
)
|
||||
.limit(1);
|
||||
|
||||
if (!item) {
|
||||
return { success: false, error: "Item não encontrado ou já processado." };
|
||||
}
|
||||
if (!item) {
|
||||
return { success: false, error: "Item não encontrado ou já processado." };
|
||||
}
|
||||
|
||||
// Marcar item como descartado
|
||||
await db
|
||||
.update(inboxItems)
|
||||
.set({
|
||||
status: "discarded",
|
||||
discardedAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.where(eq(inboxItems.id, data.inboxItemId));
|
||||
// Marcar item como descartado
|
||||
await db
|
||||
.update(inboxItems)
|
||||
.set({
|
||||
status: "discarded",
|
||||
discardedAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.where(eq(inboxItems.id, data.inboxItemId));
|
||||
|
||||
revalidateInbox();
|
||||
revalidateInbox();
|
||||
|
||||
return { success: true, message: "Item descartado." };
|
||||
} catch (error) {
|
||||
return handleActionError(error);
|
||||
}
|
||||
return { success: true, message: "Item descartado." };
|
||||
} catch (error) {
|
||||
return handleActionError(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function bulkDiscardInboxItemsAction(
|
||||
input: z.infer<typeof bulkDiscardSchema>,
|
||||
input: z.infer<typeof bulkDiscardSchema>,
|
||||
): Promise<ActionResult> {
|
||||
try {
|
||||
const user = await getUser();
|
||||
const data = bulkDiscardSchema.parse(input);
|
||||
try {
|
||||
const user = await getUser();
|
||||
const data = bulkDiscardSchema.parse(input);
|
||||
|
||||
// Marcar todos os itens como descartados
|
||||
await db
|
||||
.update(inboxItems)
|
||||
.set({
|
||||
status: "discarded",
|
||||
discardedAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.where(
|
||||
and(
|
||||
inArray(inboxItems.id, data.inboxItemIds),
|
||||
eq(inboxItems.userId, user.id),
|
||||
eq(inboxItems.status, "pending"),
|
||||
),
|
||||
);
|
||||
// Marcar todos os itens como descartados
|
||||
await db
|
||||
.update(inboxItems)
|
||||
.set({
|
||||
status: "discarded",
|
||||
discardedAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.where(
|
||||
and(
|
||||
inArray(inboxItems.id, data.inboxItemIds),
|
||||
eq(inboxItems.userId, user.id),
|
||||
eq(inboxItems.status, "pending"),
|
||||
),
|
||||
);
|
||||
|
||||
revalidateInbox();
|
||||
revalidateInbox();
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `${data.inboxItemIds.length} item(s) descartado(s).`,
|
||||
};
|
||||
} catch (error) {
|
||||
return handleActionError(error);
|
||||
}
|
||||
return {
|
||||
success: true,
|
||||
message: `${data.inboxItemIds.length} item(s) descartado(s).`,
|
||||
};
|
||||
} catch (error) {
|
||||
return handleActionError(error);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user