refactor: atualizar imports para os novos nomes de tabelas
- Atualizar imports em todos os arquivos que usavam os nomes antigos - Corrigir referências para preferenciasUsuario, insightsSalvos, tokensApi, preLancamentos, antecipacoesParcelas, compartilhamentosPagador
This commit is contained in:
@@ -1,14 +1,14 @@
|
|||||||
"use server";
|
"use server";
|
||||||
|
|
||||||
import { apiTokens, pagadores } from "@/db/schema";
|
import { createHash, randomBytes } from "node:crypto";
|
||||||
import { auth } from "@/lib/auth/config";
|
|
||||||
import { db, schema } from "@/lib/db";
|
|
||||||
import { PAGADOR_ROLE_ADMIN } from "@/lib/pagadores/constants";
|
|
||||||
import { and, eq, isNull, ne } from "drizzle-orm";
|
import { and, eq, isNull, ne } from "drizzle-orm";
|
||||||
import { revalidatePath } from "next/cache";
|
import { revalidatePath } from "next/cache";
|
||||||
import { headers } from "next/headers";
|
import { headers } from "next/headers";
|
||||||
import { createHash, randomBytes } from "node:crypto";
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
import { tokensApi, pagadores } from "@/db/schema";
|
||||||
|
import { auth } from "@/lib/auth/config";
|
||||||
|
import { db, schema } from "@/lib/db";
|
||||||
|
import { PAGADOR_ROLE_ADMIN } from "@/lib/pagadores/constants";
|
||||||
|
|
||||||
type ActionResponse<T = void> = {
|
type ActionResponse<T = void> = {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
@@ -373,8 +373,8 @@ export async function updatePreferencesAction(
|
|||||||
// Check if preferences exist, if not create them
|
// Check if preferences exist, if not create them
|
||||||
const existingResult = await db
|
const existingResult = await db
|
||||||
.select()
|
.select()
|
||||||
.from(schema.userPreferences)
|
.from(schema.preferenciasUsuario)
|
||||||
.where(eq(schema.userPreferences.userId, session.user.id))
|
.where(eq(schema.preferenciasUsuario.userId, session.user.id))
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
const existing = existingResult[0] || null;
|
const existing = existingResult[0] || null;
|
||||||
@@ -382,15 +382,15 @@ export async function updatePreferencesAction(
|
|||||||
if (existing) {
|
if (existing) {
|
||||||
// Update existing preferences
|
// Update existing preferences
|
||||||
await db
|
await db
|
||||||
.update(schema.userPreferences)
|
.update(schema.preferenciasUsuario)
|
||||||
.set({
|
.set({
|
||||||
disableMagnetlines: validated.disableMagnetlines,
|
disableMagnetlines: validated.disableMagnetlines,
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
})
|
})
|
||||||
.where(eq(schema.userPreferences.userId, session.user.id));
|
.where(eq(schema.preferenciasUsuario.userId, session.user.id));
|
||||||
} else {
|
} else {
|
||||||
// Create new preferences
|
// Create new preferences
|
||||||
await db.insert(schema.userPreferences).values({
|
await db.insert(schema.preferenciasUsuario).values({
|
||||||
userId: session.user.id,
|
userId: session.user.id,
|
||||||
disableMagnetlines: validated.disableMagnetlines,
|
disableMagnetlines: validated.disableMagnetlines,
|
||||||
});
|
});
|
||||||
@@ -463,7 +463,7 @@ export async function createApiTokenAction(
|
|||||||
|
|
||||||
// Save to database
|
// Save to database
|
||||||
const [newToken] = await db
|
const [newToken] = await db
|
||||||
.insert(apiTokens)
|
.insert(tokensApi)
|
||||||
.values({
|
.values({
|
||||||
userId: session.user.id,
|
userId: session.user.id,
|
||||||
name: validated.name,
|
name: validated.name,
|
||||||
@@ -471,7 +471,7 @@ export async function createApiTokenAction(
|
|||||||
tokenPrefix,
|
tokenPrefix,
|
||||||
expiresAt: null, // No expiration for now
|
expiresAt: null, // No expiration for now
|
||||||
})
|
})
|
||||||
.returning({ id: apiTokens.id });
|
.returning({ id: tokensApi.id });
|
||||||
|
|
||||||
revalidatePath("/ajustes");
|
revalidatePath("/ajustes");
|
||||||
|
|
||||||
@@ -519,12 +519,12 @@ export async function revokeApiTokenAction(
|
|||||||
// Find token and verify ownership
|
// Find token and verify ownership
|
||||||
const [existingToken] = await db
|
const [existingToken] = await db
|
||||||
.select()
|
.select()
|
||||||
.from(apiTokens)
|
.from(tokensApi)
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(apiTokens.id, validated.tokenId),
|
eq(tokensApi.id, validated.tokenId),
|
||||||
eq(apiTokens.userId, session.user.id),
|
eq(tokensApi.userId, session.user.id),
|
||||||
isNull(apiTokens.revokedAt),
|
isNull(tokensApi.revokedAt),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.limit(1);
|
.limit(1);
|
||||||
@@ -538,11 +538,11 @@ export async function revokeApiTokenAction(
|
|||||||
|
|
||||||
// Revoke token
|
// Revoke token
|
||||||
await db
|
await db
|
||||||
.update(apiTokens)
|
.update(tokensApi)
|
||||||
.set({
|
.set({
|
||||||
revokedAt: new Date(),
|
revokedAt: new Date(),
|
||||||
})
|
})
|
||||||
.where(eq(apiTokens.id, validated.tokenId));
|
.where(eq(tokensApi.id, validated.tokenId));
|
||||||
|
|
||||||
revalidatePath("/ajustes");
|
revalidatePath("/ajustes");
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { desc, eq } from "drizzle-orm";
|
import { desc, eq } from "drizzle-orm";
|
||||||
import { apiTokens } from "@/db/schema";
|
import { tokensApi } from "@/db/schema";
|
||||||
import { db, schema } from "@/lib/db";
|
import { db, schema } from "@/lib/db";
|
||||||
|
|
||||||
export interface UserPreferences {
|
export interface UserPreferences {
|
||||||
@@ -29,10 +29,10 @@ export async function fetchUserPreferences(
|
|||||||
): Promise<UserPreferences | null> {
|
): Promise<UserPreferences | null> {
|
||||||
const result = await db
|
const result = await db
|
||||||
.select({
|
.select({
|
||||||
disableMagnetlines: schema.userPreferences.disableMagnetlines,
|
disableMagnetlines: schema.preferenciasUsuario.disableMagnetlines,
|
||||||
})
|
})
|
||||||
.from(schema.userPreferences)
|
.from(schema.preferenciasUsuario)
|
||||||
.where(eq(schema.userPreferences.userId, userId))
|
.where(eq(schema.preferenciasUsuario.userId, userId))
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
return result[0] || null;
|
return result[0] || null;
|
||||||
@@ -41,18 +41,18 @@ export async function fetchUserPreferences(
|
|||||||
export async function fetchApiTokens(userId: string): Promise<ApiToken[]> {
|
export async function fetchApiTokens(userId: string): Promise<ApiToken[]> {
|
||||||
return db
|
return db
|
||||||
.select({
|
.select({
|
||||||
id: apiTokens.id,
|
id: tokensApi.id,
|
||||||
name: apiTokens.name,
|
name: tokensApi.name,
|
||||||
tokenPrefix: apiTokens.tokenPrefix,
|
tokenPrefix: tokensApi.tokenPrefix,
|
||||||
lastUsedAt: apiTokens.lastUsedAt,
|
lastUsedAt: tokensApi.lastUsedAt,
|
||||||
lastUsedIp: apiTokens.lastUsedIp,
|
lastUsedIp: tokensApi.lastUsedIp,
|
||||||
createdAt: apiTokens.createdAt,
|
createdAt: tokensApi.createdAt,
|
||||||
expiresAt: apiTokens.expiresAt,
|
expiresAt: tokensApi.expiresAt,
|
||||||
revokedAt: apiTokens.revokedAt,
|
revokedAt: tokensApi.revokedAt,
|
||||||
})
|
})
|
||||||
.from(apiTokens)
|
.from(tokensApi)
|
||||||
.where(eq(apiTokens.userId, userId))
|
.where(eq(tokensApi.userId, userId))
|
||||||
.orderBy(desc(apiTokens.createdAt));
|
.orderBy(desc(tokensApi.createdAt));
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchAjustesPageData(userId: string) {
|
export async function fetchAjustesPageData(userId: string) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
import { and, eq, ilike, isNull, not, or, sql } from "drizzle-orm";
|
||||||
import { cartoes, contas, lancamentos } from "@/db/schema";
|
import { cartoes, contas, lancamentos } from "@/db/schema";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
import { loadLogoOptions } from "@/lib/logo/options";
|
import { loadLogoOptions } from "@/lib/logo/options";
|
||||||
import { and, eq, ilike, isNull, not, or, sql } from "drizzle-orm";
|
|
||||||
|
|
||||||
export type CardData = {
|
export type CardData = {
|
||||||
id: string;
|
id: string;
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
import { Skeleton } from "@/components/ui/skeleton";
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
|
|
||||||
/**
|
|
||||||
* Loading state para a página de categorias
|
|
||||||
* Layout: Header + Tabs + Grid de cards
|
|
||||||
*/
|
|
||||||
export default function CategoriasLoading() {
|
export default function CategoriasLoading() {
|
||||||
return (
|
return (
|
||||||
<main className="flex flex-col items-start gap-6">
|
<main className="flex flex-col items-start gap-6">
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import { Skeleton } from "@/components/ui/skeleton";
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
|
|
||||||
/**
|
|
||||||
* Loading state para a página de contas
|
|
||||||
*/
|
|
||||||
export default function ContasLoading() {
|
export default function ContasLoading() {
|
||||||
return (
|
return (
|
||||||
<main className="flex flex-col gap-6">
|
<main className="flex flex-col gap-6">
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ export async function fetchUserDashboardPreferences(
|
|||||||
): Promise<UserDashboardPreferences> {
|
): Promise<UserDashboardPreferences> {
|
||||||
const result = await db
|
const result = await db
|
||||||
.select({
|
.select({
|
||||||
disableMagnetlines: schema.userPreferences.disableMagnetlines,
|
disableMagnetlines: schema.preferenciasUsuario.disableMagnetlines,
|
||||||
dashboardWidgets: schema.userPreferences.dashboardWidgets,
|
dashboardWidgets: schema.preferenciasUsuario.dashboardWidgets,
|
||||||
})
|
})
|
||||||
.from(schema.userPreferences)
|
.from(schema.preferenciasUsuario)
|
||||||
.where(eq(schema.userPreferences.userId, userId))
|
.where(eq(schema.preferenciasUsuario.userId, userId))
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
lancamentos,
|
lancamentos,
|
||||||
orcamentos,
|
orcamentos,
|
||||||
pagadores,
|
pagadores,
|
||||||
savedInsights,
|
insightsSalvos,
|
||||||
} from "@/db/schema";
|
} from "@/db/schema";
|
||||||
import { ACCOUNT_AUTO_INVOICE_NOTE_PREFIX } from "@/lib/accounts/constants";
|
import { ACCOUNT_AUTO_INVOICE_NOTE_PREFIX } from "@/lib/accounts/constants";
|
||||||
import { getUser } from "@/lib/auth/server";
|
import { getUser } from "@/lib/auth/server";
|
||||||
@@ -697,11 +697,11 @@ export async function saveInsightsAction(
|
|||||||
// Verificar se já existe um insight salvo para este período
|
// Verificar se já existe um insight salvo para este período
|
||||||
const existing = await db
|
const existing = await db
|
||||||
.select()
|
.select()
|
||||||
.from(savedInsights)
|
.from(insightsSalvos)
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(savedInsights.userId, user.id),
|
eq(insightsSalvos.userId, user.id),
|
||||||
eq(savedInsights.period, period),
|
eq(insightsSalvos.period, period),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.limit(1);
|
.limit(1);
|
||||||
@@ -709,7 +709,7 @@ export async function saveInsightsAction(
|
|||||||
if (existing.length > 0) {
|
if (existing.length > 0) {
|
||||||
// Atualizar existente
|
// Atualizar existente
|
||||||
const updated = await db
|
const updated = await db
|
||||||
.update(savedInsights)
|
.update(insightsSalvos)
|
||||||
.set({
|
.set({
|
||||||
modelId,
|
modelId,
|
||||||
data: JSON.stringify(data),
|
data: JSON.stringify(data),
|
||||||
@@ -717,13 +717,13 @@ export async function saveInsightsAction(
|
|||||||
})
|
})
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(savedInsights.userId, user.id),
|
eq(insightsSalvos.userId, user.id),
|
||||||
eq(savedInsights.period, period),
|
eq(insightsSalvos.period, period),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.returning({
|
.returning({
|
||||||
id: savedInsights.id,
|
id: insightsSalvos.id,
|
||||||
createdAt: savedInsights.createdAt,
|
createdAt: insightsSalvos.createdAt,
|
||||||
});
|
});
|
||||||
|
|
||||||
const updatedRecord = updated[0];
|
const updatedRecord = updated[0];
|
||||||
@@ -745,14 +745,14 @@ export async function saveInsightsAction(
|
|||||||
|
|
||||||
// Criar novo
|
// Criar novo
|
||||||
const result = await db
|
const result = await db
|
||||||
.insert(savedInsights)
|
.insert(insightsSalvos)
|
||||||
.values({
|
.values({
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
period,
|
period,
|
||||||
modelId,
|
modelId,
|
||||||
data: JSON.stringify(data),
|
data: JSON.stringify(data),
|
||||||
})
|
})
|
||||||
.returning({ id: savedInsights.id, createdAt: savedInsights.createdAt });
|
.returning({ id: insightsSalvos.id, createdAt: insightsSalvos.createdAt });
|
||||||
|
|
||||||
const insertedRecord = result[0];
|
const insertedRecord = result[0];
|
||||||
if (!insertedRecord) {
|
if (!insertedRecord) {
|
||||||
@@ -796,11 +796,11 @@ export async function loadSavedInsightsAction(period: string): Promise<
|
|||||||
|
|
||||||
const result = await db
|
const result = await db
|
||||||
.select()
|
.select()
|
||||||
.from(savedInsights)
|
.from(insightsSalvos)
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(savedInsights.userId, user.id),
|
eq(insightsSalvos.userId, user.id),
|
||||||
eq(savedInsights.period, period),
|
eq(insightsSalvos.period, period),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.limit(1);
|
.limit(1);
|
||||||
@@ -852,11 +852,11 @@ export async function deleteSavedInsightsAction(
|
|||||||
const user = await getUser();
|
const user = await getUser();
|
||||||
|
|
||||||
await db
|
await db
|
||||||
.delete(savedInsights)
|
.delete(insightsSalvos)
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(savedInsights.userId, user.id),
|
eq(insightsSalvos.userId, user.id),
|
||||||
eq(savedInsights.period, period),
|
eq(insightsSalvos.period, period),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { revalidatePath } from "next/cache";
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import {
|
import {
|
||||||
categorias,
|
categorias,
|
||||||
installmentAnticipations,
|
antecipacoesParcelas,
|
||||||
lancamentos,
|
lancamentos,
|
||||||
pagadores,
|
pagadores,
|
||||||
} from "@/db/schema";
|
} from "@/db/schema";
|
||||||
@@ -235,7 +235,7 @@ export async function createInstallmentAnticipationAction(
|
|||||||
|
|
||||||
// 4.2. Criar registro de antecipação
|
// 4.2. Criar registro de antecipação
|
||||||
const [anticipation] = await tx
|
const [anticipation] = await tx
|
||||||
.insert(installmentAnticipations)
|
.insert(antecipacoesParcelas)
|
||||||
.values({
|
.values({
|
||||||
seriesId: data.seriesId,
|
seriesId: data.seriesId,
|
||||||
anticipationPeriod: data.anticipationPeriod,
|
anticipationPeriod: data.anticipationPeriod,
|
||||||
@@ -294,43 +294,43 @@ export async function getInstallmentAnticipationsAction(
|
|||||||
// Usar query builder ao invés de db.query para evitar problemas de tipagem
|
// Usar query builder ao invés de db.query para evitar problemas de tipagem
|
||||||
const anticipations = await db
|
const anticipations = await db
|
||||||
.select({
|
.select({
|
||||||
id: installmentAnticipations.id,
|
id: antecipacoesParcelas.id,
|
||||||
seriesId: installmentAnticipations.seriesId,
|
seriesId: antecipacoesParcelas.seriesId,
|
||||||
anticipationPeriod: installmentAnticipations.anticipationPeriod,
|
anticipationPeriod: antecipacoesParcelas.anticipationPeriod,
|
||||||
anticipationDate: installmentAnticipations.anticipationDate,
|
anticipationDate: antecipacoesParcelas.anticipationDate,
|
||||||
anticipatedInstallmentIds:
|
anticipatedInstallmentIds:
|
||||||
installmentAnticipations.anticipatedInstallmentIds,
|
antecipacoesParcelas.anticipatedInstallmentIds,
|
||||||
totalAmount: installmentAnticipations.totalAmount,
|
totalAmount: antecipacoesParcelas.totalAmount,
|
||||||
installmentCount: installmentAnticipations.installmentCount,
|
installmentCount: antecipacoesParcelas.installmentCount,
|
||||||
discount: installmentAnticipations.discount,
|
discount: antecipacoesParcelas.discount,
|
||||||
lancamentoId: installmentAnticipations.lancamentoId,
|
lancamentoId: antecipacoesParcelas.lancamentoId,
|
||||||
pagadorId: installmentAnticipations.pagadorId,
|
pagadorId: antecipacoesParcelas.pagadorId,
|
||||||
categoriaId: installmentAnticipations.categoriaId,
|
categoriaId: antecipacoesParcelas.categoriaId,
|
||||||
note: installmentAnticipations.note,
|
note: antecipacoesParcelas.note,
|
||||||
userId: installmentAnticipations.userId,
|
userId: antecipacoesParcelas.userId,
|
||||||
createdAt: installmentAnticipations.createdAt,
|
createdAt: antecipacoesParcelas.createdAt,
|
||||||
// Joins
|
// Joins
|
||||||
lancamento: lancamentos,
|
lancamento: lancamentos,
|
||||||
pagador: pagadores,
|
pagador: pagadores,
|
||||||
categoria: categorias,
|
categoria: categorias,
|
||||||
})
|
})
|
||||||
.from(installmentAnticipations)
|
.from(antecipacoesParcelas)
|
||||||
.leftJoin(
|
.leftJoin(
|
||||||
lancamentos,
|
lancamentos,
|
||||||
eq(installmentAnticipations.lancamentoId, lancamentos.id),
|
eq(antecipacoesParcelas.lancamentoId, lancamentos.id),
|
||||||
)
|
)
|
||||||
.leftJoin(pagadores, eq(installmentAnticipations.pagadorId, pagadores.id))
|
.leftJoin(pagadores, eq(antecipacoesParcelas.pagadorId, pagadores.id))
|
||||||
.leftJoin(
|
.leftJoin(
|
||||||
categorias,
|
categorias,
|
||||||
eq(installmentAnticipations.categoriaId, categorias.id),
|
eq(antecipacoesParcelas.categoriaId, categorias.id),
|
||||||
)
|
)
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(installmentAnticipations.seriesId, validatedSeriesId),
|
eq(antecipacoesParcelas.seriesId, validatedSeriesId),
|
||||||
eq(installmentAnticipations.userId, user.id),
|
eq(antecipacoesParcelas.userId, user.id),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.orderBy(desc(installmentAnticipations.createdAt));
|
.orderBy(desc(antecipacoesParcelas.createdAt));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
@@ -356,32 +356,32 @@ export async function cancelInstallmentAnticipationAction(
|
|||||||
// 1. Buscar antecipação usando query builder
|
// 1. Buscar antecipação usando query builder
|
||||||
const anticipationRows = await tx
|
const anticipationRows = await tx
|
||||||
.select({
|
.select({
|
||||||
id: installmentAnticipations.id,
|
id: antecipacoesParcelas.id,
|
||||||
seriesId: installmentAnticipations.seriesId,
|
seriesId: antecipacoesParcelas.seriesId,
|
||||||
anticipationPeriod: installmentAnticipations.anticipationPeriod,
|
anticipationPeriod: antecipacoesParcelas.anticipationPeriod,
|
||||||
anticipationDate: installmentAnticipations.anticipationDate,
|
anticipationDate: antecipacoesParcelas.anticipationDate,
|
||||||
anticipatedInstallmentIds:
|
anticipatedInstallmentIds:
|
||||||
installmentAnticipations.anticipatedInstallmentIds,
|
antecipacoesParcelas.anticipatedInstallmentIds,
|
||||||
totalAmount: installmentAnticipations.totalAmount,
|
totalAmount: antecipacoesParcelas.totalAmount,
|
||||||
installmentCount: installmentAnticipations.installmentCount,
|
installmentCount: antecipacoesParcelas.installmentCount,
|
||||||
discount: installmentAnticipations.discount,
|
discount: antecipacoesParcelas.discount,
|
||||||
lancamentoId: installmentAnticipations.lancamentoId,
|
lancamentoId: antecipacoesParcelas.lancamentoId,
|
||||||
pagadorId: installmentAnticipations.pagadorId,
|
pagadorId: antecipacoesParcelas.pagadorId,
|
||||||
categoriaId: installmentAnticipations.categoriaId,
|
categoriaId: antecipacoesParcelas.categoriaId,
|
||||||
note: installmentAnticipations.note,
|
note: antecipacoesParcelas.note,
|
||||||
userId: installmentAnticipations.userId,
|
userId: antecipacoesParcelas.userId,
|
||||||
createdAt: installmentAnticipations.createdAt,
|
createdAt: antecipacoesParcelas.createdAt,
|
||||||
lancamento: lancamentos,
|
lancamento: lancamentos,
|
||||||
})
|
})
|
||||||
.from(installmentAnticipations)
|
.from(antecipacoesParcelas)
|
||||||
.leftJoin(
|
.leftJoin(
|
||||||
lancamentos,
|
lancamentos,
|
||||||
eq(installmentAnticipations.lancamentoId, lancamentos.id),
|
eq(antecipacoesParcelas.lancamentoId, lancamentos.id),
|
||||||
)
|
)
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(installmentAnticipations.id, data.anticipationId),
|
eq(antecipacoesParcelas.id, data.anticipationId),
|
||||||
eq(installmentAnticipations.userId, user.id),
|
eq(antecipacoesParcelas.userId, user.id),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.limit(1);
|
.limit(1);
|
||||||
@@ -426,8 +426,8 @@ export async function cancelInstallmentAnticipationAction(
|
|||||||
|
|
||||||
// 6. Deletar registro de antecipação
|
// 6. Deletar registro de antecipação
|
||||||
await tx
|
await tx
|
||||||
.delete(installmentAnticipations)
|
.delete(antecipacoesParcelas)
|
||||||
.where(eq(installmentAnticipations.id, data.anticipationId));
|
.where(eq(antecipacoesParcelas.id, data.anticipationId));
|
||||||
});
|
});
|
||||||
|
|
||||||
revalidatePath("/lancamentos");
|
revalidatePath("/lancamentos");
|
||||||
@@ -454,10 +454,10 @@ export async function getAnticipationDetailsAction(
|
|||||||
// Validar anticipationId
|
// Validar anticipationId
|
||||||
const validatedId = uuidSchema("Antecipação").parse(anticipationId);
|
const validatedId = uuidSchema("Antecipação").parse(anticipationId);
|
||||||
|
|
||||||
const anticipation = await db.query.installmentAnticipations.findFirst({
|
const anticipation = await db.query.antecipacoesParcelas.findFirst({
|
||||||
where: and(
|
where: and(
|
||||||
eq(installmentAnticipations.id, validatedId),
|
eq(antecipacoesParcelas.id, validatedId),
|
||||||
eq(installmentAnticipations.userId, user.id),
|
eq(antecipacoesParcelas.userId, user.id),
|
||||||
),
|
),
|
||||||
with: {
|
with: {
|
||||||
lancamento: true,
|
lancamento: true,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
contas,
|
contas,
|
||||||
lancamentos,
|
lancamentos,
|
||||||
pagadores,
|
pagadores,
|
||||||
pagadorShares,
|
compartilhamentosPagador,
|
||||||
user as usersTable,
|
user as usersTable,
|
||||||
} from "@/db/schema";
|
} from "@/db/schema";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
@@ -23,15 +23,15 @@ export async function fetchPagadorShares(
|
|||||||
): Promise<ShareData[]> {
|
): Promise<ShareData[]> {
|
||||||
const shareRows = await db
|
const shareRows = await db
|
||||||
.select({
|
.select({
|
||||||
id: pagadorShares.id,
|
id: compartilhamentosPagador.id,
|
||||||
sharedWithUserId: pagadorShares.sharedWithUserId,
|
sharedWithUserId: compartilhamentosPagador.sharedWithUserId,
|
||||||
createdAt: pagadorShares.createdAt,
|
createdAt: compartilhamentosPagador.createdAt,
|
||||||
userName: usersTable.name,
|
userName: usersTable.name,
|
||||||
userEmail: usersTable.email,
|
userEmail: usersTable.email,
|
||||||
})
|
})
|
||||||
.from(pagadorShares)
|
.from(compartilhamentosPagador)
|
||||||
.innerJoin(usersTable, eq(pagadorShares.sharedWithUserId, usersTable.id))
|
.innerJoin(usersTable, eq(compartilhamentosPagador.sharedWithUserId, usersTable.id))
|
||||||
.where(eq(pagadorShares.pagadorId, pagadorId));
|
.where(eq(compartilhamentosPagador.pagadorId, pagadorId));
|
||||||
|
|
||||||
return shareRows.map((share) => ({
|
return shareRows.map((share) => ({
|
||||||
id: share.id,
|
id: share.id,
|
||||||
@@ -46,14 +46,14 @@ export async function fetchCurrentUserShare(
|
|||||||
pagadorId: string,
|
pagadorId: string,
|
||||||
userId: string,
|
userId: string,
|
||||||
): Promise<{ id: string; createdAt: string } | null> {
|
): Promise<{ id: string; createdAt: string } | null> {
|
||||||
const shareRow = await db.query.pagadorShares.findFirst({
|
const shareRow = await db.query.compartilhamentosPagador.findFirst({
|
||||||
columns: {
|
columns: {
|
||||||
id: true,
|
id: true,
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
},
|
},
|
||||||
where: and(
|
where: and(
|
||||||
eq(pagadorShares.pagadorId, pagadorId),
|
eq(compartilhamentosPagador.pagadorId, pagadorId),
|
||||||
eq(pagadorShares.sharedWithUserId, userId),
|
eq(compartilhamentosPagador.sharedWithUserId, userId),
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { randomBytes } from "node:crypto";
|
|||||||
import { and, eq } from "drizzle-orm";
|
import { and, eq } from "drizzle-orm";
|
||||||
import { revalidatePath } from "next/cache";
|
import { revalidatePath } from "next/cache";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { pagadores, pagadorShares, user } from "@/db/schema";
|
import { pagadores, compartilhamentosPagador, user } from "@/db/schema";
|
||||||
import { handleActionError, revalidateForEntity } from "@/lib/actions/helpers";
|
import { handleActionError, revalidateForEntity } from "@/lib/actions/helpers";
|
||||||
import type { ActionResult } from "@/lib/actions/types";
|
import type { ActionResult } from "@/lib/actions/types";
|
||||||
import { getUser } from "@/lib/auth/server";
|
import { getUser } from "@/lib/auth/server";
|
||||||
@@ -223,10 +223,10 @@ export async function joinPagadorByShareCodeAction(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const existingShare = await db.query.pagadorShares.findFirst({
|
const existingShare = await db.query.compartilhamentosPagador.findFirst({
|
||||||
where: and(
|
where: and(
|
||||||
eq(pagadorShares.pagadorId, pagadorRow.id),
|
eq(compartilhamentosPagador.pagadorId, pagadorRow.id),
|
||||||
eq(pagadorShares.sharedWithUserId, user.id),
|
eq(compartilhamentosPagador.sharedWithUserId, user.id),
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -237,7 +237,7 @@ export async function joinPagadorByShareCodeAction(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
await db.insert(pagadorShares).values({
|
await db.insert(compartilhamentosPagador).values({
|
||||||
pagadorId: pagadorRow.id,
|
pagadorId: pagadorRow.id,
|
||||||
sharedWithUserId: user.id,
|
sharedWithUserId: user.id,
|
||||||
permission: "read",
|
permission: "read",
|
||||||
@@ -259,13 +259,13 @@ export async function deletePagadorShareAction(
|
|||||||
const user = await getUser();
|
const user = await getUser();
|
||||||
const data = shareDeleteSchema.parse(input);
|
const data = shareDeleteSchema.parse(input);
|
||||||
|
|
||||||
const existing = await db.query.pagadorShares.findFirst({
|
const existing = await db.query.compartilhamentosPagador.findFirst({
|
||||||
columns: {
|
columns: {
|
||||||
id: true,
|
id: true,
|
||||||
pagadorId: true,
|
pagadorId: true,
|
||||||
sharedWithUserId: true,
|
sharedWithUserId: true,
|
||||||
},
|
},
|
||||||
where: eq(pagadorShares.id, data.shareId),
|
where: eq(compartilhamentosPagador.id, data.shareId),
|
||||||
with: {
|
with: {
|
||||||
pagador: {
|
pagador: {
|
||||||
columns: {
|
columns: {
|
||||||
@@ -287,7 +287,7 @@ export async function deletePagadorShareAction(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
await db.delete(pagadorShares).where(eq(pagadorShares.id, data.shareId));
|
await db.delete(compartilhamentosPagador).where(eq(compartilhamentosPagador.id, data.shareId));
|
||||||
|
|
||||||
revalidate();
|
revalidate();
|
||||||
revalidatePath(`/pagadores/${existing.pagadorId}`);
|
revalidatePath(`/pagadores/${existing.pagadorId}`);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import { and, eq, inArray } from "drizzle-orm";
|
import { and, eq, inArray } from "drizzle-orm";
|
||||||
import { revalidatePath } from "next/cache";
|
import { revalidatePath } from "next/cache";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { inboxItems } from "@/db/schema";
|
import { preLancamentos } from "@/db/schema";
|
||||||
import { handleActionError } from "@/lib/actions/helpers";
|
import { handleActionError } from "@/lib/actions/helpers";
|
||||||
import type { ActionResult } from "@/lib/actions/types";
|
import type { ActionResult } from "@/lib/actions/types";
|
||||||
import { getUser } from "@/lib/auth/server";
|
import { getUser } from "@/lib/auth/server";
|
||||||
@@ -40,12 +40,12 @@ export async function markInboxAsProcessedAction(
|
|||||||
// Verificar se item existe e pertence ao usuário
|
// Verificar se item existe e pertence ao usuário
|
||||||
const [item] = await db
|
const [item] = await db
|
||||||
.select()
|
.select()
|
||||||
.from(inboxItems)
|
.from(preLancamentos)
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(inboxItems.id, data.inboxItemId),
|
eq(preLancamentos.id, data.inboxItemId),
|
||||||
eq(inboxItems.userId, user.id),
|
eq(preLancamentos.userId, user.id),
|
||||||
eq(inboxItems.status, "pending"),
|
eq(preLancamentos.status, "pending"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.limit(1);
|
.limit(1);
|
||||||
@@ -56,13 +56,13 @@ export async function markInboxAsProcessedAction(
|
|||||||
|
|
||||||
// Marcar item como processado
|
// Marcar item como processado
|
||||||
await db
|
await db
|
||||||
.update(inboxItems)
|
.update(preLancamentos)
|
||||||
.set({
|
.set({
|
||||||
status: "processed",
|
status: "processed",
|
||||||
processedAt: new Date(),
|
processedAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
})
|
})
|
||||||
.where(eq(inboxItems.id, data.inboxItemId));
|
.where(eq(preLancamentos.id, data.inboxItemId));
|
||||||
|
|
||||||
revalidateInbox();
|
revalidateInbox();
|
||||||
|
|
||||||
@@ -82,12 +82,12 @@ export async function discardInboxItemAction(
|
|||||||
// Verificar se item existe e pertence ao usuário
|
// Verificar se item existe e pertence ao usuário
|
||||||
const [item] = await db
|
const [item] = await db
|
||||||
.select()
|
.select()
|
||||||
.from(inboxItems)
|
.from(preLancamentos)
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(inboxItems.id, data.inboxItemId),
|
eq(preLancamentos.id, data.inboxItemId),
|
||||||
eq(inboxItems.userId, user.id),
|
eq(preLancamentos.userId, user.id),
|
||||||
eq(inboxItems.status, "pending"),
|
eq(preLancamentos.status, "pending"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.limit(1);
|
.limit(1);
|
||||||
@@ -98,13 +98,13 @@ export async function discardInboxItemAction(
|
|||||||
|
|
||||||
// Marcar item como descartado
|
// Marcar item como descartado
|
||||||
await db
|
await db
|
||||||
.update(inboxItems)
|
.update(preLancamentos)
|
||||||
.set({
|
.set({
|
||||||
status: "discarded",
|
status: "discarded",
|
||||||
discardedAt: new Date(),
|
discardedAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
})
|
})
|
||||||
.where(eq(inboxItems.id, data.inboxItemId));
|
.where(eq(preLancamentos.id, data.inboxItemId));
|
||||||
|
|
||||||
revalidateInbox();
|
revalidateInbox();
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ export async function bulkDiscardInboxItemsAction(
|
|||||||
|
|
||||||
// Marcar todos os itens como descartados
|
// Marcar todos os itens como descartados
|
||||||
await db
|
await db
|
||||||
.update(inboxItems)
|
.update(preLancamentos)
|
||||||
.set({
|
.set({
|
||||||
status: "discarded",
|
status: "discarded",
|
||||||
discardedAt: new Date(),
|
discardedAt: new Date(),
|
||||||
@@ -131,9 +131,9 @@ export async function bulkDiscardInboxItemsAction(
|
|||||||
})
|
})
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
inArray(inboxItems.id, data.inboxItemIds),
|
inArray(preLancamentos.id, data.inboxItemIds),
|
||||||
eq(inboxItems.userId, user.id),
|
eq(preLancamentos.userId, user.id),
|
||||||
eq(inboxItems.status, "pending"),
|
eq(preLancamentos.status, "pending"),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
/**
|
|
||||||
* Data fetching functions for Pré-Lançamentos
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { and, desc, eq, gte } from "drizzle-orm";
|
import { and, desc, eq, gte } from "drizzle-orm";
|
||||||
import type {
|
import type {
|
||||||
@@ -11,7 +9,7 @@ import {
|
|||||||
cartoes,
|
cartoes,
|
||||||
categorias,
|
categorias,
|
||||||
contas,
|
contas,
|
||||||
inboxItems,
|
preLancamentos,
|
||||||
lancamentos,
|
lancamentos,
|
||||||
} from "@/db/schema";
|
} from "@/db/schema";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
@@ -27,9 +25,9 @@ export async function fetchInboxItems(
|
|||||||
): Promise<InboxItem[]> {
|
): Promise<InboxItem[]> {
|
||||||
const items = await db
|
const items = await db
|
||||||
.select()
|
.select()
|
||||||
.from(inboxItems)
|
.from(preLancamentos)
|
||||||
.where(and(eq(inboxItems.userId, userId), eq(inboxItems.status, status)))
|
.where(and(eq(preLancamentos.userId, userId), eq(preLancamentos.status, status)))
|
||||||
.orderBy(desc(inboxItems.createdAt));
|
.orderBy(desc(preLancamentos.createdAt));
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
@@ -40,8 +38,8 @@ export async function fetchInboxItemById(
|
|||||||
): Promise<InboxItem | null> {
|
): Promise<InboxItem | null> {
|
||||||
const [item] = await db
|
const [item] = await db
|
||||||
.select()
|
.select()
|
||||||
.from(inboxItems)
|
.from(preLancamentos)
|
||||||
.where(and(eq(inboxItems.id, itemId), eq(inboxItems.userId, userId)))
|
.where(and(eq(preLancamentos.id, itemId), eq(preLancamentos.userId, userId)))
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
return item ?? null;
|
return item ?? null;
|
||||||
@@ -90,10 +88,10 @@ export async function fetchCartoesForSelect(
|
|||||||
|
|
||||||
export async function fetchPendingInboxCount(userId: string): Promise<number> {
|
export async function fetchPendingInboxCount(userId: string): Promise<number> {
|
||||||
const items = await db
|
const items = await db
|
||||||
.select({ id: inboxItems.id })
|
.select({ id: preLancamentos.id })
|
||||||
.from(inboxItems)
|
.from(preLancamentos)
|
||||||
.where(
|
.where(
|
||||||
and(eq(inboxItems.userId, userId), eq(inboxItems.status, "pending")),
|
and(eq(preLancamentos.userId, userId), eq(preLancamentos.status, "pending")),
|
||||||
);
|
);
|
||||||
|
|
||||||
return items.length;
|
return items.length;
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
/**
|
|
||||||
* POST /api/auth/device/refresh
|
|
||||||
*
|
|
||||||
* Atualiza access token usando refresh token.
|
|
||||||
* Usado pelo app Android quando o access token expira.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { and, eq, isNull } from "drizzle-orm";
|
import { and, eq, isNull } from "drizzle-orm";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { apiTokens } from "@/db/schema";
|
import { tokensApi } from "@/db/schema";
|
||||||
import {
|
import {
|
||||||
extractBearerToken,
|
extractBearerToken,
|
||||||
hashToken,
|
hashToken,
|
||||||
@@ -40,11 +35,11 @@ export async function POST(request: Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verificar se token não foi revogado
|
// Verificar se token não foi revogado
|
||||||
const tokenRecord = await db.query.apiTokens.findFirst({
|
const tokenRecord = await db.query.tokensApi.findFirst({
|
||||||
where: and(
|
where: and(
|
||||||
eq(apiTokens.id, payload.tokenId),
|
eq(tokensApi.id, payload.tokenId),
|
||||||
eq(apiTokens.userId, payload.sub),
|
eq(tokensApi.userId, payload.sub),
|
||||||
isNull(apiTokens.revokedAt),
|
isNull(tokensApi.revokedAt),
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -67,7 +62,7 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
// Atualizar hash do token e último uso
|
// Atualizar hash do token e último uso
|
||||||
await db
|
await db
|
||||||
.update(apiTokens)
|
.update(tokensApi)
|
||||||
.set({
|
.set({
|
||||||
tokenHash: hashToken(result.accessToken),
|
tokenHash: hashToken(result.accessToken),
|
||||||
lastUsedAt: new Date(),
|
lastUsedAt: new Date(),
|
||||||
@@ -76,7 +71,7 @@ export async function POST(request: Request) {
|
|||||||
request.headers.get("x-real-ip"),
|
request.headers.get("x-real-ip"),
|
||||||
expiresAt: result.expiresAt,
|
expiresAt: result.expiresAt,
|
||||||
})
|
})
|
||||||
.where(eq(apiTokens.id, payload.tokenId));
|
.where(eq(tokensApi.id, payload.tokenId));
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
accessToken: result.accessToken,
|
accessToken: result.accessToken,
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
/**
|
|
||||||
* POST /api/auth/device/token
|
|
||||||
*
|
|
||||||
* Gera um novo token de API para dispositivo.
|
|
||||||
* Requer sessão web autenticada.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { headers } from "next/headers";
|
import { headers } from "next/headers";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { apiTokens } from "@/db/schema";
|
import { tokensApi } from "@/db/schema";
|
||||||
import {
|
import {
|
||||||
generateTokenPair,
|
generateTokenPair,
|
||||||
getTokenPrefix,
|
getTokenPrefix,
|
||||||
@@ -42,7 +37,7 @@ export async function POST(request: Request) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Salvar hash do token no banco
|
// Salvar hash do token no banco
|
||||||
await db.insert(apiTokens).values({
|
await db.insert(tokensApi).values({
|
||||||
id: tokenId,
|
id: tokenId,
|
||||||
userId: session.user.id,
|
userId: session.user.id,
|
||||||
name,
|
name,
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
/**
|
|
||||||
* DELETE /api/auth/device/tokens/[tokenId]
|
|
||||||
*
|
|
||||||
* Revoga um token de API específico.
|
|
||||||
* Requer sessão web autenticada.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { and, eq } from "drizzle-orm";
|
import { and, eq } from "drizzle-orm";
|
||||||
import { headers } from "next/headers";
|
import { headers } from "next/headers";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { apiTokens } from "@/db/schema";
|
import { tokensApi } from "@/db/schema";
|
||||||
import { auth } from "@/lib/auth/config";
|
import { auth } from "@/lib/auth/config";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
|
|
||||||
@@ -28,10 +23,10 @@ export async function DELETE(_request: Request, { params }: RouteParams) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verificar se token pertence ao usuário
|
// Verificar se token pertence ao usuário
|
||||||
const token = await db.query.apiTokens.findFirst({
|
const token = await db.query.tokensApi.findFirst({
|
||||||
where: and(
|
where: and(
|
||||||
eq(apiTokens.id, tokenId),
|
eq(tokensApi.id, tokenId),
|
||||||
eq(apiTokens.userId, session.user.id),
|
eq(tokensApi.userId, session.user.id),
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -44,9 +39,9 @@ export async function DELETE(_request: Request, { params }: RouteParams) {
|
|||||||
|
|
||||||
// Revogar token (soft delete)
|
// Revogar token (soft delete)
|
||||||
await db
|
await db
|
||||||
.update(apiTokens)
|
.update(tokensApi)
|
||||||
.set({ revokedAt: new Date() })
|
.set({ revokedAt: new Date() })
|
||||||
.where(eq(apiTokens.id, tokenId));
|
.where(eq(tokensApi.id, tokenId));
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
message: "Token revogado com sucesso",
|
message: "Token revogado com sucesso",
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
/**
|
|
||||||
* GET /api/auth/device/tokens
|
|
||||||
*
|
|
||||||
* Lista todos os tokens de API do usuário.
|
|
||||||
* Requer sessão web autenticada.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { desc, eq } from "drizzle-orm";
|
import { desc, eq } from "drizzle-orm";
|
||||||
import { headers } from "next/headers";
|
import { headers } from "next/headers";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { apiTokens } from "@/db/schema";
|
import { tokensApi } from "@/db/schema";
|
||||||
import { auth } from "@/lib/auth/config";
|
import { auth } from "@/lib/auth/config";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
|
|
||||||
@@ -24,17 +19,17 @@ export async function GET() {
|
|||||||
// Buscar tokens ativos do usuário
|
// Buscar tokens ativos do usuário
|
||||||
const tokens = await db
|
const tokens = await db
|
||||||
.select({
|
.select({
|
||||||
id: apiTokens.id,
|
id: tokensApi.id,
|
||||||
name: apiTokens.name,
|
name: tokensApi.name,
|
||||||
tokenPrefix: apiTokens.tokenPrefix,
|
tokenPrefix: tokensApi.tokenPrefix,
|
||||||
lastUsedAt: apiTokens.lastUsedAt,
|
lastUsedAt: tokensApi.lastUsedAt,
|
||||||
lastUsedIp: apiTokens.lastUsedIp,
|
lastUsedIp: tokensApi.lastUsedIp,
|
||||||
expiresAt: apiTokens.expiresAt,
|
expiresAt: tokensApi.expiresAt,
|
||||||
createdAt: apiTokens.createdAt,
|
createdAt: tokensApi.createdAt,
|
||||||
})
|
})
|
||||||
.from(apiTokens)
|
.from(tokensApi)
|
||||||
.where(eq(apiTokens.userId, session.user.id))
|
.where(eq(tokensApi.userId, session.user.id))
|
||||||
.orderBy(desc(apiTokens.createdAt));
|
.orderBy(desc(tokensApi.createdAt));
|
||||||
|
|
||||||
// Separar tokens ativos e revogados
|
// Separar tokens ativos e revogados
|
||||||
const activeTokens = tokens.filter(
|
const activeTokens = tokens.filter(
|
||||||
|
|||||||
@@ -1,15 +1,8 @@
|
|||||||
/**
|
|
||||||
* POST /api/auth/device/verify
|
|
||||||
*
|
|
||||||
* Valida se um token de API é válido.
|
|
||||||
* Usado pelo app Android durante o setup.
|
|
||||||
*
|
|
||||||
* Aceita tokens no formato os_xxx (hash-based, sem expiração).
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { and, eq, isNull } from "drizzle-orm";
|
import { and, eq, isNull } from "drizzle-orm";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { apiTokens } from "@/db/schema";
|
import { tokensApi } from "@/db/schema";
|
||||||
import { extractBearerToken, hashToken } from "@/lib/auth/api-token";
|
import { extractBearerToken, hashToken } from "@/lib/auth/api-token";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
|
|
||||||
@@ -38,10 +31,10 @@ export async function POST(request: Request) {
|
|||||||
const tokenHash = hashToken(token);
|
const tokenHash = hashToken(token);
|
||||||
|
|
||||||
// Buscar token no banco
|
// Buscar token no banco
|
||||||
const tokenRecord = await db.query.apiTokens.findFirst({
|
const tokenRecord = await db.query.tokensApi.findFirst({
|
||||||
where: and(
|
where: and(
|
||||||
eq(apiTokens.tokenHash, tokenHash),
|
eq(tokensApi.tokenHash, tokenHash),
|
||||||
isNull(apiTokens.revokedAt),
|
isNull(tokensApi.revokedAt),
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -59,12 +52,12 @@ export async function POST(request: Request) {
|
|||||||
null;
|
null;
|
||||||
|
|
||||||
await db
|
await db
|
||||||
.update(apiTokens)
|
.update(tokensApi)
|
||||||
.set({
|
.set({
|
||||||
lastUsedAt: new Date(),
|
lastUsedAt: new Date(),
|
||||||
lastUsedIp: clientIp,
|
lastUsedIp: clientIp,
|
||||||
})
|
})
|
||||||
.where(eq(apiTokens.id, tokenRecord.id));
|
.where(eq(tokensApi.id, tokenRecord.id));
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
valid: true,
|
valid: true,
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
/**
|
|
||||||
* POST /api/inbox/batch
|
|
||||||
*
|
|
||||||
* Recebe múltiplas notificações do app Android (sync offline).
|
|
||||||
* Requer autenticação via API token (formato os_xxx).
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { and, eq, isNull } from "drizzle-orm";
|
import { and, eq, isNull } from "drizzle-orm";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { apiTokens, inboxItems } from "@/db/schema";
|
import { tokensApi, preLancamentos } from "@/db/schema";
|
||||||
import { extractBearerToken, hashToken } from "@/lib/auth/api-token";
|
import { extractBearerToken, hashToken } from "@/lib/auth/api-token";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
import { inboxBatchSchema } from "@/lib/schemas/inbox";
|
import { inboxBatchSchema } from "@/lib/schemas/inbox";
|
||||||
@@ -66,10 +61,10 @@ export async function POST(request: Request) {
|
|||||||
const tokenHash = hashToken(token);
|
const tokenHash = hashToken(token);
|
||||||
|
|
||||||
// Buscar token no banco
|
// Buscar token no banco
|
||||||
const tokenRecord = await db.query.apiTokens.findFirst({
|
const tokenRecord = await db.query.tokensApi.findFirst({
|
||||||
where: and(
|
where: and(
|
||||||
eq(apiTokens.tokenHash, tokenHash),
|
eq(tokensApi.tokenHash, tokenHash),
|
||||||
isNull(apiTokens.revokedAt),
|
isNull(tokensApi.revokedAt),
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -98,7 +93,7 @@ export async function POST(request: Request) {
|
|||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
try {
|
try {
|
||||||
const [inserted] = await db
|
const [inserted] = await db
|
||||||
.insert(inboxItems)
|
.insert(preLancamentos)
|
||||||
.values({
|
.values({
|
||||||
userId: tokenRecord.userId,
|
userId: tokenRecord.userId,
|
||||||
sourceApp: item.sourceApp,
|
sourceApp: item.sourceApp,
|
||||||
@@ -111,7 +106,7 @@ export async function POST(request: Request) {
|
|||||||
parsedTransactionType: item.parsedTransactionType,
|
parsedTransactionType: item.parsedTransactionType,
|
||||||
status: "pending",
|
status: "pending",
|
||||||
})
|
})
|
||||||
.returning({ id: inboxItems.id });
|
.returning({ id: preLancamentos.id });
|
||||||
|
|
||||||
results.push({
|
results.push({
|
||||||
clientId: item.clientId,
|
clientId: item.clientId,
|
||||||
@@ -134,12 +129,12 @@ export async function POST(request: Request) {
|
|||||||
null;
|
null;
|
||||||
|
|
||||||
await db
|
await db
|
||||||
.update(apiTokens)
|
.update(tokensApi)
|
||||||
.set({
|
.set({
|
||||||
lastUsedAt: new Date(),
|
lastUsedAt: new Date(),
|
||||||
lastUsedIp: clientIp,
|
lastUsedIp: clientIp,
|
||||||
})
|
})
|
||||||
.where(eq(apiTokens.id, tokenRecord.id));
|
.where(eq(tokensApi.id, tokenRecord.id));
|
||||||
|
|
||||||
const successCount = results.filter((r) => r.success).length;
|
const successCount = results.filter((r) => r.success).length;
|
||||||
const failCount = results.filter((r) => !r.success).length;
|
const failCount = results.filter((r) => !r.success).length;
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
/**
|
|
||||||
* POST /api/inbox
|
|
||||||
*
|
|
||||||
* Recebe uma notificação do app Android.
|
|
||||||
* Requer autenticação via API token (formato os_xxx).
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { and, eq, isNull } from "drizzle-orm";
|
import { and, eq, isNull } from "drizzle-orm";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { apiTokens, inboxItems } from "@/db/schema";
|
import { tokensApi, preLancamentos } from "@/db/schema";
|
||||||
import { extractBearerToken, hashToken } from "@/lib/auth/api-token";
|
import { extractBearerToken, hashToken } from "@/lib/auth/api-token";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
import { inboxItemSchema } from "@/lib/schemas/inbox";
|
import { inboxItemSchema } from "@/lib/schemas/inbox";
|
||||||
@@ -59,10 +54,10 @@ export async function POST(request: Request) {
|
|||||||
const tokenHash = hashToken(token);
|
const tokenHash = hashToken(token);
|
||||||
|
|
||||||
// Buscar token no banco
|
// Buscar token no banco
|
||||||
const tokenRecord = await db.query.apiTokens.findFirst({
|
const tokenRecord = await db.query.tokensApi.findFirst({
|
||||||
where: and(
|
where: and(
|
||||||
eq(apiTokens.tokenHash, tokenHash),
|
eq(tokensApi.tokenHash, tokenHash),
|
||||||
isNull(apiTokens.revokedAt),
|
isNull(tokensApi.revokedAt),
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -87,7 +82,7 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
// Inserir item na inbox
|
// Inserir item na inbox
|
||||||
const [inserted] = await db
|
const [inserted] = await db
|
||||||
.insert(inboxItems)
|
.insert(preLancamentos)
|
||||||
.values({
|
.values({
|
||||||
userId: tokenRecord.userId,
|
userId: tokenRecord.userId,
|
||||||
sourceApp: data.sourceApp,
|
sourceApp: data.sourceApp,
|
||||||
@@ -100,7 +95,7 @@ export async function POST(request: Request) {
|
|||||||
parsedTransactionType: data.parsedTransactionType,
|
parsedTransactionType: data.parsedTransactionType,
|
||||||
status: "pending",
|
status: "pending",
|
||||||
})
|
})
|
||||||
.returning({ id: inboxItems.id });
|
.returning({ id: preLancamentos.id });
|
||||||
|
|
||||||
// Atualizar último uso do token
|
// Atualizar último uso do token
|
||||||
const clientIp =
|
const clientIp =
|
||||||
@@ -109,12 +104,12 @@ export async function POST(request: Request) {
|
|||||||
null;
|
null;
|
||||||
|
|
||||||
await db
|
await db
|
||||||
.update(apiTokens)
|
.update(tokensApi)
|
||||||
.set({
|
.set({
|
||||||
lastUsedAt: new Date(),
|
lastUsedAt: new Date(),
|
||||||
lastUsedIp: clientIp,
|
lastUsedIp: clientIp,
|
||||||
})
|
})
|
||||||
.where(eq(apiTokens.id, tokenRecord.id));
|
.where(eq(tokensApi.id, tokenRecord.id));
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
/**
|
|
||||||
* Types for Pré-Lançamentos feature
|
|
||||||
*/
|
|
||||||
|
|
||||||
import type { SelectOption as LancamentoSelectOption } from "@/components/lancamentos/types";
|
import type { SelectOption as LancamentoSelectOption } from "@/components/lancamentos/types";
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
/**
|
|
||||||
* API Token utilities for OpenSheets Companion
|
|
||||||
*
|
|
||||||
* Handles JWT generation, validation, and token hashing for device authentication.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import crypto from "node:crypto";
|
import crypto from "node:crypto";
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
/**
|
|
||||||
* Better Auth Configuration
|
|
||||||
*
|
|
||||||
* Configuração central de autenticação usando Better Auth.
|
|
||||||
* Suporta email/password e Google OAuth.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { betterAuth } from "better-auth";
|
import { betterAuth } from "better-auth";
|
||||||
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
||||||
|
|||||||
@@ -1,14 +1,4 @@
|
|||||||
/**
|
|
||||||
* Server-side authentication utilities
|
|
||||||
*
|
|
||||||
* This module consolidates server-side auth functions from:
|
|
||||||
* - /lib/get-user.tsx
|
|
||||||
* - /lib/get-user-id.tsx
|
|
||||||
* - /lib/get-user-session.tsx
|
|
||||||
*
|
|
||||||
* All functions in this module are server-side only and will redirect
|
|
||||||
* to /login if the user is not authenticated.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { headers } from "next/headers";
|
import { headers } from "next/headers";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
/**
|
|
||||||
* Category defaults and seeding
|
|
||||||
*
|
|
||||||
* Consolidated from:
|
|
||||||
* - /lib/category-defaults.ts
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import { categorias } from "@/db/schema";
|
import { categorias } from "@/db/schema";
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
/**
|
|
||||||
* Common utilities and helpers for dashboard queries
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { calculatePercentageChange } from "@/lib/utils/math";
|
import { calculatePercentageChange } from "@/lib/utils/math";
|
||||||
import { safeToNumber } from "@/lib/utils/number";
|
import { safeToNumber } from "@/lib/utils/number";
|
||||||
|
|||||||
@@ -18,21 +18,21 @@ export async function updateWidgetPreferences(
|
|||||||
|
|
||||||
// Check if preferences exist
|
// Check if preferences exist
|
||||||
const existing = await db
|
const existing = await db
|
||||||
.select({ id: schema.userPreferences.id })
|
.select({ id: schema.preferenciasUsuario.id })
|
||||||
.from(schema.userPreferences)
|
.from(schema.preferenciasUsuario)
|
||||||
.where(eq(schema.userPreferences.userId, user.id))
|
.where(eq(schema.preferenciasUsuario.userId, user.id))
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
if (existing.length > 0) {
|
if (existing.length > 0) {
|
||||||
await db
|
await db
|
||||||
.update(schema.userPreferences)
|
.update(schema.preferenciasUsuario)
|
||||||
.set({
|
.set({
|
||||||
dashboardWidgets: preferences,
|
dashboardWidgets: preferences,
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
})
|
})
|
||||||
.where(eq(schema.userPreferences.userId, user.id));
|
.where(eq(schema.preferenciasUsuario.userId, user.id));
|
||||||
} else {
|
} else {
|
||||||
await db.insert(schema.userPreferences).values({
|
await db.insert(schema.preferenciasUsuario).values({
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
dashboardWidgets: preferences,
|
dashboardWidgets: preferences,
|
||||||
});
|
});
|
||||||
@@ -54,12 +54,12 @@ export async function resetWidgetPreferences(): Promise<{
|
|||||||
const user = await getUser();
|
const user = await getUser();
|
||||||
|
|
||||||
await db
|
await db
|
||||||
.update(schema.userPreferences)
|
.update(schema.preferenciasUsuario)
|
||||||
.set({
|
.set({
|
||||||
dashboardWidgets: null,
|
dashboardWidgets: null,
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
})
|
})
|
||||||
.where(eq(schema.userPreferences.userId, user.id));
|
.where(eq(schema.preferenciasUsuario.userId, user.id));
|
||||||
|
|
||||||
revalidatePath("/dashboard");
|
revalidatePath("/dashboard");
|
||||||
return { success: true };
|
return { success: true };
|
||||||
@@ -74,9 +74,9 @@ export async function getWidgetPreferences(): Promise<WidgetPreferences | null>
|
|||||||
const user = await getUser();
|
const user = await getUser();
|
||||||
|
|
||||||
const result = await db
|
const result = await db
|
||||||
.select({ dashboardWidgets: schema.userPreferences.dashboardWidgets })
|
.select({ dashboardWidgets: schema.preferenciasUsuario.dashboardWidgets })
|
||||||
.from(schema.userPreferences)
|
.from(schema.preferenciasUsuario)
|
||||||
.where(eq(schema.userPreferences.userId, user.id))
|
.where(eq(schema.preferenciasUsuario.userId, user.id))
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
return result[0]?.dashboardWidgets ?? null;
|
return result[0]?.dashboardWidgets ?? null;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type {
|
import type {
|
||||||
|
AntecipacaoParcela,
|
||||||
Categoria,
|
Categoria,
|
||||||
InstallmentAnticipation,
|
|
||||||
Lancamento,
|
Lancamento,
|
||||||
Pagador,
|
Pagador,
|
||||||
} from "@/db/schema";
|
} from "@/db/schema";
|
||||||
@@ -25,7 +25,7 @@ export type EligibleInstallment = {
|
|||||||
/**
|
/**
|
||||||
* Antecipação com dados completos
|
* Antecipação com dados completos
|
||||||
*/
|
*/
|
||||||
export type InstallmentAnticipationWithRelations = InstallmentAnticipation & {
|
export type InstallmentAnticipationWithRelations = AntecipacaoParcela & {
|
||||||
lancamento: Lancamento;
|
lancamento: Lancamento;
|
||||||
pagador: Pagador | null;
|
pagador: Pagador | null;
|
||||||
categoria: Categoria | null;
|
categoria: Categoria | null;
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
/**
|
|
||||||
* Categoria grouping and sorting helpers for lancamentos
|
|
||||||
*/
|
|
||||||
|
|
||||||
import type { SelectOption } from "@/components/lancamentos/types";
|
import type { SelectOption } from "@/components/lancamentos/types";
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
/**
|
|
||||||
* Form state management helpers for lancamentos
|
|
||||||
*/
|
|
||||||
|
|
||||||
import type { LancamentoItem } from "@/components/lancamentos/types";
|
import type { LancamentoItem } from "@/components/lancamentos/types";
|
||||||
import { getTodayDateString } from "@/lib/utils/date";
|
import { getTodayDateString } from "@/lib/utils/date";
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
/**
|
|
||||||
* Logo options loader
|
|
||||||
*
|
|
||||||
* Consolidated from:
|
|
||||||
* - /lib/logo-options.ts (async logo loading)
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { readdir } from "node:fs/promises";
|
import { readdir } from "node:fs/promises";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { and, eq } from "drizzle-orm";
|
import { and, eq } from "drizzle-orm";
|
||||||
import { pagadores, pagadorShares, user as usersTable } from "@/db/schema";
|
import { pagadores, compartilhamentosPagador, user as usersTable } from "@/db/schema";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
|
|
||||||
export type PagadorWithAccess = typeof pagadores.$inferSelect & {
|
export type PagadorWithAccess = typeof pagadores.$inferSelect & {
|
||||||
@@ -18,15 +18,15 @@ export async function fetchPagadoresWithAccess(
|
|||||||
}),
|
}),
|
||||||
db
|
db
|
||||||
.select({
|
.select({
|
||||||
shareId: pagadorShares.id,
|
shareId: compartilhamentosPagador.id,
|
||||||
pagador: pagadores,
|
pagador: pagadores,
|
||||||
ownerName: usersTable.name,
|
ownerName: usersTable.name,
|
||||||
ownerEmail: usersTable.email,
|
ownerEmail: usersTable.email,
|
||||||
})
|
})
|
||||||
.from(pagadorShares)
|
.from(compartilhamentosPagador)
|
||||||
.innerJoin(pagadores, eq(pagadorShares.pagadorId, pagadores.id))
|
.innerJoin(pagadores, eq(compartilhamentosPagador.pagadorId, pagadores.id))
|
||||||
.leftJoin(usersTable, eq(pagadores.userId, usersTable.id))
|
.leftJoin(usersTable, eq(pagadores.userId, usersTable.id))
|
||||||
.where(eq(pagadorShares.sharedWithUserId, userId)),
|
.where(eq(compartilhamentosPagador.sharedWithUserId, userId)),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const ownedMapped: PagadorWithAccess[] = owned.map((item) => ({
|
const ownedMapped: PagadorWithAccess[] = owned.map((item) => ({
|
||||||
@@ -62,14 +62,14 @@ export async function getPagadorAccess(userId: string, pagadorId: string) {
|
|||||||
return {
|
return {
|
||||||
pagador,
|
pagador,
|
||||||
canEdit: true,
|
canEdit: true,
|
||||||
share: null as typeof pagadorShares.$inferSelect | null,
|
share: null as typeof compartilhamentosPagador.$inferSelect | null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const share = await db.query.pagadorShares.findFirst({
|
const share = await db.query.compartilhamentosPagador.findFirst({
|
||||||
where: and(
|
where: and(
|
||||||
eq(pagadorShares.pagadorId, pagadorId),
|
eq(compartilhamentosPagador.pagadorId, pagadorId),
|
||||||
eq(pagadorShares.sharedWithUserId, userId),
|
eq(compartilhamentosPagador.sharedWithUserId, userId),
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
/**
|
|
||||||
* Pagador constants
|
|
||||||
*
|
|
||||||
* Extracted from /lib/pagadores.ts
|
|
||||||
*/
|
|
||||||
|
|
||||||
export const PAGADOR_STATUS_OPTIONS = ["Ativo", "Inativo"] as const;
|
export const PAGADOR_STATUS_OPTIONS = ["Ativo", "Inativo"] as const;
|
||||||
|
|
||||||
export type PagadorStatus = (typeof PAGADOR_STATUS_OPTIONS)[number];
|
export type PagadorStatus = (typeof PAGADOR_STATUS_OPTIONS)[number];
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
/**
|
|
||||||
* Pagador defaults - User seeding logic
|
|
||||||
*
|
|
||||||
* Moved from /lib/pagador-defaults.ts to /lib/pagadores/defaults.ts
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import { pagadores } from "@/db/schema";
|
import { pagadores } from "@/db/schema";
|
||||||
import { db } from "@/lib/db";
|
import { db } from "@/lib/db";
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
import { cartoes, lancamentos } from "@/db/schema";
|
|
||||||
import { ACCOUNT_AUTO_INVOICE_NOTE_PREFIX } from "@/lib/accounts/constants";
|
|
||||||
import { db } from "@/lib/db";
|
|
||||||
import {
|
import {
|
||||||
and,
|
and,
|
||||||
eq,
|
eq,
|
||||||
@@ -13,6 +10,9 @@ import {
|
|||||||
sql,
|
sql,
|
||||||
sum,
|
sum,
|
||||||
} from "drizzle-orm";
|
} from "drizzle-orm";
|
||||||
|
import { cartoes, lancamentos } from "@/db/schema";
|
||||||
|
import { ACCOUNT_AUTO_INVOICE_NOTE_PREFIX } from "@/lib/accounts/constants";
|
||||||
|
import { db } from "@/lib/db";
|
||||||
|
|
||||||
const RECEITA = "Receita";
|
const RECEITA = "Receita";
|
||||||
const DESPESA = "Despesa";
|
const DESPESA = "Despesa";
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
/**
|
|
||||||
* Pagador utility functions
|
|
||||||
*
|
|
||||||
* Extracted from /lib/pagadores.ts
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { DEFAULT_PAGADOR_AVATAR } from "./constants";
|
import { DEFAULT_PAGADOR_AVATAR } from "./constants";
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
/**
|
|
||||||
* Data fetching function for Category Chart (based on selected filters)
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import { ptBR } from "date-fns/locale";
|
import { ptBR } from "date-fns/locale";
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
/**
|
|
||||||
* Data fetching function for Category Report
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { and, eq, inArray, isNull, or, sql } from "drizzle-orm";
|
import { and, eq, inArray, isNull, or, sql } from "drizzle-orm";
|
||||||
import { categorias, lancamentos, pagadores } from "@/db/schema";
|
import { categorias, lancamentos, pagadores } from "@/db/schema";
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
/**
|
|
||||||
* Utility functions for Category Report feature
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { currencyFormatter } from "@/lib/lancamentos/formatting-helpers";
|
import { currencyFormatter } from "@/lib/lancamentos/formatting-helpers";
|
||||||
import { calculatePercentageChange } from "@/lib/utils/math";
|
import { calculatePercentageChange } from "@/lib/utils/math";
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
/**
|
|
||||||
* Zod schemas for inbox items (OpenSheets Companion)
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
/**
|
|
||||||
* UI utilities - Functions for UI manipulation and styling
|
|
||||||
*
|
|
||||||
* This module contains UI-related utilities, primarily for className manipulation.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { type ClassValue, clsx } from "clsx";
|
import { type ClassValue, clsx } from "clsx";
|
||||||
import { twMerge } from "tailwind-merge";
|
import { twMerge } from "tailwind-merge";
|
||||||
|
|||||||
Reference in New Issue
Block a user