diff --git a/server/src/contexts/common/infrastructure/ContextFactory.ts b/server/src/contexts/common/infrastructure/ContextFactory.ts index 1f1287c..cb9edd7 100644 --- a/server/src/contexts/common/infrastructure/ContextFactory.ts +++ b/server/src/contexts/common/infrastructure/ContextFactory.ts @@ -1,9 +1,11 @@ +import { config } from "../../../config"; import { IRepositoryManager, RepositoryManager } from "../domain"; import { ISequelizeAdapter, createSequelizeAdapter } from "./sequelize"; export interface IContext { adapter: ISequelizeAdapter; repositoryManager: IRepositoryManager; + defaults: Record; } export class ContextFactory { @@ -12,6 +14,7 @@ export class ContextFactory { public static getInstance(): IContext { if (!ContextFactory.instance) { ContextFactory.instance = new ContextFactory({ + defaults: config.defaults, // Agregamos los valores específicos de ProfileContext adapter: createSequelizeAdapter(), repositoryManager: RepositoryManager.getInstance(), }); diff --git a/server/src/contexts/profile/infrastructure/Profile.context.ts b/server/src/contexts/profile/infrastructure/Profile.context.ts index 6ff6001..20caa96 100644 --- a/server/src/contexts/profile/infrastructure/Profile.context.ts +++ b/server/src/contexts/profile/infrastructure/Profile.context.ts @@ -1,9 +1,6 @@ import { ContextFactory, IContext } from "@/contexts/common/infrastructure"; -import { config } from "../../../config"; -export interface IProfileContext extends IContext { - defaults: Record; -} +export interface IProfileContext extends IContext {} export class ProfileContext extends ContextFactory { protected static instance: ProfileContext | null = null; @@ -13,7 +10,6 @@ export class ProfileContext extends ContextFactory { try { ProfileContext.instance = new ProfileContext({ ...ContextFactory.getInstance(), // Reutilizamos el contexto de la clase base - defaults: config.defaults, // Agregamos los valores específicos de ProfileContext }); } catch (error: unknown) { throw new Error(`Error initializing ProfileContext: ${(error as Error).message}`); diff --git a/server/src/contexts/sales/infrastructure/Sales.context.ts b/server/src/contexts/sales/infrastructure/Sales.context.ts index f1af694..b8f70ee 100644 --- a/server/src/contexts/sales/infrastructure/Sales.context.ts +++ b/server/src/contexts/sales/infrastructure/Sales.context.ts @@ -1,6 +1,4 @@ -import { RepositoryManager } from "@/contexts/common/domain"; -import { IContext } from "@/contexts/common/infrastructure"; -import { createSequelizeAdapter } from "@/contexts/common/infrastructure/sequelize"; +import { ContextFactory, IContext } from "@/contexts/common/infrastructure"; import { Dealer, IQuoteReferenceGeneratorService } from "../domain"; export interface ISalesContext extends IContext { @@ -10,23 +8,24 @@ export interface ISalesContext extends IContext { dealer?: Dealer; } -export class SalesContext { - private static instance: SalesContext | null = null; +export class SalesContext extends ContextFactory { + protected static instance: SalesContext | null = null; public static getInstance(): ISalesContext { if (!SalesContext.instance) { - SalesContext.instance = new SalesContext({ - adapter: createSequelizeAdapter(), - repositoryManager: RepositoryManager.getInstance(), - }); + try { + SalesContext.instance = new SalesContext({ + ...ContextFactory.getInstance(), // Reutilizamos el contexto de la clase base + }); + } catch (error: unknown) { + throw new Error(`Error initializing SalesContext: ${(error as Error).message}`); + } } return SalesContext.instance.context; } - private context: ISalesContext; - private constructor(context: ISalesContext) { - this.context = context; + super(context); // Llamamos al constructor de la clase base } } diff --git a/server/src/infrastructure/express/api/routes/profile.routes.ts b/server/src/infrastructure/express/api/routes/profile.routes.ts index ddaab94..9fd94f1 100644 --- a/server/src/infrastructure/express/api/routes/profile.routes.ts +++ b/server/src/infrastructure/express/api/routes/profile.routes.ts @@ -8,7 +8,6 @@ import { import { createGetProfileLogoController } from "@/contexts/profile/infrastructure/express/controllers/getProfileLogo"; import { createUploadProfileLogoController } from "@/contexts/profile/infrastructure/express/controllers/uploadProfileLogo"; import { NextFunction, Request, Response, Router } from "express"; -import multer from "multer"; import { createMulterMiddleware } from "../upload.middleware"; const uploadProfileLogo = createMulterMiddleware({ @@ -34,18 +33,7 @@ export const profileRouter = (appRouter: Router) => { profileRoutes.post( "/logo", checkUser, - (req, res, next) => { - uploadProfileLogo.single("logo")(req, res, (err) => { - if (err instanceof multer.MulterError) { - // Error relacionado con Multer (e.g. tamaño del archivo excedido) - return res.status(400).json({ error: err.message }); - } else if (err) { - // Otro tipo de error - return res.status(500).json({ error: "Error uploading the file" }); - } - next(); - }); - }, + uploadProfileLogo.single("logo"), handleRequest(createUploadProfileLogoController) );