diff --git a/server/src/contexts/catalog/application/ListProductsUseCase.ts b/server/src/contexts/catalog/application/ListProductsUseCase.ts index 0f0a7e8..efd3c4b 100644 --- a/server/src/contexts/catalog/application/ListProductsUseCase.ts +++ b/server/src/contexts/catalog/application/ListProductsUseCase.ts @@ -58,7 +58,7 @@ export class ListProductsUseCase let products: ICollection = new Collection(); try { - await transaction.complete(async (t) => { + transaction.complete(async (t) => { products = await productRepoBuilder({ transaction: t }).findAll( queryCriteria ); diff --git a/server/src/contexts/catalog/infrastructure/Catalog.repository.ts b/server/src/contexts/catalog/infrastructure/Catalog.repository.ts index c9f5afd..c7a8010 100644 --- a/server/src/contexts/catalog/infrastructure/Catalog.repository.ts +++ b/server/src/contexts/catalog/infrastructure/Catalog.repository.ts @@ -32,28 +32,38 @@ export class CatalogRepository public async getById(id: UniqueID): Promise { const rawProduct: Product_Model = await this.adapter.execute( - "SELECT * FROM TABLE WHERE ID=?", + "SELECT * FROM ARTICULOS WHERE ID=?", [id.toString()] ); return this.mapper.mapToDomain(rawProduct); } + /*public async count(): number { + const result = await this.adapter.execute( + "SELECT count(*) FROM ARTICULOS", + [] + ); + + + + }*/ + public async findAll( queryCriteria?: IQueryCriteria ): Promise> { let rows: Product_Model[] = []; - const count = await this.adapter.execute( - "SELECT count(*) FROM TABLE", + const count = await this.adapter.execute( + "SELECT count(*) FROM ARTICULOS", [] ); - if (count) { + if (count[0]) { rows = await this.adapter.execute( - "SELECT * FROM TABLE", + "SELECT * FROM ARTICULOS", [] ); } - return this.mapper.mapArrayAndCountToDomain(rows, count); + return this.mapper.mapArrayAndCountToDomain(rows, count[0]); } } diff --git a/server/src/contexts/catalog/infrastructure/express/catalogRoutes.ts b/server/src/contexts/catalog/infrastructure/express/catalogRoutes.ts index 79b0e87..b418ffe 100644 --- a/server/src/contexts/catalog/infrastructure/express/catalogRoutes.ts +++ b/server/src/contexts/catalog/infrastructure/express/catalogRoutes.ts @@ -1,7 +1,7 @@ import express, { NextFunction, Request, Response, Router } from "express"; import { RepositoryManager } from "@/contexts/common/domain"; -import { createSequelizeAdapter } from "@/contexts/common/infrastructure/sequelize"; +import { createFirebirdAdapter } from "@/contexts/common/infrastructure/firebird"; import { createListProductsController } from "./controllers/listProducts"; const catalogRouter: Router = express.Router({ mergeParams: true }); @@ -17,7 +17,7 @@ catalogRouter.use(logMiddleware); const contextMiddleware = (req: Request, res: Response, next: NextFunction) => { res.locals["context"] = { - adapter: createSequelizeAdapter(), + adapter: createFirebirdAdapter(), repositoryManager: RepositoryManager.getInstance(), services: {}, }; diff --git a/server/src/contexts/catalog/infrastructure/express/controllers/index.ts b/server/src/contexts/catalog/infrastructure/express/controllers/index.ts new file mode 100644 index 0000000..802e3e2 --- /dev/null +++ b/server/src/contexts/catalog/infrastructure/express/controllers/index.ts @@ -0,0 +1 @@ +export * from "./listProducts"; diff --git a/server/src/contexts/catalog/infrastructure/express/index.ts b/server/src/contexts/catalog/infrastructure/express/index.ts new file mode 100644 index 0000000..5d84f8d --- /dev/null +++ b/server/src/contexts/catalog/infrastructure/express/index.ts @@ -0,0 +1,2 @@ +export * from "./catalogRoutes"; +export * from "./controllers"; diff --git a/server/src/contexts/catalog/infrastructure/firebird/product.model.ts b/server/src/contexts/catalog/infrastructure/firebird/product.model.ts index dd638ee..6c70fc2 100644 --- a/server/src/contexts/catalog/infrastructure/firebird/product.model.ts +++ b/server/src/contexts/catalog/infrastructure/firebird/product.model.ts @@ -1,4 +1,4 @@ -import { FirebirdModel } from "./firebird.model"; +import { FirebirdModel } from "../../../common/infrastructure/firebird/firebird.model"; export type Product_Model = FirebirdModel & { id: string; diff --git a/server/src/contexts/common/infrastructure/firebird/FirebirdAdapter.ts b/server/src/contexts/common/infrastructure/firebird/FirebirdAdapter.ts index 00a9878..20b1e4f 100644 --- a/server/src/contexts/common/infrastructure/firebird/FirebirdAdapter.ts +++ b/server/src/contexts/common/infrastructure/firebird/FirebirdAdapter.ts @@ -8,6 +8,7 @@ import { FirebirdBusinessTransaction } from "./FirebirdBusinessTransaction"; export interface IFirebirdAdapter extends IAdapter { queryBuilder: IRepositoryQueryBuilder; + startTransaction: () => FirebirdBusinessTransaction; disconnect: () => void; execute: (query: string, params: any[]) => Promise; sync: () => void; @@ -59,9 +60,8 @@ export class FirebirdAdapter implements IFirebirdAdapter { if (err) { throw err; } - - endConnection(); }); + endConnection(); } } @@ -71,7 +71,7 @@ export class FirebirdAdapter implements IFirebirdAdapter { if (err) { return reject(err); } - db.query(query, params, (err, result) => { + db.execute(query, params, (err, result) => { if (err) { return reject(err); } diff --git a/server/src/contexts/common/infrastructure/firebird/FirebirdBusinessTransaction.ts b/server/src/contexts/common/infrastructure/firebird/FirebirdBusinessTransaction.ts index 2e30757..6a6498b 100644 --- a/server/src/contexts/common/infrastructure/firebird/FirebirdBusinessTransaction.ts +++ b/server/src/contexts/common/infrastructure/firebird/FirebirdBusinessTransaction.ts @@ -23,7 +23,7 @@ export class FirebirdBusinessTransaction } public complete( - work: (t: Firebird.Transaction, db: Firebird.Database) => unknown + work: (t: Firebird.Transaction, db?: Firebird.Database) => unknown ): void { this._connection.get((err, db: Firebird.Database) => { if (err) { diff --git a/server/src/contexts/catalog/infrastructure/firebird/firebird.model.ts b/server/src/contexts/common/infrastructure/firebird/firebird.model.ts similarity index 100% rename from server/src/contexts/catalog/infrastructure/firebird/firebird.model.ts rename to server/src/contexts/common/infrastructure/firebird/firebird.model.ts diff --git a/server/src/infrastructure/express/api/v1.ts b/server/src/infrastructure/express/api/v1.ts index f9214e7..fa1e681 100644 --- a/server/src/infrastructure/express/api/v1.ts +++ b/server/src/infrastructure/express/api/v1.ts @@ -1,3 +1,4 @@ +import { catalogRouter } from "@/contexts/catalog/infrastructure/express/catalogRoutes"; import express from "express"; const v1Router = express.Router({ mergeParams: true }); @@ -6,4 +7,6 @@ v1Router.get("/hello", (req, res) => { res.send("Hello world!"); }); +v1Router.use("/catalog", catalogRouter); + export { v1Router }; diff --git a/server/src/infrastructure/express/app.ts b/server/src/infrastructure/express/app.ts index 1d5b936..103da96 100644 --- a/server/src/infrastructure/express/app.ts +++ b/server/src/infrastructure/express/app.ts @@ -2,9 +2,9 @@ import rTracer from "cls-rtracer"; import cors from "cors"; import express from "express"; import helmet from "helmet"; -import morgan from "morgan"; import responseTime from "response-time"; +import morgan from "morgan"; import { initLogger } from "../logger"; import { v1Router } from "./api/v1"; @@ -13,7 +13,7 @@ const logger = initLogger(rTracer); // Create Express server const app = express(); -app.use(rTracer.expressMiddleware()); +//app.use(rTracer.expressMiddleware()); app.disable("x-powered-by"); app.use(express.json()); app.use(express.text()); diff --git a/server/src/infrastructure/http/server.ts b/server/src/infrastructure/http/server.ts index 58e1400..e6f509d 100644 --- a/server/src/infrastructure/http/server.ts +++ b/server/src/infrastructure/http/server.ts @@ -86,8 +86,6 @@ const serverConnection = (conn: any) => { const key = `${conn.remoteAddress}:${conn.remotePort}`; currentState.connections[key] = conn; - logger.debug(currentState.connections); - conn.on("close", () => { delete currentState.connections[key]; }); @@ -138,6 +136,7 @@ try { } process.on("uncaughtException", (error: any) => { + firebirdConn.disconnect(); logger.error(`${new Date().toUTCString()} uncaughtException:`, error.message); logger.error(error.stack); //process.exit(1);