ผูก log เมนูทะเบียนประวัติ

This commit is contained in:
AdisakKanthawilang 2024-10-03 15:57:44 +07:00
parent 5643cc67c4
commit 6539804937
76 changed files with 909 additions and 431 deletions

View file

@ -57,6 +57,14 @@ export async function expressAuthentication(
break;
}
if (!request.app.locals.logData) {
request.app.locals.logData = {};
}
request.app.locals.logData.userId = payload.sub;
request.app.locals.logData.userName = payload.name;
request.app.locals.logData.user = payload.preferred_username;
return payload;
}

View file

@ -4,6 +4,12 @@ import HttpStatus from "../interfaces/http-status";
import { ValidateError } from "tsoa";
function error(error: Error, _req: Request, res: Response, _next: NextFunction) {
const logData = _req.app.locals.logData.sequence?.at(-1);
if (logData) {
logData.status = "error";
logData.description = error.message;
}
if (error instanceof HttpError) {
return res.status(error.status).json({
status: error.status,

View file

@ -41,9 +41,9 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
let system = "org";
if (req.url.startsWith("/api/v1/org/metadata/")) system="metadata";
if (req.url.startsWith("/api/v1/org/auth/authRoleAttr/")) system = "admin";
if (req.url.startsWith("/api/v1/org/auth/authRoleAttr/")) system = "admin";
if (req.url.startsWith("/api/v1/org/auth/authRoleAttr/")) system = "admin";
if (req.url.startsWith("/api/v1/org/auth/authRoleAttr/")) system = "admin";
if (req.url.startsWith("/api/v1/org/profile/")) system = "profile";
// if (req.url.startsWith("/api/v1/org/auth/authRoleAttr/")) system = "admin";
// if (req.url.startsWith("/api/v1/org/auth/authRoleAttr/")) system = "admin";
const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "debug"] || 4;