feat: enhance date handling and formatting in quotes and belo features
This commit is contained in:
@@ -25,7 +25,9 @@ export const payExpenseSchema = z.object({
|
||||
|
||||
export const updateExpenseSchema = z.object({
|
||||
amount: z.number().positive("El monto debe ser mayor a 0"),
|
||||
dueDate: z.string().datetime({ message: "La fecha debe ser una fecha ISO válida" }),
|
||||
dueDate: z
|
||||
.string()
|
||||
.datetime({ message: "La fecha debe ser una fecha ISO válida" }),
|
||||
});
|
||||
|
||||
function lastDayOfMonth(year: number, month: number): number {
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { Context } from "hono";
|
||||
import type { QuoteType } from "../../../generated/prisma/client";
|
||||
import { cache } from "../../../lib/cache";
|
||||
import { prisma } from "../../../lib/prisma";
|
||||
import { parseLocalDate, startOfNextLocalDay } from "../../../lib/utils";
|
||||
|
||||
const VALID_TYPES = ["BLUE", "BNA", "BELO"] as const;
|
||||
|
||||
@@ -22,11 +23,9 @@ export async function getDailyMinMax(c: Context) {
|
||||
|
||||
const now = new Date();
|
||||
const startDate = startDateParam
|
||||
? new Date(startDateParam)
|
||||
? parseLocalDate(startDateParam)
|
||||
: new Date(now.getFullYear(), now.getMonth(), 1);
|
||||
const endDate = endDateParam
|
||||
? new Date(new Date(endDateParam).getTime() + 86_400_000)
|
||||
: now;
|
||||
const endDate = endDateParam ? startOfNextLocalDay(endDateParam) : now;
|
||||
|
||||
if (Number.isNaN(startDate.getTime()) || Number.isNaN(endDate.getTime())) {
|
||||
return c.json({ error: "Invalid date format. Use ISO 8601." }, 400);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { Context } from "hono";
|
||||
import { cache } from "../../../lib/cache";
|
||||
import { prisma } from "../../../lib/prisma";
|
||||
import { parseLocalDate, startOfNextLocalDay } from "../../../lib/utils";
|
||||
|
||||
const VALID_TYPES = ["BLUE", "BNA", "BELO"] as const;
|
||||
|
||||
@@ -21,11 +22,9 @@ export async function getDailyQuotes(c: Context) {
|
||||
|
||||
const now = new Date();
|
||||
const startDate = startDateParam
|
||||
? new Date(startDateParam)
|
||||
? parseLocalDate(startDateParam)
|
||||
: new Date(now.getFullYear(), now.getMonth(), 1);
|
||||
const endDate = endDateParam
|
||||
? new Date(new Date(endDateParam).getTime() + 86_400_000)
|
||||
: now;
|
||||
const endDate = endDateParam ? startOfNextLocalDay(endDateParam) : now;
|
||||
|
||||
if (Number.isNaN(startDate.getTime()) || Number.isNaN(endDate.getTime())) {
|
||||
return c.json({ error: "Invalid date format. Use ISO 8601." }, 400);
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { Context } from "hono";
|
||||
import type { QuoteType } from "../../../generated/prisma/client";
|
||||
import { cache } from "../../../lib/cache";
|
||||
import { prisma } from "../../../lib/prisma";
|
||||
import { parseLocalDate, startOfNextLocalDay } from "../../../lib/utils";
|
||||
|
||||
const VALID_TYPES = ["BLUE", "BNA", "BELO"] as const;
|
||||
|
||||
@@ -23,11 +24,9 @@ export async function getQuoteHistory(c: Context) {
|
||||
|
||||
const now = new Date();
|
||||
const startDate = startDateParam
|
||||
? new Date(startDateParam)
|
||||
? parseLocalDate(startDateParam)
|
||||
: new Date(now.getFullYear(), now.getMonth(), 1);
|
||||
const endDate = endDateParam
|
||||
? new Date(new Date(endDateParam).getTime() + 86_400_000)
|
||||
: now;
|
||||
const endDate = endDateParam ? startOfNextLocalDay(endDateParam) : now;
|
||||
|
||||
if (Number.isNaN(startDate.getTime()) || Number.isNaN(endDate.getTime())) {
|
||||
return c.json({ error: "Invalid date format. Use ISO 8601." }, 400);
|
||||
|
||||
Reference in New Issue
Block a user