add checkRootDna
This commit is contained in:
parent
84dbbf67c3
commit
d19fa67cf2
2 changed files with 35 additions and 2 deletions
|
|
@ -250,6 +250,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");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
|
||||||
let rootId = null
|
let rootId = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
rootId = token ? await new permission().checkOrg(token, req.app.locals.logData.userId) : null
|
rootId = token ? await new permission().checkRootDna(token, req.app.locals.logData.userId) : null
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn("Error fetching rootId:", err)
|
console.warn("Error fetching rootId:", err)
|
||||||
}
|
}
|
||||||
|
|
@ -57,7 +57,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: "probation",
|
systemName: "probation",
|
||||||
startTimeStamp: timestamp,
|
startTimeStamp: timestamp,
|
||||||
endTimeStamp: new Date().toISOString(),
|
endTimeStamp: new Date().toISOString(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue