.
This commit is contained in:
parent
cb1e076a7b
commit
d66a175f32
@ -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<string, any>;
|
||||
}
|
||||
|
||||
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(),
|
||||
});
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
import { ContextFactory, IContext } from "@/contexts/common/infrastructure";
|
||||
import { config } from "../../../config";
|
||||
|
||||
export interface IProfileContext extends IContext {
|
||||
defaults: Record<string, any>;
|
||||
}
|
||||
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}`);
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user