Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop
This commit is contained in:
commit
9265f6ec80
1 changed files with 9 additions and 3 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
import { NextFunction, Request, Response } from "express";
|
import { NextFunction, Request, Response } from "express";
|
||||||
import { Client } from "@elastic/elasticsearch";
|
import { Client } from "@elastic/elasticsearch";
|
||||||
|
import { AppDataSource } from "../database/data-source";
|
||||||
|
import { PosMaster } from "../entities/PosMaster";
|
||||||
|
|
||||||
if (!process.env.ELASTICSEARCH_INDEX) {
|
if (!process.env.ELASTICSEARCH_INDEX) {
|
||||||
throw new Error("Require ELASTICSEARCH_INDEX to store log.");
|
throw new Error("Require ELASTICSEARCH_INDEX to store log.");
|
||||||
|
|
@ -23,6 +25,7 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
|
||||||
if (!req.url.startsWith("/api/")) return next();
|
if (!req.url.startsWith("/api/")) return next();
|
||||||
|
|
||||||
let data: any;
|
let data: any;
|
||||||
|
const repoPosmaster = AppDataSource.getRepository(PosMaster);
|
||||||
|
|
||||||
const originalJson = res.json;
|
const originalJson = res.json;
|
||||||
|
|
||||||
|
|
@ -30,12 +33,15 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
|
||||||
data = v;
|
data = v;
|
||||||
return originalJson.call(this, v);
|
return originalJson.call(this, v);
|
||||||
};
|
};
|
||||||
|
|
||||||
const timestamp = new Date().toISOString();
|
const timestamp = new Date().toISOString();
|
||||||
const start = performance.now();
|
const start = performance.now();
|
||||||
|
|
||||||
req.app.locals.logData = {};
|
req.app.locals.logData = {};
|
||||||
|
|
||||||
|
const rootId = await repoPosmaster.findOne({
|
||||||
|
where: { current_holderId: req.app.locals.logData.userId },
|
||||||
|
});
|
||||||
|
|
||||||
res.on("finish", () => {
|
res.on("finish", () => {
|
||||||
if (!req.url.startsWith("/api/")) return;
|
if (!req.url.startsWith("/api/")) return;
|
||||||
let system = "organization";
|
let system = "organization";
|
||||||
|
|
@ -56,14 +62,14 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
|
||||||
if (req.url.startsWith("/api/v1/org/profile-temp/")) system = "registry";
|
if (req.url.startsWith("/api/v1/org/profile-temp/")) system = "registry";
|
||||||
|
|
||||||
const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "debug"] || 4;
|
const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "debug"] || 4;
|
||||||
|
|
||||||
if (level === 1 && res.statusCode < 500) return;
|
if (level === 1 && res.statusCode < 500) return;
|
||||||
if (level === 2 && res.statusCode < 400) return;
|
if (level === 2 && res.statusCode < 400) return;
|
||||||
if (level === 3 && res.statusCode < 200) return;
|
if (level === 3 && res.statusCode < 200) return;
|
||||||
|
|
||||||
const obj = {
|
const obj = {
|
||||||
logType: res.statusCode >= 500 ? "error" : res.statusCode >= 400 ? "warning" : "info",
|
logType: res.statusCode >= 500 ? "error" : res.statusCode >= 400 ? "warning" : "info",
|
||||||
ip: req.ip,
|
ip: req.ip,
|
||||||
|
rootId: rootId?rootId.orgRootId:null,
|
||||||
systemName: system,
|
systemName: system,
|
||||||
startTimeStamp: timestamp,
|
startTimeStamp: timestamp,
|
||||||
endTimeStamp: new Date().toISOString(),
|
endTimeStamp: new Date().toISOString(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue