chore(cleanup): remove dead code and legacy top-estabelecimentos route
This commit is contained in:
@@ -6,16 +6,16 @@ import { fetchIncomeByCategory } from "./categories/income-by-category";
|
||||
import { fetchInstallmentExpenses } from "./expenses/installment-expenses";
|
||||
import { fetchRecurringExpenses } from "./expenses/recurring-expenses";
|
||||
import { fetchTopExpenses } from "./expenses/top-expenses";
|
||||
import { fetchGoalsProgressData } from "./goals-progress";
|
||||
import { fetchIncomeExpenseBalance } from "./income-expense-balance";
|
||||
import { fetchDashboardInvoices } from "./invoices";
|
||||
import { fetchDashboardCardMetrics } from "./metrics";
|
||||
import { fetchDashboardNotifications } from "./notifications";
|
||||
import { fetchDashboardNotes } from "./notes";
|
||||
import { fetchDashboardPagadores } from "./pagadores";
|
||||
import { fetchPaymentConditions } from "./payments/payment-conditions";
|
||||
import { fetchPaymentMethods } from "./payments/payment-methods";
|
||||
import { fetchPaymentStatus } from "./payments/payment-status";
|
||||
import { fetchPurchasesByCategory } from "./purchases-by-category";
|
||||
import { fetchRecentTransactions } from "./recent-transactions";
|
||||
import { fetchTopEstablishments } from "./top-establishments";
|
||||
|
||||
async function fetchDashboardDataInternal(userId: string, period: string) {
|
||||
@@ -24,11 +24,11 @@ async function fetchDashboardDataInternal(userId: string, period: string) {
|
||||
accountsSnapshot,
|
||||
invoicesSnapshot,
|
||||
boletosSnapshot,
|
||||
notificationsSnapshot,
|
||||
goalsProgressData,
|
||||
paymentStatusData,
|
||||
incomeExpenseBalanceData,
|
||||
pagadoresSnapshot,
|
||||
recentTransactionsData,
|
||||
notesData,
|
||||
paymentConditionsData,
|
||||
paymentMethodsData,
|
||||
recurringExpensesData,
|
||||
@@ -44,11 +44,11 @@ async function fetchDashboardDataInternal(userId: string, period: string) {
|
||||
fetchDashboardAccounts(userId),
|
||||
fetchDashboardInvoices(userId, period),
|
||||
fetchDashboardBoletos(userId, period),
|
||||
fetchDashboardNotifications(userId, period),
|
||||
fetchGoalsProgressData(userId, period),
|
||||
fetchPaymentStatus(userId, period),
|
||||
fetchIncomeExpenseBalance(userId, period),
|
||||
fetchDashboardPagadores(userId, period),
|
||||
fetchRecentTransactions(userId, period),
|
||||
fetchDashboardNotes(userId),
|
||||
fetchPaymentConditions(userId, period),
|
||||
fetchPaymentMethods(userId, period),
|
||||
fetchRecurringExpenses(userId, period),
|
||||
@@ -66,11 +66,11 @@ async function fetchDashboardDataInternal(userId: string, period: string) {
|
||||
accountsSnapshot,
|
||||
invoicesSnapshot,
|
||||
boletosSnapshot,
|
||||
notificationsSnapshot,
|
||||
goalsProgressData,
|
||||
paymentStatusData,
|
||||
incomeExpenseBalanceData,
|
||||
pagadoresSnapshot,
|
||||
recentTransactionsData,
|
||||
notesData,
|
||||
paymentConditionsData,
|
||||
paymentMethodsData,
|
||||
recurringExpensesData,
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
import { and, desc, eq, isNull, or, sql } from "drizzle-orm";
|
||||
import { cartoes, contas, lancamentos } from "@/db/schema";
|
||||
import {
|
||||
ACCOUNT_AUTO_INVOICE_NOTE_PREFIX,
|
||||
INITIAL_BALANCE_NOTE,
|
||||
} from "@/lib/accounts/constants";
|
||||
import { toNumber } from "@/lib/dashboard/common";
|
||||
import { db } from "@/lib/db";
|
||||
import { getAdminPagadorId } from "@/lib/pagadores/get-admin-id";
|
||||
|
||||
export type RecentTransaction = {
|
||||
id: string;
|
||||
name: string;
|
||||
amount: number;
|
||||
purchaseDate: Date;
|
||||
cardLogo: string | null;
|
||||
accountLogo: string | null;
|
||||
};
|
||||
|
||||
export type RecentTransactionsData = {
|
||||
transactions: RecentTransaction[];
|
||||
};
|
||||
|
||||
export async function fetchRecentTransactions(
|
||||
userId: string,
|
||||
period: string,
|
||||
): Promise<RecentTransactionsData> {
|
||||
const adminPagadorId = await getAdminPagadorId(userId);
|
||||
if (!adminPagadorId) {
|
||||
return { transactions: [] };
|
||||
}
|
||||
|
||||
const results = await db
|
||||
.select({
|
||||
id: lancamentos.id,
|
||||
name: lancamentos.name,
|
||||
amount: lancamentos.amount,
|
||||
purchaseDate: lancamentos.purchaseDate,
|
||||
cardLogo: cartoes.logo,
|
||||
accountLogo: contas.logo,
|
||||
note: lancamentos.note,
|
||||
})
|
||||
.from(lancamentos)
|
||||
.leftJoin(cartoes, eq(lancamentos.cartaoId, cartoes.id))
|
||||
.leftJoin(contas, eq(lancamentos.contaId, contas.id))
|
||||
.where(
|
||||
and(
|
||||
eq(lancamentos.userId, userId),
|
||||
eq(lancamentos.period, period),
|
||||
eq(lancamentos.transactionType, "Despesa"),
|
||||
eq(lancamentos.pagadorId, adminPagadorId),
|
||||
or(
|
||||
isNull(lancamentos.note),
|
||||
and(
|
||||
sql`${lancamentos.note} != ${INITIAL_BALANCE_NOTE}`,
|
||||
sql`${lancamentos.note} NOT LIKE ${`${ACCOUNT_AUTO_INVOICE_NOTE_PREFIX}%`}`,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
.orderBy(desc(lancamentos.purchaseDate), desc(lancamentos.createdAt))
|
||||
.limit(5);
|
||||
|
||||
const transactions = results.map((row): RecentTransaction => {
|
||||
return {
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
amount: Math.abs(toNumber(row.amount)),
|
||||
purchaseDate: row.purchaseDate,
|
||||
cardLogo: row.cardLogo,
|
||||
accountLogo: row.accountLogo,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
transactions,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user