.
This commit is contained in:
parent
69a24e452f
commit
12331c8c48
@ -1,17 +1,13 @@
|
|||||||
import { AuthUser } from "@/contexts/auth/domain";
|
import { AuthUser } from "@/contexts/auth/domain";
|
||||||
import { generateExpressError } from "@/contexts/common/infrastructure/express";
|
import { generateExpressError } from "@/contexts/common/infrastructure/express";
|
||||||
import * as express from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import httpStatus from "http-status";
|
import httpStatus from "http-status";
|
||||||
|
|
||||||
interface AuthenticatedRequest extends express.Request {
|
interface AuthenticatedRequest extends Request {
|
||||||
user?: AuthUser;
|
user?: AuthUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
const profileMiddleware = (
|
const profileMiddleware = (req: Request, res: Response, next: NextFunction) => {
|
||||||
req: express.Request,
|
|
||||||
res: express.Response,
|
|
||||||
next: express.NextFunction
|
|
||||||
) => {
|
|
||||||
const _req = req as AuthenticatedRequest;
|
const _req = req as AuthenticatedRequest;
|
||||||
const user = <AuthUser>_req.user;
|
const user = <AuthUser>_req.user;
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { IError_Response_DTO } from "@shared/contexts";
|
import { IError_Response_DTO } from "@shared/contexts";
|
||||||
import Express from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import httpStatus from "http-status";
|
import httpStatus from "http-status";
|
||||||
import { URL } from "url";
|
import { URL } from "url";
|
||||||
import { IServerError } from "../../domain/errors";
|
import { IServerError } from "../../domain/errors";
|
||||||
@ -8,16 +8,16 @@ import { InfrastructureError } from "../InfrastructureError";
|
|||||||
import { generateExpressError } from "./ExpressErrorResponse";
|
import { generateExpressError } from "./ExpressErrorResponse";
|
||||||
|
|
||||||
export abstract class ExpressController implements IController {
|
export abstract class ExpressController implements IController {
|
||||||
protected req: Express.Request;
|
protected req: Request;
|
||||||
protected res: Express.Response;
|
protected res: Response;
|
||||||
protected next: Express.NextFunction;
|
protected next: NextFunction;
|
||||||
|
|
||||||
protected serverURL: string = "";
|
protected serverURL: string = "";
|
||||||
protected file: any;
|
protected file: any;
|
||||||
|
|
||||||
protected abstract executeImpl(): Promise<void | any>;
|
protected abstract executeImpl(): Promise<void | any>;
|
||||||
|
|
||||||
public execute(req: Express.Request, res: Express.Response, next: Express.NextFunction): void {
|
public execute(req: Request, res: Response, next: NextFunction): void {
|
||||||
this.req = req;
|
this.req = req;
|
||||||
this.res = res;
|
this.res = res;
|
||||||
this.next = next;
|
this.next = next;
|
||||||
@ -109,7 +109,7 @@ export abstract class ExpressController implements IController {
|
|||||||
return this._errorResponse(httpStatus.SERVICE_UNAVAILABLE, message);
|
return this._errorResponse(httpStatus.SERVICE_UNAVAILABLE, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _jsonResponse(statusCode: number, jsonPayload: any): Express.Response<any> {
|
private _jsonResponse(statusCode: number, jsonPayload: any): Response<any> {
|
||||||
return this.res.status(statusCode).json(jsonPayload).send();
|
return this.res.status(statusCode).json(jsonPayload).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ export abstract class ExpressController implements IController {
|
|||||||
statusCode: number,
|
statusCode: number,
|
||||||
message?: string,
|
message?: string,
|
||||||
error?: Error | InfrastructureError
|
error?: Error | InfrastructureError
|
||||||
): Express.Response<IError_Response_DTO> {
|
): Response<IError_Response_DTO> {
|
||||||
return generateExpressError(this.req, this.res, statusCode, message, error);
|
return generateExpressError(this.req, this.res, statusCode, message, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,16 +1,16 @@
|
|||||||
import { IErrorExtra_Response_DTO, IError_Response_DTO } from "@shared/contexts";
|
import { IErrorExtra_Response_DTO, IError_Response_DTO } from "@shared/contexts";
|
||||||
import Express from "express";
|
import { Request, Response } from "express";
|
||||||
import { UseCaseError } from "../../application";
|
import { UseCaseError } from "../../application";
|
||||||
import { InfrastructureError } from "../InfrastructureError";
|
import { InfrastructureError } from "../InfrastructureError";
|
||||||
import { ProblemDocument, ProblemDocumentExtension } from "./ProblemDocument";
|
import { ProblemDocument, ProblemDocumentExtension } from "./ProblemDocument";
|
||||||
|
|
||||||
export const generateExpressError = (
|
export const generateExpressError = (
|
||||||
req: Express.Request,
|
req: Request,
|
||||||
res: Express.Response,
|
res: Response,
|
||||||
statusCode: number,
|
statusCode: number,
|
||||||
message?: string,
|
message?: string,
|
||||||
error?: Error | InfrastructureError
|
error?: Error | InfrastructureError
|
||||||
): Express.Response<IError_Response_DTO> => {
|
): Response<IError_Response_DTO> => {
|
||||||
const context = {
|
const context = {
|
||||||
user: res.locals.user || undefined,
|
user: res.locals.user || undefined,
|
||||||
params: req.params || undefined,
|
params: req.params || undefined,
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
import Express from "express";
|
import { NextFunction, Request, RequestHandler, Response } from "express";
|
||||||
|
|
||||||
const registeredMiddlewares: Record<string, Express.RequestHandler> = {};
|
const registeredMiddlewares: Record<string, RequestHandler> = {};
|
||||||
|
|
||||||
function registerMiddleware(name: string, middleware: Express.RequestHandler) {
|
function registerMiddleware(name: string, middleware: RequestHandler) {
|
||||||
return (req: Express.Request, res: Express.Response, next: Express.NextFunction) => {
|
return (req: Request, res: Response, next: NextFunction) => {
|
||||||
registeredMiddlewares[name] = middleware;
|
registeredMiddlewares[name] = middleware;
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
@ -12,7 +12,7 @@ function registerMiddleware(name: string, middleware: Express.RequestHandler) {
|
|||||||
function applyMiddleware(middlewares: string | Array<string>) {
|
function applyMiddleware(middlewares: string | Array<string>) {
|
||||||
const middlewareNames = typeof middlewares === "string" ? [middlewares] : middlewares;
|
const middlewareNames = typeof middlewares === "string" ? [middlewares] : middlewares;
|
||||||
|
|
||||||
return (req: Express.Request, res: Express.Response, next: Express.NextFunction) => {
|
return (req: Request, res: Response, next: NextFunction) => {
|
||||||
middlewareNames.forEach((name) => {
|
middlewareNames.forEach((name) => {
|
||||||
const middleware = registeredMiddlewares[name];
|
const middleware = registeredMiddlewares[name];
|
||||||
if (middleware) {
|
if (middleware) {
|
||||||
@ -25,12 +25,12 @@ function applyMiddleware(middlewares: string | Array<string>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createMiddlewareMap() {
|
function createMiddlewareMap() {
|
||||||
return new Map<string, Express.RequestHandler>();
|
return new Map<string, RequestHandler>();
|
||||||
}
|
}
|
||||||
|
|
||||||
function composeMiddleware(middlewareArray: any[]) {
|
function composeMiddleware(middlewareArray: any[]) {
|
||||||
if (!middlewareArray.length) {
|
if (!middlewareArray.length) {
|
||||||
return function (req: Express.Request, res: Express.Response, next: Express.NextFunction) {
|
return function (req: Request, res: Response, next: NextFunction) {
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ function composeMiddleware(middlewareArray: any[]) {
|
|||||||
const head = middlewareArray[0];
|
const head = middlewareArray[0];
|
||||||
const tail = middlewareArray.slice(1);
|
const tail = middlewareArray.slice(1);
|
||||||
|
|
||||||
return function (req: Express.Request, res: Express.Response, next: Express.NextFunction) {
|
return function (req: Request, res: Response, next: NextFunction) {
|
||||||
head(req, res, function (err: unknown) {
|
head(req, res, function (err: unknown) {
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
composeMiddleware(tail)(req, res, next);
|
composeMiddleware(tail)(req, res, next);
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
//export * from "./CreateDealer.useCase";
|
|
||||||
//export * from "./DeleteDealer.useCase";
|
|
||||||
export * from "./GetDealer.useCase";
|
export * from "./GetDealer.useCase";
|
||||||
export * from "./GetDealerByUser.useCase";
|
export * from "./GetDealerByUser.useCase";
|
||||||
export * from "./ListDealers.useCase";
|
export * from "./ListDealers.useCase";
|
||||||
//export * from "./UpdateDealer.useCase";
|
|
||||||
|
/*export * from "./CreateDealer.useCase";
|
||||||
|
export * from "./DeleteDealer.useCase";
|
||||||
|
export * from "./UpdateDealer.useCase";*/
|
||||||
|
|
||||||
export * from "./dealerServices";
|
export * from "./dealerServices";
|
||||||
|
|||||||
@ -1,15 +1,11 @@
|
|||||||
import { CreateDealerUseCase } from "@/contexts/sales/application";
|
import { CreateDealerUseCase } from "@/contexts/sales/application";
|
||||||
import Express from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import { registerDealerRepository } from "../../../../Dealer.repository";
|
import { registerDealerRepository } from "../../../../Dealer.repository";
|
||||||
import { ISalesContext } from "../../../../Sales.context";
|
import { ISalesContext } from "../../../../Sales.context";
|
||||||
import { CreateDealerController } from "./CreateDealer.controller";
|
import { CreateDealerController } from "./CreateDealer.controller";
|
||||||
import { CreateDealerPresenter } from "./presenter";
|
import { CreateDealerPresenter } from "./presenter";
|
||||||
|
|
||||||
export const createDealerController = (
|
export const createDealerController = (req: Request, res: Response, next: NextFunction) => {
|
||||||
req: Express.Request,
|
|
||||||
res: Express.Response,
|
|
||||||
next: Express.NextFunction
|
|
||||||
) => {
|
|
||||||
const context: ISalesContext = res.locals.context;
|
const context: ISalesContext = res.locals.context;
|
||||||
|
|
||||||
registerDealerRepository(context);
|
registerDealerRepository(context);
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import { DeleteDealerUseCase } from "@/contexts/sales/application";
|
import { DeleteDealerUseCase } from "@/contexts/sales/application";
|
||||||
import Express from "express";
|
|
||||||
import { registerDealerRepository } from "../../../../Dealer.repository";
|
import { registerDealerRepository } from "../../../../Dealer.repository";
|
||||||
import { ISalesContext } from "../../../../Sales.context";
|
import { ISalesContext } from "../../../../Sales.context";
|
||||||
import { DeleteDealerController } from "./DeleteDealer.controller";
|
import { DeleteDealerController } from "./DeleteDealer.controller";
|
||||||
|
|||||||
@ -1,15 +1,11 @@
|
|||||||
import { GetDealerUseCase } from "@/contexts/sales/application";
|
import { GetDealerUseCase } from "@/contexts/sales/application";
|
||||||
import Express from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import { registerDealerRepository } from "../../../../Dealer.repository";
|
import { registerDealerRepository } from "../../../../Dealer.repository";
|
||||||
import { ISalesContext } from "../../../../Sales.context";
|
import { ISalesContext } from "../../../../Sales.context";
|
||||||
import { GetDealerController } from "./GetDealer.controller";
|
import { GetDealerController } from "./GetDealer.controller";
|
||||||
import { GetDealerPresenter } from "./presenter";
|
import { GetDealerPresenter } from "./presenter";
|
||||||
|
|
||||||
export const getDealerController = (
|
export const getDealerController = (req: Request, res: Response, next: NextFunction) => {
|
||||||
req: Express.Request,
|
|
||||||
res: Express.Response,
|
|
||||||
next: Express.NextFunction
|
|
||||||
) => {
|
|
||||||
const context: ISalesContext = res.locals.context;
|
const context: ISalesContext = res.locals.context;
|
||||||
|
|
||||||
registerDealerRepository(context);
|
registerDealerRepository(context);
|
||||||
|
|||||||
@ -1,15 +1,11 @@
|
|||||||
import { GetDealerByUserUseCase } from "@/contexts/sales/application";
|
import { GetDealerByUserUseCase } from "@/contexts/sales/application";
|
||||||
import Express from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import { registerDealerRepository } from "../../../../Dealer.repository";
|
import { registerDealerRepository } from "../../../../Dealer.repository";
|
||||||
import { ISalesContext } from "../../../../Sales.context";
|
import { ISalesContext } from "../../../../Sales.context";
|
||||||
import { GetDealerByUserController } from "./GetDealerByUser.controller";
|
import { GetDealerByUserController } from "./GetDealerByUser.controller";
|
||||||
import { GetDealerByUserPresenter } from "./presenter";
|
import { GetDealerByUserPresenter } from "./presenter";
|
||||||
|
|
||||||
export const getDealerByUserController = (
|
export const getDealerByUserController = (req: Request, res: Response, next: NextFunction) => {
|
||||||
req: Express.Request,
|
|
||||||
res: Express.Response,
|
|
||||||
next: Express.NextFunction
|
|
||||||
) => {
|
|
||||||
const context: ISalesContext = res.locals.context;
|
const context: ISalesContext = res.locals.context;
|
||||||
|
|
||||||
registerDealerRepository(context);
|
registerDealerRepository(context);
|
||||||
|
|||||||
@ -1,15 +1,11 @@
|
|||||||
import { ListDealersUseCase } from "@/contexts/sales/application";
|
import { ListDealersUseCase } from "@/contexts/sales/application";
|
||||||
import Express from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import { registerDealerRepository } from "../../../../Dealer.repository";
|
import { registerDealerRepository } from "../../../../Dealer.repository";
|
||||||
import { ISalesContext } from "../../../../Sales.context";
|
import { ISalesContext } from "../../../../Sales.context";
|
||||||
import { ListDealersController } from "./ListDealers.controller";
|
import { ListDealersController } from "./ListDealers.controller";
|
||||||
import { listDealersPresenter } from "./presenter/ListDealers.presenter";
|
import { listDealersPresenter } from "./presenter/ListDealers.presenter";
|
||||||
|
|
||||||
export const listDealersController = (
|
export const listDealersController = (req: Request, res: Response, next: NextFunction) => {
|
||||||
req: Express.Request,
|
|
||||||
res: Express.Response,
|
|
||||||
next: Express.NextFunction
|
|
||||||
) => {
|
|
||||||
const context: ISalesContext = res.locals.context;
|
const context: ISalesContext = res.locals.context;
|
||||||
|
|
||||||
registerDealerRepository(context);
|
registerDealerRepository(context);
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import { UpdateDealerUseCase } from "@/contexts/sales/application";
|
import { UpdateDealerUseCase } from "@/contexts/sales/application";
|
||||||
import Express from "express";
|
|
||||||
import { registerDealerRepository } from "../../../../Dealer.repository";
|
import { registerDealerRepository } from "../../../../Dealer.repository";
|
||||||
import { ISalesContext } from "../../../../Sales.context";
|
import { ISalesContext } from "../../../../Sales.context";
|
||||||
import { UpdateDealerController } from "./UpdateDealer.controller";
|
import { UpdateDealerController } from "./UpdateDealer.controller";
|
||||||
|
|||||||
@ -1,15 +1,11 @@
|
|||||||
import { CreateQuoteUseCase } from "@/contexts/sales/application";
|
import { CreateQuoteUseCase } from "@/contexts/sales/application";
|
||||||
import Express from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import { registerQuoteRepository } from "../../../../Quote.repository";
|
import { registerQuoteRepository } from "../../../../Quote.repository";
|
||||||
import { ISalesContext } from "../../../../Sales.context";
|
import { ISalesContext } from "../../../../Sales.context";
|
||||||
import { CreateQuoteController } from "./CreateQuote.controller";
|
import { CreateQuoteController } from "./CreateQuote.controller";
|
||||||
import { CreateQuotePresenter } from "./presenter";
|
import { CreateQuotePresenter } from "./presenter";
|
||||||
|
|
||||||
export const createQuoteController = (
|
export const createQuoteController = (req: Request, res: Response, next: NextFunction) => {
|
||||||
req: Express.Request,
|
|
||||||
res: Express.Response,
|
|
||||||
next: Express.NextFunction
|
|
||||||
) => {
|
|
||||||
const context: ISalesContext = res.locals.context;
|
const context: ISalesContext = res.locals.context;
|
||||||
|
|
||||||
registerQuoteRepository(context);
|
registerQuoteRepository(context);
|
||||||
|
|||||||
@ -1,14 +1,10 @@
|
|||||||
import { DeleteQuoteUseCase } from "@/contexts/sales/application";
|
import { DeleteQuoteUseCase } from "@/contexts/sales/application";
|
||||||
import Express from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import { registerQuoteRepository } from "../../../../Quote.repository";
|
import { registerQuoteRepository } from "../../../../Quote.repository";
|
||||||
import { ISalesContext } from "../../../../Sales.context";
|
import { ISalesContext } from "../../../../Sales.context";
|
||||||
import { DeleteQuoteController } from "./DeleteQuote.controller";
|
import { DeleteQuoteController } from "./DeleteQuote.controller";
|
||||||
|
|
||||||
export const deleteQuoteController = (
|
export const deleteQuoteController = (req: Request, res: Response, next: NextFunction) => {
|
||||||
req: Express.Request,
|
|
||||||
res: Express.Response,
|
|
||||||
next: Express.NextFunction
|
|
||||||
) => {
|
|
||||||
const context: ISalesContext = res.locals.context;
|
const context: ISalesContext = res.locals.context;
|
||||||
|
|
||||||
registerQuoteRepository(context);
|
registerQuoteRepository(context);
|
||||||
|
|||||||
@ -1,15 +1,11 @@
|
|||||||
import { GetQuoteUseCase } from "@/contexts/sales/application";
|
import { GetQuoteUseCase } from "@/contexts/sales/application";
|
||||||
import Express from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import { registerQuoteRepository } from "../../../../Quote.repository";
|
import { registerQuoteRepository } from "../../../../Quote.repository";
|
||||||
import { ISalesContext } from "../../../../Sales.context";
|
import { ISalesContext } from "../../../../Sales.context";
|
||||||
import { GetQuoteController } from "./GetQuote.controller";
|
import { GetQuoteController } from "./GetQuote.controller";
|
||||||
import { GetQuotePresenter } from "./presenter";
|
import { GetQuotePresenter } from "./presenter";
|
||||||
|
|
||||||
export const getQuoteController = (
|
export const getQuoteController = (req: Request, res: Response, next: NextFunction) => {
|
||||||
req: Express.Request,
|
|
||||||
res: Express.Response,
|
|
||||||
next: Express.NextFunction
|
|
||||||
) => {
|
|
||||||
const context: ISalesContext = res.locals.context;
|
const context: ISalesContext = res.locals.context;
|
||||||
|
|
||||||
registerQuoteRepository(context);
|
registerQuoteRepository(context);
|
||||||
|
|||||||
@ -1,15 +1,11 @@
|
|||||||
import { ListQuotesUseCase } from "@/contexts/sales/application";
|
import { ListQuotesUseCase } from "@/contexts/sales/application";
|
||||||
import { registerQuoteRepository } from "@/contexts/sales/infrastructure/Quote.repository";
|
import { registerQuoteRepository } from "@/contexts/sales/infrastructure/Quote.repository";
|
||||||
import { ISalesContext } from "@/contexts/sales/infrastructure/Sales.context";
|
import { ISalesContext } from "@/contexts/sales/infrastructure/Sales.context";
|
||||||
import Express from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import { ListQuotesController } from "./ListQuotes.controller";
|
import { ListQuotesController } from "./ListQuotes.controller";
|
||||||
import { ListQuotesPresenter } from "./presenter";
|
import { ListQuotesPresenter } from "./presenter";
|
||||||
|
|
||||||
export const listQuotesController = (
|
export const listQuotesController = (req: Request, res: Response, next: NextFunction) => {
|
||||||
req: Express.Request,
|
|
||||||
res: Express.Response,
|
|
||||||
next: Express.NextFunction
|
|
||||||
) => {
|
|
||||||
const context: ISalesContext = res.locals.context;
|
const context: ISalesContext = res.locals.context;
|
||||||
|
|
||||||
registerQuoteRepository(context);
|
registerQuoteRepository(context);
|
||||||
|
|||||||
@ -1,15 +1,11 @@
|
|||||||
import { GetQuoteUseCase } from "@/contexts/sales/application";
|
import { GetQuoteUseCase } from "@/contexts/sales/application";
|
||||||
import Express from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import { registerQuoteRepository } from "../../../../Quote.repository";
|
import { registerQuoteRepository } from "../../../../Quote.repository";
|
||||||
import { ISalesContext } from "../../../../Sales.context";
|
import { ISalesContext } from "../../../../Sales.context";
|
||||||
import { ReportQuotePresenter } from "./reporter/ReportQuote.reporter";
|
import { ReportQuotePresenter } from "./reporter/ReportQuote.reporter";
|
||||||
import { ReportQuoteController } from "./ReportQuote.controller";
|
import { ReportQuoteController } from "./ReportQuote.controller";
|
||||||
|
|
||||||
export const reportQuoteController = (
|
export const reportQuoteController = (req: Request, res: Response, next: NextFunction) => {
|
||||||
req: Express.Request,
|
|
||||||
res: Express.Response,
|
|
||||||
next: Express.NextFunction
|
|
||||||
) => {
|
|
||||||
const context: ISalesContext = res.locals.context;
|
const context: ISalesContext = res.locals.context;
|
||||||
|
|
||||||
registerQuoteRepository(context);
|
registerQuoteRepository(context);
|
||||||
|
|||||||
@ -1,14 +1,10 @@
|
|||||||
import { SetStatusQuoteUseCase } from "@/contexts/sales/application";
|
import { SetStatusQuoteUseCase } from "@/contexts/sales/application";
|
||||||
import Express from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import { registerQuoteRepository } from "../../../../Quote.repository";
|
import { registerQuoteRepository } from "../../../../Quote.repository";
|
||||||
import { ISalesContext } from "../../../../Sales.context";
|
import { ISalesContext } from "../../../../Sales.context";
|
||||||
import { SetStatusQuoteController } from "./SetStatusQuote.controller";
|
import { SetStatusQuoteController } from "./SetStatusQuote.controller";
|
||||||
|
|
||||||
export const setStatusQuoteController = (
|
export const setStatusQuoteController = (req: Request, res: Response, next: NextFunction) => {
|
||||||
req: Express.Request,
|
|
||||||
res: Express.Response,
|
|
||||||
next: Express.NextFunction
|
|
||||||
) => {
|
|
||||||
const context: ISalesContext = res.locals.context;
|
const context: ISalesContext = res.locals.context;
|
||||||
|
|
||||||
registerQuoteRepository(context);
|
registerQuoteRepository(context);
|
||||||
|
|||||||
@ -1,15 +1,11 @@
|
|||||||
import { UpdateQuoteUseCase } from "@/contexts/sales/application";
|
import { UpdateQuoteUseCase } from "@/contexts/sales/application";
|
||||||
import Express from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import { registerQuoteRepository } from "../../../../Quote.repository";
|
import { registerQuoteRepository } from "../../../../Quote.repository";
|
||||||
import { ISalesContext } from "../../../../Sales.context";
|
import { ISalesContext } from "../../../../Sales.context";
|
||||||
import { UpdateQuoteController } from "./UpdateQuote.controller";
|
import { UpdateQuoteController } from "./UpdateQuote.controller";
|
||||||
import { UpdateQuotePresenter } from "./presenter/UpdateQuote.presenter";
|
import { UpdateQuotePresenter } from "./presenter/UpdateQuote.presenter";
|
||||||
|
|
||||||
export const updateQuoteController = (
|
export const updateQuoteController = (req: Request, res: Response, next: NextFunction) => {
|
||||||
req: Express.Request,
|
|
||||||
res: Express.Response,
|
|
||||||
next: Express.NextFunction
|
|
||||||
) => {
|
|
||||||
const context: ISalesContext = res.locals.context;
|
const context: ISalesContext = res.locals.context;
|
||||||
|
|
||||||
registerQuoteRepository(context);
|
registerQuoteRepository(context);
|
||||||
|
|||||||
@ -1,15 +1,12 @@
|
|||||||
import { checkUser } from "@/contexts/auth";
|
import { checkUser } from "@/contexts/auth";
|
||||||
import Express from "express";
|
import { NextFunction, Request, Response, Router } from "express";
|
||||||
import { listArticlesController } from "../../../../contexts/catalog/infrastructure/express/controllers";
|
import { listArticlesController } from "../../../../contexts/catalog/infrastructure/express/controllers";
|
||||||
|
|
||||||
export const catalogRouter = (appRouter: Express.Router) => {
|
export const catalogRouter = (appRouter: Router) => {
|
||||||
const catalogRoutes: Express.Router = Express.Router({ mergeParams: true });
|
const catalogRoutes: Router = Router({ mergeParams: true });
|
||||||
|
|
||||||
catalogRoutes.get(
|
catalogRoutes.get("/", checkUser, (req: Request, res: Response, next: NextFunction) =>
|
||||||
"/",
|
listArticlesController(res.locals["context"]).execute(req, res, next)
|
||||||
checkUser,
|
|
||||||
(req: Express.Request, res: Express.Response, next: Express.NextFunction) =>
|
|
||||||
listArticlesController(res.locals["context"]).execute(req, res, next)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
appRouter.use("/catalog", catalogRoutes);
|
appRouter.use("/catalog", catalogRoutes);
|
||||||
|
|||||||
@ -4,10 +4,10 @@ import {
|
|||||||
listDealersController,
|
listDealersController,
|
||||||
} from "@/contexts/sales/infrastructure/express/controllers/dealers";
|
} from "@/contexts/sales/infrastructure/express/controllers/dealers";
|
||||||
import { getDealerMiddleware } from "@/contexts/sales/infrastructure/express/middlewares/dealerMiddleware";
|
import { getDealerMiddleware } from "@/contexts/sales/infrastructure/express/middlewares/dealerMiddleware";
|
||||||
import Express from "express";
|
import { Router } from "express";
|
||||||
|
|
||||||
export const DealerRouter = (appRouter: Express.Router) => {
|
export const DealerRouter = (appRouter: Router) => {
|
||||||
const dealerRoutes: Express.Router = Express.Router({ mergeParams: true });
|
const dealerRoutes: Router = Router({ mergeParams: true });
|
||||||
|
|
||||||
dealerRoutes.get("/", checkisAdmin, listDealersController);
|
dealerRoutes.get("/", checkisAdmin, listDealersController);
|
||||||
dealerRoutes.get("/:dealerId", checkUser, getDealerMiddleware, getDealerController);
|
dealerRoutes.get("/:dealerId", checkUser, getDealerMiddleware, getDealerController);
|
||||||
|
|||||||
@ -3,23 +3,17 @@ import {
|
|||||||
createGetProfileController,
|
createGetProfileController,
|
||||||
createUpdateProfileController,
|
createUpdateProfileController,
|
||||||
} from "@/contexts/profile/infrastructure";
|
} from "@/contexts/profile/infrastructure";
|
||||||
import Express from "express";
|
import { NextFunction, Request, Response, Router } from "express";
|
||||||
|
|
||||||
export const profileRouter = (appRouter: Express.Router) => {
|
export const profileRouter = (appRouter: Router) => {
|
||||||
const profileRoutes: Express.Router = Express.Router({ mergeParams: true });
|
const profileRoutes: Router = Router({ mergeParams: true });
|
||||||
|
|
||||||
profileRoutes.get(
|
profileRoutes.get("/", checkUser, (req: Request, res: Response, next: NextFunction) =>
|
||||||
"/",
|
createGetProfileController(res.locals["context"]).execute(req, res, next)
|
||||||
checkUser,
|
|
||||||
(req: Express.Request, res: Express.Response, next: Express.NextFunction) =>
|
|
||||||
createGetProfileController(res.locals["context"]).execute(req, res, next)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
profileRoutes.put(
|
profileRoutes.put("/", checkUser, (req: Request, res: Response, next: NextFunction) =>
|
||||||
"/",
|
createUpdateProfileController(res.locals["context"]).execute(req, res, next)
|
||||||
checkUser,
|
|
||||||
(req: Express.Request, res: Express.Response, next: Express.NextFunction) =>
|
|
||||||
createUpdateProfileController(res.locals["context"]).execute(req, res, next)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
appRouter.use("/profile", profileRoutes);
|
appRouter.use("/profile", profileRoutes);
|
||||||
|
|||||||
@ -8,10 +8,10 @@ import {
|
|||||||
updateQuoteController,
|
updateQuoteController,
|
||||||
} from "@/contexts/sales/infrastructure/express/controllers";
|
} from "@/contexts/sales/infrastructure/express/controllers";
|
||||||
import { getDealerMiddleware } from "@/contexts/sales/infrastructure/express/middlewares/dealerMiddleware";
|
import { getDealerMiddleware } from "@/contexts/sales/infrastructure/express/middlewares/dealerMiddleware";
|
||||||
import Express from "express";
|
import { Router } from "express";
|
||||||
|
|
||||||
export const QuoteRouter = (appRouter: Express.Router) => {
|
export const QuoteRouter = (appRouter: Router) => {
|
||||||
const quoteRoutes: Express.Router = Express.Router({ mergeParams: true });
|
const quoteRoutes: Router = Router({ mergeParams: true });
|
||||||
|
|
||||||
// Users CRUD
|
// Users CRUD
|
||||||
quoteRoutes.get("/", checkUser, getDealerMiddleware, listQuotesController);
|
quoteRoutes.get("/", checkUser, getDealerMiddleware, listQuotesController);
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { checkAdminOrSelf, checkisAdmin } from "@/contexts/auth";
|
import { checkAdminOrSelf, checkisAdmin } from "@/contexts/auth";
|
||||||
import Express from "express";
|
import { NextFunction, Request, Response, Router } from "express";
|
||||||
import {
|
import {
|
||||||
createCreateUserController,
|
createCreateUserController,
|
||||||
createDeleteUserController,
|
createDeleteUserController,
|
||||||
@ -8,42 +8,27 @@ import {
|
|||||||
createUpdateUserController,
|
createUpdateUserController,
|
||||||
} from "../../../../contexts/users/infrastructure/express/controllers";
|
} from "../../../../contexts/users/infrastructure/express/controllers";
|
||||||
|
|
||||||
export const usersRouter = (appRouter: Express.Router) => {
|
export const usersRouter = (appRouter: Router) => {
|
||||||
const userRoutes: Express.Router = Express.Router({ mergeParams: true });
|
const userRoutes: Router = Router({ mergeParams: true });
|
||||||
|
|
||||||
userRoutes.get(
|
userRoutes.get("/", checkisAdmin, (req: Request, res: Response, next: NextFunction) =>
|
||||||
"/",
|
createListUsersController(res.locals["context"]).execute(req, res, next)
|
||||||
checkisAdmin,
|
|
||||||
(req: Express.Request, res: Express.Response, next: Express.NextFunction) =>
|
|
||||||
createListUsersController(res.locals["context"]).execute(req, res, next)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
userRoutes.get(
|
userRoutes.get("/:userId", checkAdminOrSelf, (req: Request, res: Response, next: NextFunction) =>
|
||||||
"/:userId",
|
createGetUserController(res.locals["context"]).execute(req, res, next)
|
||||||
checkAdminOrSelf,
|
|
||||||
(req: Express.Request, res: Express.Response, next: Express.NextFunction) =>
|
|
||||||
createGetUserController(res.locals["context"]).execute(req, res, next)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
userRoutes.post(
|
userRoutes.post("/", checkisAdmin, (req: Request, res: Response, next: NextFunction) =>
|
||||||
"/",
|
createCreateUserController(res.locals["context"]).execute(req, res, next)
|
||||||
checkisAdmin,
|
|
||||||
(req: Express.Request, res: Express.Response, next: Express.NextFunction) =>
|
|
||||||
createCreateUserController(res.locals["context"]).execute(req, res, next)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
userRoutes.put(
|
userRoutes.put("/:userId", checkisAdmin, (req: Request, res: Response, next: NextFunction) =>
|
||||||
"/:userId",
|
createUpdateUserController(res.locals["context"]).execute(req, res, next)
|
||||||
checkisAdmin,
|
|
||||||
(req: Express.Request, res: Express.Response, next: Express.NextFunction) =>
|
|
||||||
createUpdateUserController(res.locals["context"]).execute(req, res, next)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
userRoutes.delete(
|
userRoutes.delete("/:userId", checkisAdmin, (req: Request, res: Response, next: NextFunction) =>
|
||||||
"/:userId",
|
createDeleteUserController(res.locals["context"]).execute(req, res, next)
|
||||||
checkisAdmin,
|
|
||||||
(req: Express.Request, res: Express.Response, next: Express.NextFunction) =>
|
|
||||||
createDeleteUserController(res.locals["context"]).execute(req, res, next)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
appRouter.use("/users", userRoutes);
|
appRouter.use("/users", userRoutes);
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import Express from "express";
|
import { NextFunction, Request, Response, Router } from "express";
|
||||||
import { createContextMiddleware } from "./context.middleware";
|
import { createContextMiddleware } from "./context.middleware";
|
||||||
import {
|
import {
|
||||||
DealerRouter,
|
DealerRouter,
|
||||||
@ -10,13 +10,13 @@ import {
|
|||||||
} from "./routes";
|
} from "./routes";
|
||||||
|
|
||||||
export const v1Routes = () => {
|
export const v1Routes = () => {
|
||||||
const routes = Express.Router({ mergeParams: true });
|
const routes = Router({ mergeParams: true });
|
||||||
|
|
||||||
routes.get("/hello", (req, res) => {
|
routes.get("/hello", (req, res) => {
|
||||||
res.send("Hello world!");
|
res.send("Hello world!");
|
||||||
});
|
});
|
||||||
|
|
||||||
routes.use((req: Express.Request, res: Express.Response, next: Express.NextFunction) => {
|
routes.use((req: Request, res: Response, next: NextFunction) => {
|
||||||
res.locals["context"] = createContextMiddleware();
|
res.locals["context"] = createContextMiddleware();
|
||||||
//res.locals["middlewares"] = createMiddlewareMap();
|
//res.locals["middlewares"] = createMiddlewareMap();
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"extends": "./tsconfig.json",
|
"extends": "./tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"types": ["jest"],
|
"types": ["jest"],
|
||||||
//"baseUrl": "./src",
|
"baseUrl": "./src",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["./src/*"],
|
"@/*": ["./src/*"],
|
||||||
|
|||||||
@ -75,6 +75,14 @@
|
|||||||
"src/**/*.test.*",
|
"src/**/*.test.*",
|
||||||
"node_modules",
|
"node_modules",
|
||||||
|
|
||||||
"src/**/firebird/*"
|
"src/**/firebird/*",
|
||||||
|
|
||||||
|
"src/**/CreateDealer.useCase.ts",
|
||||||
|
"src/**/UpdateDealer.useCase.ts",
|
||||||
|
"src/**/DeleteDealer.useCase.ts",
|
||||||
|
|
||||||
|
"src/**/createDealer/*",
|
||||||
|
"src/**/updateDealer/*",
|
||||||
|
"src/**/deleteDealer/*"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user