refactor: traduz contratos compartilhados do schema

This commit is contained in:
Felipe Coutinho
2026-03-14 12:50:43 +00:00
parent fa9bf17663
commit ef918a3667
9 changed files with 248 additions and 247 deletions

View File

@@ -1,7 +1,7 @@
import { and, eq, isNull } from "drizzle-orm";
import { NextResponse } from "next/server";
import { z } from "zod";
import { preLancamentos, tokensApi } from "@/db/schema";
import { apiTokens, inboxItems } from "@/db/schema";
import { extractBearerToken, hashToken } from "@/shared/lib/auth/api-token";
import { db } from "@/shared/lib/db";
import { inboxBatchSchema } from "@/shared/lib/schemas/inbox";
@@ -59,10 +59,10 @@ export async function POST(request: Request) {
const tokenHash = hashToken(token);
// Buscar token no banco
const tokenRecord = await db.query.tokensApi.findFirst({
const tokenRecord = await db.query.apiTokens.findFirst({
where: and(
eq(tokensApi.tokenHash, tokenHash),
isNull(tokensApi.revokedAt),
eq(apiTokens.tokenHash, tokenHash),
isNull(apiTokens.revokedAt),
),
});
@@ -91,7 +91,7 @@ export async function POST(request: Request) {
for (const item of items) {
try {
const [inserted] = await db
.insert(preLancamentos)
.insert(inboxItems)
.values({
userId: tokenRecord.userId,
sourceApp: item.sourceApp,
@@ -103,7 +103,7 @@ export async function POST(request: Request) {
parsedAmount: item.parsedAmount?.toString(),
status: "pending",
})
.returning({ id: preLancamentos.id });
.returning({ id: inboxItems.id });
results.push({
clientId: item.clientId,
@@ -126,12 +126,12 @@ export async function POST(request: Request) {
null;
await db
.update(tokensApi)
.update(apiTokens)
.set({
lastUsedAt: new Date(),
lastUsedIp: clientIp,
})
.where(eq(tokensApi.id, tokenRecord.id));
.where(eq(apiTokens.id, tokenRecord.id));
const successCount = results.filter((r) => r.success).length;
const failCount = results.filter((r) => !r.success).length;