fix(lint): resolve Biome errors and migrate config
- migrate biome.json to schema 2.5.10 (preset instead of recommended) - apply safe fixes: formatting, import organization, unused imports/vars - use node:crypto import protocol - drop unused catch bindings - a11y: associate labels with controls via htmlFor/id (add optional id to DatePicker), hide decorative SVGs from AT, and replace the custom role="checkbox" button with a native checkbox input - remove unnecessary pageSize dependency from useMemo
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import { z } from "zod";
|
||||
import { PaymentStatus, QuoteType, type Prisma } from "../../generated/prisma/client";
|
||||
import {
|
||||
PaymentStatus,
|
||||
type Prisma,
|
||||
QuoteType,
|
||||
} from "../../generated/prisma/client";
|
||||
import { cache } from "../../lib/cache";
|
||||
import { prisma } from "../../lib/prisma";
|
||||
import { roundTo } from "../../lib/utils";
|
||||
@@ -87,7 +91,10 @@ export async function getBeloSellPriceForDate(
|
||||
paymentDate.getUTCFullYear(),
|
||||
paymentDate.getUTCMonth(),
|
||||
paymentDate.getUTCDate(),
|
||||
17, 0, 0, 0,
|
||||
17,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -240,7 +247,9 @@ export async function createNonPeriodicExpense(
|
||||
const isUSDC = wallet.currency === "USDC";
|
||||
|
||||
if (isUSDC && !data.usdcConversionRate) {
|
||||
throw new Error("La tasa de conversión es obligatoria para billeteras USDC");
|
||||
throw new Error(
|
||||
"La tasa de conversión es obligatoria para billeteras USDC",
|
||||
);
|
||||
}
|
||||
|
||||
const belo = isUSDC ? null : await getBeloSellPriceForDate(dueDate);
|
||||
@@ -313,14 +322,17 @@ export async function payExpense(
|
||||
const isUSDC = wallet.currency === "USDC";
|
||||
|
||||
if (isUSDC && !data.usdcConversionRate) {
|
||||
throw new Error("La tasa de conversión es obligatoria para billeteras USDC");
|
||||
throw new Error(
|
||||
"La tasa de conversión es obligatoria para billeteras USDC",
|
||||
);
|
||||
}
|
||||
|
||||
const belo = isUSDC ? null : await getBeloSellPriceForDate(paymentDate);
|
||||
|
||||
const movementAmount = isUSDC && data.usdcConversionRate
|
||||
? -roundTo(data.amountPayed / data.usdcConversionRate, 4)
|
||||
: -data.amountPayed;
|
||||
const movementAmount =
|
||||
isUSDC && data.usdcConversionRate
|
||||
? -roundTo(data.amountPayed / data.usdcConversionRate, 4)
|
||||
: -data.amountPayed;
|
||||
|
||||
const expenseUpdateData: Prisma.ExpenseUncheckedUpdateInput = {
|
||||
status: PaymentStatus.PAYED,
|
||||
@@ -331,7 +343,10 @@ export async function payExpense(
|
||||
|
||||
if (isUSDC && data.usdcConversionRate) {
|
||||
expenseUpdateData.beloPrice = data.usdcConversionRate;
|
||||
expenseUpdateData.usdcEquivalent = roundTo(data.amountPayed / data.usdcConversionRate, 6);
|
||||
expenseUpdateData.usdcEquivalent = roundTo(
|
||||
data.amountPayed / data.usdcConversionRate,
|
||||
6,
|
||||
);
|
||||
} else if (belo !== null) {
|
||||
expenseUpdateData.beloPrice = belo;
|
||||
expenseUpdateData.usdcEquivalent = roundTo(data.amountPayed / belo, 6);
|
||||
@@ -405,11 +420,16 @@ export async function updateExpense(
|
||||
updateData.paymentDate = new Date(data.paymentDate);
|
||||
}
|
||||
|
||||
const resolvedPaymentDate = updateData.paymentDate instanceof Date
|
||||
? updateData.paymentDate
|
||||
: (existing.paymentDate ?? undefined);
|
||||
const resolvedPaymentDate =
|
||||
updateData.paymentDate instanceof Date
|
||||
? updateData.paymentDate
|
||||
: (existing.paymentDate ?? undefined);
|
||||
const amountPayed = updateData.amountPayed ?? existing.amountPayed;
|
||||
if (resolvedPaymentDate && amountPayed !== undefined && amountPayed !== null) {
|
||||
if (
|
||||
resolvedPaymentDate &&
|
||||
amountPayed !== undefined &&
|
||||
amountPayed !== null
|
||||
) {
|
||||
const belo = await getBeloSellPriceForDate(resolvedPaymentDate);
|
||||
if (belo !== null) {
|
||||
updateData.beloPrice = belo;
|
||||
@@ -424,9 +444,10 @@ export async function updateExpense(
|
||||
const oldPayed = existing.amountPayed
|
||||
? Number(existing.amountPayed)
|
||||
: Number(existing.amount);
|
||||
const newPayed = data.amountPayed !== undefined
|
||||
? Number(data.amountPayed)
|
||||
: Number(data.amount);
|
||||
const newPayed =
|
||||
data.amountPayed !== undefined
|
||||
? Number(data.amountPayed)
|
||||
: Number(data.amount);
|
||||
|
||||
if (newPayed !== oldPayed) {
|
||||
const difference = newPayed - oldPayed;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { Context } from "hono";
|
||||
import type { QuoteType } from "../../../generated/prisma/client";
|
||||
import { cache } from "../../../lib/cache";
|
||||
import { prisma } from "../../../lib/prisma";
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ export async function generateCodeHandler(c: Context) {
|
||||
try {
|
||||
const result = await generateCode();
|
||||
return c.json(result);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return c.json({ error: "Failed to generate code" }, 500);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ export async function telegramStatusHandler(c: Context) {
|
||||
try {
|
||||
const status = await getTelegramStatus();
|
||||
return c.json(status);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return c.json({ connected: false, botUsername: null }, 500);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import crypto from "crypto";
|
||||
import crypto from "node:crypto";
|
||||
import type { QuoteType } from "../../generated/prisma/client";
|
||||
import { logger } from "../../lib/logger";
|
||||
import { prisma } from "../../lib/prisma";
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import type { Context } from "hono";
|
||||
import {
|
||||
adjustBalance,
|
||||
adjustBalanceSchema,
|
||||
} from "../wallets.service";
|
||||
import { adjustBalance, adjustBalanceSchema } from "../wallets.service";
|
||||
|
||||
export async function adjustBalanceHandler(c: Context) {
|
||||
const id = Number(c.req.param("id"));
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import type { Context } from "hono";
|
||||
import {
|
||||
createWallet,
|
||||
createWalletSchema,
|
||||
} from "../wallets.service";
|
||||
import { createWallet, createWalletSchema } from "../wallets.service";
|
||||
|
||||
export async function createWalletHandler(c: Context) {
|
||||
const body = await c.req.json();
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import type { Context } from "hono";
|
||||
import {
|
||||
depositWallet,
|
||||
depositSchema,
|
||||
} from "../wallets.service";
|
||||
import { depositSchema, depositWallet } from "../wallets.service";
|
||||
|
||||
export async function depositWalletHandler(c: Context) {
|
||||
const id = Number(c.req.param("id"));
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import type { Context } from "hono";
|
||||
import {
|
||||
transferSchema,
|
||||
transferWallet,
|
||||
} from "../wallets.service";
|
||||
import { transferSchema, transferWallet } from "../wallets.service";
|
||||
|
||||
export async function transferWalletHandler(c: Context) {
|
||||
const body = await c.req.json();
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import type { Context } from "hono";
|
||||
import {
|
||||
updateWallet,
|
||||
updateWalletSchema,
|
||||
} from "../wallets.service";
|
||||
import { updateWallet, updateWalletSchema } from "../wallets.service";
|
||||
|
||||
export async function updateWalletHandler(c: Context) {
|
||||
const id = Number(c.req.param("id"));
|
||||
|
||||
@@ -6,9 +6,9 @@ import { depositWalletHandler } from "./handlers/depositWallet";
|
||||
import { listAllMovementsHandler } from "./handlers/listAllMovements";
|
||||
import { listMovementsHandler } from "./handlers/listMovements";
|
||||
import { listWalletsHandler } from "./handlers/listWallets";
|
||||
import { setDefaultWalletHandler } from "./handlers/setDefaultWallet";
|
||||
import { transferWalletHandler } from "./handlers/transferWallet";
|
||||
import { updateWalletHandler } from "./handlers/updateWallet";
|
||||
import { setDefaultWalletHandler } from "./handlers/setDefaultWallet";
|
||||
|
||||
const app = new Hono();
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { z } from "zod";
|
||||
import { Prisma } from "../../generated/prisma/client";
|
||||
import { prisma } from "../../lib/prisma";
|
||||
import { cache } from "../../lib/cache";
|
||||
import { prisma } from "../../lib/prisma";
|
||||
|
||||
export const createWalletSchema = z.object({
|
||||
name: z.string().min(1).max(100),
|
||||
@@ -80,7 +79,9 @@ export async function updateWallet(id: number, input: UpdateWalletInput) {
|
||||
export async function deleteWallet(id: number) {
|
||||
const wallet = await prisma.wallet.findUniqueOrThrow({ where: { id } });
|
||||
if (Number(wallet.balance) !== 0) {
|
||||
throw new Error("No se puede eliminar una billetera con saldo distinto de cero");
|
||||
throw new Error(
|
||||
"No se puede eliminar una billetera con saldo distinto de cero",
|
||||
);
|
||||
}
|
||||
await prisma.walletMovement.deleteMany({ where: { walletId: id } });
|
||||
await prisma.wallet.delete({ where: { id } });
|
||||
@@ -182,7 +183,9 @@ export async function setDefaultWallet(walletId: number) {
|
||||
data: { isDefault: true },
|
||||
}),
|
||||
]);
|
||||
const wallet = await prisma.wallet.findUniqueOrThrow({ where: { id: walletId } });
|
||||
const wallet = await prisma.wallet.findUniqueOrThrow({
|
||||
where: { id: walletId },
|
||||
});
|
||||
return { ...wallet, balance: Number(wallet.balance) };
|
||||
}
|
||||
|
||||
|
||||
@@ -800,7 +800,6 @@ describe("payExpense with BELO", () => {
|
||||
amountPayed: null,
|
||||
paymentDate: null,
|
||||
};
|
||||
const paymentDate = new Date("2026-06-10T00:00:00.000Z");
|
||||
const wallet = { id: 1, balance: 100000, currency: "ARS" };
|
||||
mockPrisma.expense.findUniqueOrThrow.mockResolvedValueOnce(expense);
|
||||
mockWalletFindUnique.mockResolvedValueOnce(wallet);
|
||||
@@ -884,17 +883,15 @@ describe("createNonPeriodicExpense with BELO", () => {
|
||||
})
|
||||
.mockResolvedValueOnce(null);
|
||||
|
||||
mockPrisma.expense.create.mockImplementationOnce(
|
||||
async ({ data }) => ({
|
||||
id: 1,
|
||||
description: data.description,
|
||||
amount: data.amount,
|
||||
amountPayed: data.amountPayed,
|
||||
status: PaymentStatus.PAYED,
|
||||
beloPrice: data.beloPrice,
|
||||
usdcEquivalent: data.usdcEquivalent,
|
||||
}),
|
||||
);
|
||||
mockPrisma.expense.create.mockImplementationOnce(async ({ data }) => ({
|
||||
id: 1,
|
||||
description: data.description,
|
||||
amount: data.amount,
|
||||
amountPayed: data.amountPayed,
|
||||
status: PaymentStatus.PAYED,
|
||||
beloPrice: data.beloPrice,
|
||||
usdcEquivalent: data.usdcEquivalent,
|
||||
}));
|
||||
mockWalletUpdate.mockResolvedValueOnce({ ...wallet, balance: 70000 });
|
||||
mockMovementCreate.mockResolvedValueOnce({ id: 1 });
|
||||
|
||||
@@ -916,15 +913,13 @@ describe("createNonPeriodicExpense with BELO", () => {
|
||||
.mockResolvedValueOnce(null)
|
||||
.mockResolvedValueOnce(null);
|
||||
|
||||
mockPrisma.expense.create.mockImplementationOnce(
|
||||
async ({ data }) => ({
|
||||
id: 1,
|
||||
description: data.description,
|
||||
amount: data.amount,
|
||||
amountPayed: data.amountPayed,
|
||||
status: PaymentStatus.PAYED,
|
||||
}),
|
||||
);
|
||||
mockPrisma.expense.create.mockImplementationOnce(async ({ data }) => ({
|
||||
id: 1,
|
||||
description: data.description,
|
||||
amount: data.amount,
|
||||
amountPayed: data.amountPayed,
|
||||
status: PaymentStatus.PAYED,
|
||||
}));
|
||||
mockWalletUpdate.mockResolvedValueOnce({ ...wallet, balance: 97500 });
|
||||
mockMovementCreate.mockResolvedValueOnce({ id: 1 });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user