.
This commit is contained in:
parent
41edc1bf72
commit
3965c807e1
@ -14,7 +14,6 @@ export function createApp(): Application {
|
|||||||
app.set("port", process.env.PORT ?? 3002);
|
app.set("port", process.env.PORT ?? 3002);
|
||||||
|
|
||||||
// secure apps by setting various HTTP headers
|
// secure apps by setting various HTTP headers
|
||||||
app.use(helmet());
|
|
||||||
app.disable("x-powered-by");
|
app.disable("x-powered-by");
|
||||||
|
|
||||||
// Middlewares
|
// Middlewares
|
||||||
@ -24,6 +23,18 @@ export function createApp(): Application {
|
|||||||
|
|
||||||
app.use(responseTime()); // set up the response-time middleware
|
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
|
// Inicializar Auth Provider
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
authProvider.initialize();
|
authProvider.initialize();
|
||||||
@ -35,11 +46,11 @@ export function createApp(): Application {
|
|||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Registrar rutas de la API
|
|
||||||
app.use("/api/v1", v1Routes());
|
|
||||||
|
|
||||||
// Gestión global de errores
|
// Gestión global de errores
|
||||||
app.use(globalErrorHandler);
|
app.use(globalErrorHandler);
|
||||||
|
|
||||||
|
// Registrar rutas de la API
|
||||||
|
app.use("/api/v1", v1Routes());
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,7 +36,11 @@ export class UniqueID extends ValueObject<string> {
|
|||||||
return this.props;
|
return this.props;
|
||||||
}
|
}
|
||||||
|
|
||||||
toPrimitive(): string {
|
toString(): string {
|
||||||
return this.props;
|
return this.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
toPrimitive() {
|
||||||
|
return this.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,8 +27,8 @@ export class UtcDate extends ValueObject<IUtcDateProps> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Crea una instancia de UtcDate a partir de un string en formato UTC.
|
* 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)
|
* @param dateString Fecha en formato UTC (con o sin hora YYYY-MM-DD)
|
||||||
* @returns UtcDate si es válida, Error en caso contrario.
|
* @returns UtcDate si es válida, Error en caso contrario.
|
||||||
*/
|
*/
|
||||||
static create(dateString: string): Result<UtcDate, Error> {
|
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() {
|
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 {
|
toISOString(): string {
|
||||||
return this.date.toISOString();
|
return this.date.toISOString();
|
||||||
|
|||||||
@ -82,14 +82,14 @@ const initLogger = () => {
|
|||||||
// If we're not in production then log to the `console` with the format:
|
// If we're not in production then log to the `console` with the format:
|
||||||
// `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
|
// `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
|
||||||
//
|
//
|
||||||
//if (!config.isProduction) {
|
if (!isProduction) {
|
||||||
logger.add(
|
logger.add(
|
||||||
new transports.Console({
|
new transports.Console({
|
||||||
format: consoleFormat,
|
format: consoleFormat,
|
||||||
level: "debug",
|
level: "debug",
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
//}
|
}
|
||||||
|
|
||||||
return logger;
|
return logger;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -66,7 +66,7 @@ export class CreateInvoiceUseCase {
|
|||||||
invoiceSeries: invoiceSeriesOrError.data,
|
invoiceSeries: invoiceSeriesOrError.data,
|
||||||
issueDate: issueDateOrError.data,
|
issueDate: issueDateOrError.data,
|
||||||
operationDate: operationDateOrError.data,
|
operationDate: operationDateOrError.data,
|
||||||
//invoiceCurrency: defaultCurrency.
|
invoiceCurrency: dto.currency_code,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*if (errors.length > 0) {
|
/*if (errors.length > 0) {
|
||||||
|
|||||||
@ -35,4 +35,8 @@ export class InvoiceNumber extends ValueObject<IInvoiceNumberProps> {
|
|||||||
toString(): string {
|
toString(): string {
|
||||||
return this.getValue();
|
return this.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toPrimitive() {
|
||||||
|
return this.getValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,4 +43,8 @@ export class InvoiceSerie extends ValueObject<IInvoiceSerieProps> {
|
|||||||
toString(): string {
|
toString(): string {
|
||||||
return this.getValue();
|
return this.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toPrimitive() {
|
||||||
|
return this.getValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -73,13 +73,13 @@ export default (sequelize: Sequelize) => {
|
|||||||
},
|
},
|
||||||
|
|
||||||
issue_date: {
|
issue_date: {
|
||||||
type: new DataTypes.DATE(),
|
type: new DataTypes.DATEONLY(),
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
defaultValue: null,
|
defaultValue: null,
|
||||||
},
|
},
|
||||||
|
|
||||||
operation_date: {
|
operation_date: {
|
||||||
type: new DataTypes.DATE(),
|
type: new DataTypes.DATEONLY(),
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
defaultValue: null,
|
defaultValue: null,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -15,7 +15,7 @@ export const createInvoicePresenter: ICreateInvoicePresenter = {
|
|||||||
issue_date: invoice.issueDate.toDateString(),
|
issue_date: invoice.issueDate.toDateString(),
|
||||||
operation_date: invoice.operationDate.toDateString(),
|
operation_date: invoice.operationDate.toDateString(),
|
||||||
language_code: "es",
|
language_code: "es",
|
||||||
currency: invoice.currency,
|
currency: invoice.invoiceCurrency || "EUR",
|
||||||
subtotal: invoice.calculateSubtotal().toPrimitive(),
|
subtotal: invoice.calculateSubtotal().toPrimitive(),
|
||||||
total: invoice.calculateTotal().toPrimitive(),
|
total: invoice.calculateTotal().toPrimitive(),
|
||||||
|
|
||||||
|
|||||||
@ -12,10 +12,10 @@ export const getInvoicePresenter: IGetInvoicePresenter = {
|
|||||||
invoice_status: invoice.status.toString(),
|
invoice_status: invoice.status.toString(),
|
||||||
invoice_number: invoice.invoiceNumber.toString(),
|
invoice_number: invoice.invoiceNumber.toString(),
|
||||||
invoice_series: invoice.invoiceSeries.toString(),
|
invoice_series: invoice.invoiceSeries.toString(),
|
||||||
issue_date: invoice.issueDate.toISOString(),
|
issue_date: invoice.issueDate.toDateString(),
|
||||||
operation_date: invoice.operationDate.toISOString(),
|
operation_date: invoice.operationDate.toDateString(),
|
||||||
language_code: "ES",
|
language_code: "ES",
|
||||||
currency: invoice.currency,
|
currency: invoice.invoiceCurrency.toString(),
|
||||||
subtotal: invoice.calculateSubtotal().toPrimitive(),
|
subtotal: invoice.calculateSubtotal().toPrimitive(),
|
||||||
total: invoice.calculateTotal().toPrimitive(),
|
total: invoice.calculateTotal().toPrimitive(),
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
//export * from "./create-invoice";
|
export * from "./create-invoice";
|
||||||
//export * from "./delete-invoice";
|
//export * from "./delete-invoice";
|
||||||
export * from "./get-invoice";
|
export * from "./get-invoice";
|
||||||
export * from "./list-invoices";
|
export * from "./list-invoices";
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
import { validateRequestDTO } from "@common/presentation";
|
import { validateRequestDTO } from "@common/presentation";
|
||||||
import {
|
import {
|
||||||
|
buildCreateInvoiceController,
|
||||||
buildGetInvoiceController,
|
buildGetInvoiceController,
|
||||||
buildListInvoicesController,
|
buildListInvoicesController,
|
||||||
IGetInvoiceRequestSchema,
|
IGetInvoiceRequestSchema,
|
||||||
IListInvoicesRequestSchema,
|
IListInvoicesRequestSchema,
|
||||||
} from "@contexts/invoices/presentation";
|
} from "@contexts/invoices/presentation";
|
||||||
|
|
||||||
import { NextFunction, Request, Response, Router } from "express";
|
import { NextFunction, Request, Response, Router } from "express";
|
||||||
|
|
||||||
export const invoicesRouter = (appRouter: Router) => {
|
export const invoicesRouter = (appRouter: Router) => {
|
||||||
@ -30,16 +32,17 @@ export const invoicesRouter = (appRouter: Router) => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
/*routes.post(
|
routes.post(
|
||||||
"/",
|
"/",
|
||||||
validateRequestDTO(ICreateInvoiceRequestSchema),
|
//validateRequestDTO(ICreateInvoiceRequestSchema),
|
||||||
checkTabContext,
|
//checkTabContext,
|
||||||
//checkUser,
|
//checkUser,
|
||||||
(req: Request, res: Response, next: NextFunction) => {
|
(req: Request, res: Response, next: NextFunction) => {
|
||||||
buildCreateInvoiceController().execute(req, res, next);
|
buildCreateInvoiceController().execute(req, res, next);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
routes.put(
|
routes.put(
|
||||||
"/:invoiceId",
|
"/:invoiceId",
|
||||||
validateRequestDTO(IUpdateInvoiceRequestSchema),
|
validateRequestDTO(IUpdateInvoiceRequestSchema),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user