.
This commit is contained in:
parent
2194ed1420
commit
ccdf2efef3
@ -58,7 +58,7 @@ export class ListProductsUseCase
|
|||||||
let products: ICollection<Product> = new Collection();
|
let products: ICollection<Product> = new Collection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await transaction.complete(async (t) => {
|
transaction.complete(async (t) => {
|
||||||
products = await productRepoBuilder({ transaction: t }).findAll(
|
products = await productRepoBuilder({ transaction: t }).findAll(
|
||||||
queryCriteria
|
queryCriteria
|
||||||
);
|
);
|
||||||
|
|||||||
@ -32,28 +32,38 @@ export class CatalogRepository
|
|||||||
|
|
||||||
public async getById(id: UniqueID): Promise<Product | null> {
|
public async getById(id: UniqueID): Promise<Product | null> {
|
||||||
const rawProduct: Product_Model = await this.adapter.execute(
|
const rawProduct: Product_Model = await this.adapter.execute(
|
||||||
"SELECT * FROM TABLE WHERE ID=?",
|
"SELECT * FROM ARTICULOS WHERE ID=?",
|
||||||
[id.toString()]
|
[id.toString()]
|
||||||
);
|
);
|
||||||
|
|
||||||
return this.mapper.mapToDomain(rawProduct);
|
return this.mapper.mapToDomain(rawProduct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*public async count(): number {
|
||||||
|
const result = await this.adapter.execute<number>(
|
||||||
|
"SELECT count(*) FROM ARTICULOS",
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
public async findAll(
|
public async findAll(
|
||||||
queryCriteria?: IQueryCriteria
|
queryCriteria?: IQueryCriteria
|
||||||
): Promise<ICollection<Product>> {
|
): Promise<ICollection<Product>> {
|
||||||
let rows: Product_Model[] = [];
|
let rows: Product_Model[] = [];
|
||||||
const count = await this.adapter.execute<number>(
|
const count = await this.adapter.execute<number[]>(
|
||||||
"SELECT count(*) FROM TABLE",
|
"SELECT count(*) FROM ARTICULOS",
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
if (count) {
|
if (count[0]) {
|
||||||
rows = await this.adapter.execute<Product_Model[]>(
|
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 express, { NextFunction, Request, Response, Router } from "express";
|
||||||
|
|
||||||
import { RepositoryManager } from "@/contexts/common/domain";
|
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";
|
import { createListProductsController } from "./controllers/listProducts";
|
||||||
|
|
||||||
const catalogRouter: Router = express.Router({ mergeParams: true });
|
const catalogRouter: Router = express.Router({ mergeParams: true });
|
||||||
@ -17,7 +17,7 @@ catalogRouter.use(logMiddleware);
|
|||||||
|
|
||||||
const contextMiddleware = (req: Request, res: Response, next: NextFunction) => {
|
const contextMiddleware = (req: Request, res: Response, next: NextFunction) => {
|
||||||
res.locals["context"] = {
|
res.locals["context"] = {
|
||||||
adapter: createSequelizeAdapter(),
|
adapter: createFirebirdAdapter(),
|
||||||
repositoryManager: RepositoryManager.getInstance(),
|
repositoryManager: RepositoryManager.getInstance(),
|
||||||
services: {},
|
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 & {
|
export type Product_Model = FirebirdModel & {
|
||||||
id: string;
|
id: string;
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import { FirebirdBusinessTransaction } from "./FirebirdBusinessTransaction";
|
|||||||
export interface IFirebirdAdapter extends IAdapter {
|
export interface IFirebirdAdapter extends IAdapter {
|
||||||
queryBuilder: IRepositoryQueryBuilder;
|
queryBuilder: IRepositoryQueryBuilder;
|
||||||
|
|
||||||
|
startTransaction: () => FirebirdBusinessTransaction;
|
||||||
disconnect: () => void;
|
disconnect: () => void;
|
||||||
execute: <T>(query: string, params: any[]) => Promise<T>;
|
execute: <T>(query: string, params: any[]) => Promise<T>;
|
||||||
sync: () => void;
|
sync: () => void;
|
||||||
@ -59,9 +60,8 @@ export class FirebirdAdapter implements IFirebirdAdapter {
|
|||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
endConnection();
|
|
||||||
});
|
});
|
||||||
|
endConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ export class FirebirdAdapter implements IFirebirdAdapter {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
db.query(query, params, (err, result) => {
|
db.execute(query, params, (err, result) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ export class FirebirdBusinessTransaction
|
|||||||
}
|
}
|
||||||
|
|
||||||
public complete(
|
public complete(
|
||||||
work: (t: Firebird.Transaction, db: Firebird.Database) => unknown
|
work: (t: Firebird.Transaction, db?: Firebird.Database) => unknown
|
||||||
): void {
|
): void {
|
||||||
this._connection.get((err, db: Firebird.Database) => {
|
this._connection.get((err, db: Firebird.Database) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { catalogRouter } from "@/contexts/catalog/infrastructure/express/catalogRoutes";
|
||||||
import express from "express";
|
import express from "express";
|
||||||
|
|
||||||
const v1Router = express.Router({ mergeParams: true });
|
const v1Router = express.Router({ mergeParams: true });
|
||||||
@ -6,4 +7,6 @@ v1Router.get("/hello", (req, res) => {
|
|||||||
res.send("Hello world!");
|
res.send("Hello world!");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
v1Router.use("/catalog", catalogRouter);
|
||||||
|
|
||||||
export { v1Router };
|
export { v1Router };
|
||||||
|
|||||||
@ -2,9 +2,9 @@ import rTracer from "cls-rtracer";
|
|||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import helmet from "helmet";
|
import helmet from "helmet";
|
||||||
import morgan from "morgan";
|
|
||||||
import responseTime from "response-time";
|
import responseTime from "response-time";
|
||||||
|
|
||||||
|
import morgan from "morgan";
|
||||||
import { initLogger } from "../logger";
|
import { initLogger } from "../logger";
|
||||||
import { v1Router } from "./api/v1";
|
import { v1Router } from "./api/v1";
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ const logger = initLogger(rTracer);
|
|||||||
// Create Express server
|
// Create Express server
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.use(rTracer.expressMiddleware());
|
//app.use(rTracer.expressMiddleware());
|
||||||
app.disable("x-powered-by");
|
app.disable("x-powered-by");
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(express.text());
|
app.use(express.text());
|
||||||
|
|||||||
@ -86,8 +86,6 @@ const serverConnection = (conn: any) => {
|
|||||||
const key = `${conn.remoteAddress}:${conn.remotePort}`;
|
const key = `${conn.remoteAddress}:${conn.remotePort}`;
|
||||||
currentState.connections[key] = conn;
|
currentState.connections[key] = conn;
|
||||||
|
|
||||||
logger.debug(currentState.connections);
|
|
||||||
|
|
||||||
conn.on("close", () => {
|
conn.on("close", () => {
|
||||||
delete currentState.connections[key];
|
delete currentState.connections[key];
|
||||||
});
|
});
|
||||||
@ -138,6 +136,7 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
process.on("uncaughtException", (error: any) => {
|
process.on("uncaughtException", (error: any) => {
|
||||||
|
firebirdConn.disconnect();
|
||||||
logger.error(`${new Date().toUTCString()} uncaughtException:`, error.message);
|
logger.error(`${new Date().toUTCString()} uncaughtException:`, error.message);
|
||||||
logger.error(error.stack);
|
logger.error(error.stack);
|
||||||
//process.exit(1);
|
//process.exit(1);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user