Merge branch 'develop' into dev
All checks were successful
Build & Deploy on Dev / build (push) Successful in 51s

This commit is contained in:
Adisak 2026-01-28 17:58:57 +07:00
commit aa145824a4
2 changed files with 35 additions and 2 deletions

View file

@ -236,6 +236,39 @@ class CheckAuth {
throw error; throw error;
} }
} }
public async checkRootDna(token: any, keycloakId: string) {
const redisClient = await this.redis.createClient({
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
});
const getAsync = promisify(redisClient.get).bind(redisClient);
try {
let reply = await getAsync("org_" + keycloakId);
if (reply != null) {
reply = JSON.parse(reply);
} else {
if (!keycloakId) throw new Error("No KeycloakId provided");
const x = await new CallAPI().GetData(
{
headers: { authorization: token },
},
`/org/dotnet/user-logs/${keycloakId}`,
false,
);
const data = {
rootDnaId: x.rootDnaId,
};
return data;
}
} catch (error) {
console.error("Error calling API:", error);
throw error;
}
}
public async PermissionCreate(req: RequestWithUser, system: string) { public async PermissionCreate(req: RequestWithUser, system: string) {
return await this.Permission(req, system, "CREATE"); return await this.Permission(req, system, "CREATE");
} }

View file

@ -50,7 +50,7 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
try { try {
rootId = token rootId = token
? await new permission().checkOrg(token, req.app.locals.logData.userId) ? await new permission().checkRootDna(token, req.app.locals.logData.userId)
: null; : null;
} catch (err) { } catch (err) {
console.warn("Error fetching rootId:", err); console.warn("Error fetching rootId:", err);
@ -59,7 +59,7 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
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?.orgRootId ?? null, rootId: rootId?.rootDnaId ?? null,
systemName: "development", systemName: "development",
startTimeStamp: timestamp, startTimeStamp: timestamp,
endTimeStamp: new Date().toISOString(), endTimeStamp: new Date().toISOString(),