.
This commit is contained in:
parent
2194ed1420
commit
ccdf2efef3
@ -58,7 +58,7 @@ export class ListProductsUseCase
|
||||
let products: ICollection<Product> = new Collection();
|
||||
|
||||
try {
|
||||
await transaction.complete(async (t) => {
|
||||
transaction.complete(async (t) => {
|
||||
products = await productRepoBuilder({ transaction: t }).findAll(
|
||||
queryCriteria
|
||||
);
|
||||
|
||||
@ -32,28 +32,38 @@ export class CatalogRepository
|
||||
|
||||
public async getById(id: UniqueID): Promise<Product | null> {
|
||||
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<number>(
|
||||
"SELECT count(*) FROM ARTICULOS",
|
||||
[]
|
||||
);
|
||||
|
||||
|
||||
|
||||
}*/
|
||||
|
||||
public async findAll(
|
||||
queryCriteria?: IQueryCriteria
|
||||
): Promise<ICollection<Product>> {
|
||||
let rows: Product_Model[] = [];
|
||||
const count = await this.adapter.execute<number>(
|
||||
"SELECT count(*) FROM TABLE",
|
||||
const count = await this.adapter.execute<number[]>(
|
||||
"SELECT count(*) FROM ARTICULOS",
|
||||
[]
|
||||
);
|
||||
if (count) {
|
||||
if (count[0]) {
|
||||
rows = await this.adapter.execute<Product_Model[]>(
|
||||
"SELECT * FROM TABLE",
|
||||
"SELECT * FROM ARTICULOS",
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
return this.mapper.mapArrayAndCountToDomain(rows, count);
|
||||
return this.mapper.mapArrayAndCountToDomain(rows, count[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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: {},
|
||||
};
|
||||
|
||||
@ -0,0 +1 @@
|
||||
export * from "./listProducts";
|
||||
@ -0,0 +1,2 @@
|
||||
export * from "./catalogRoutes";
|
||||
export * from "./controllers";
|
||||
@ -1,4 +1,4 @@
|
||||
import { FirebirdModel } from "./firebird.model";
|
||||
import { FirebirdModel } from "../../../common/infrastructure/firebird/firebird.model";
|
||||
|
||||
export type Product_Model = FirebirdModel & {
|
||||
id: string;
|
||||
|
||||
@ -8,6 +8,7 @@ import { FirebirdBusinessTransaction } from "./FirebirdBusinessTransaction";
|
||||
export interface IFirebirdAdapter extends IAdapter {
|
||||
queryBuilder: IRepositoryQueryBuilder;
|
||||
|
||||
startTransaction: () => FirebirdBusinessTransaction;
|
||||
disconnect: () => void;
|
||||
execute: <T>(query: string, params: any[]) => Promise<T>;
|
||||
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);
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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 };
|
||||
|
||||
@ -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());
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user