This commit is contained in:
David Arranz 2025-04-01 17:32:53 +02:00
parent 41edc1bf72
commit 3965c807e1
12 changed files with 56 additions and 30 deletions

View File

@ -14,7 +14,6 @@ export function createApp(): Application {
app.set("port", process.env.PORT ?? 3002);
// secure apps by setting various HTTP headers
app.use(helmet());
app.disable("x-powered-by");
// Middlewares
@ -24,6 +23,18 @@ export function createApp(): Application {
app.use(responseTime()); // set up the response-time middleware
// secure apps by setting various HTTP headers
app.use(helmet());
// Middleware global para desactivar la caché en todas las rutas
app.use((req, res, next) => {
res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0");
res.setHeader("Pragma", "no-cache");
res.setHeader("Expires", "0");
res.setHeader("etag", "false");
next(); // Continúa con la siguiente función middleware o la ruta
});
// Inicializar Auth Provider
app.use((req, res, next) => {
authProvider.initialize();
@ -35,11 +46,11 @@ export function createApp(): Application {
next();
});
// Registrar rutas de la API
app.use("/api/v1", v1Routes());
// Gestión global de errores
app.use(globalErrorHandler);
// Registrar rutas de la API
app.use("/api/v1", v1Routes());
return app;
}

View File

@ -36,7 +36,11 @@ export class UniqueID extends ValueObject<string> {
return this.props;
}
toPrimitive(): string {
return this.props;
toString(): string {
return this.getValue();
}
toPrimitive() {
return this.getValue();
}
}

View File

@ -27,8 +27,8 @@ export class UtcDate extends ValueObject<IUtcDateProps> {
}
/**
* Crea una instancia de UtcDate a partir de un string en formato UTC.
* @param dateString Fecha en formato UTC (con o sin hora)
* Crea una instancia de UtcDate a partir de un string en formato UTC ISO 8601.
* @param dateString Fecha en formato UTC (con o sin hora YYYY-MM-DD)
* @returns UtcDate si es válida, Error en caso contrario.
*/
static create(dateString: string): Result<UtcDate, Error> {
@ -45,10 +45,10 @@ export class UtcDate extends ValueObject<IUtcDateProps> {
}
/**
* Devuelve la fecha completa en formato UTC con hora. Ejemplo: 2025-12-31T23:59:59Z.
* Devuelve la fecha completa en formato UTC con hora (ISO 8601). Ejemplo: 2025-12-31T23:59:59Z.
*/
toPrimitive() {
return this.getValue();
return this.toISOString();
}
/**
@ -59,7 +59,7 @@ export class UtcDate extends ValueObject<IUtcDateProps> {
}
/**
* Devuelve la fecha en formato UTC con hora (ISO 8601).
* Devuelve la fecha en formato UTC con hora (ISO 8601). Ejemplo: 2025-12-31T23:59:59Z.
*/
toISOString(): string {
return this.date.toISOString();

View File

@ -82,14 +82,14 @@ const initLogger = () => {
// If we're not in production then log to the `console` with the format:
// `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
//
//if (!config.isProduction) {
logger.add(
new transports.Console({
format: consoleFormat,
level: "debug",
})
);
//}
if (!isProduction) {
logger.add(
new transports.Console({
format: consoleFormat,
level: "debug",
})
);
}
return logger;
};

View File

@ -66,7 +66,7 @@ export class CreateInvoiceUseCase {
invoiceSeries: invoiceSeriesOrError.data,
issueDate: issueDateOrError.data,
operationDate: operationDateOrError.data,
//invoiceCurrency: defaultCurrency.
invoiceCurrency: dto.currency_code,
};
/*if (errors.length > 0) {

View File

@ -35,4 +35,8 @@ export class InvoiceNumber extends ValueObject<IInvoiceNumberProps> {
toString(): string {
return this.getValue();
}
toPrimitive() {
return this.getValue();
}
}

View File

@ -43,4 +43,8 @@ export class InvoiceSerie extends ValueObject<IInvoiceSerieProps> {
toString(): string {
return this.getValue();
}
toPrimitive() {
return this.getValue();
}
}

View File

@ -73,13 +73,13 @@ export default (sequelize: Sequelize) => {
},
issue_date: {
type: new DataTypes.DATE(),
type: new DataTypes.DATEONLY(),
allowNull: true,
defaultValue: null,
},
operation_date: {
type: new DataTypes.DATE(),
type: new DataTypes.DATEONLY(),
allowNull: true,
defaultValue: null,
},

View File

@ -15,7 +15,7 @@ export const createInvoicePresenter: ICreateInvoicePresenter = {
issue_date: invoice.issueDate.toDateString(),
operation_date: invoice.operationDate.toDateString(),
language_code: "es",
currency: invoice.currency,
currency: invoice.invoiceCurrency || "EUR",
subtotal: invoice.calculateSubtotal().toPrimitive(),
total: invoice.calculateTotal().toPrimitive(),

View File

@ -12,10 +12,10 @@ export const getInvoicePresenter: IGetInvoicePresenter = {
invoice_status: invoice.status.toString(),
invoice_number: invoice.invoiceNumber.toString(),
invoice_series: invoice.invoiceSeries.toString(),
issue_date: invoice.issueDate.toISOString(),
operation_date: invoice.operationDate.toISOString(),
issue_date: invoice.issueDate.toDateString(),
operation_date: invoice.operationDate.toDateString(),
language_code: "ES",
currency: invoice.currency,
currency: invoice.invoiceCurrency.toString(),
subtotal: invoice.calculateSubtotal().toPrimitive(),
total: invoice.calculateTotal().toPrimitive(),

View File

@ -1,4 +1,4 @@
//export * from "./create-invoice";
export * from "./create-invoice";
//export * from "./delete-invoice";
export * from "./get-invoice";
export * from "./list-invoices";

View File

@ -1,10 +1,12 @@
import { validateRequestDTO } from "@common/presentation";
import {
buildCreateInvoiceController,
buildGetInvoiceController,
buildListInvoicesController,
IGetInvoiceRequestSchema,
IListInvoicesRequestSchema,
} from "@contexts/invoices/presentation";
import { NextFunction, Request, Response, Router } from "express";
export const invoicesRouter = (appRouter: Router) => {
@ -30,16 +32,17 @@ export const invoicesRouter = (appRouter: Router) => {
}
);
/*routes.post(
routes.post(
"/",
validateRequestDTO(ICreateInvoiceRequestSchema),
checkTabContext,
//validateRequestDTO(ICreateInvoiceRequestSchema),
//checkTabContext,
//checkUser,
(req: Request, res: Response, next: NextFunction) => {
buildCreateInvoiceController().execute(req, res, next);
}
);
/*
routes.put(
"/:invoiceId",
validateRequestDTO(IUpdateInvoiceRequestSchema),