add permission brother

This commit is contained in:
kittapath 2025-12-12 01:37:44 +07:00
parent 2cb7a9ab07
commit c6fabbcf16
2 changed files with 64 additions and 49 deletions

View file

@ -94,6 +94,15 @@ class CheckAuth {
child4: null,
privilege: "ROOT",
};
} else if (privilege == "PARENT") {
data = {
root: [x.orgRootId],
child1: [null],
child2: null,
child3: null,
child4: null,
privilege: "PARENT",
};
} else if (privilege == "CHILD") {
data = {
root: node >= 0 ? [x.orgRootId] : null,
@ -103,6 +112,15 @@ class CheckAuth {
child4: node >= 4 ? [x.orgChild4Id] : null,
privilege: "CHILD",
};
} else if (privilege == "BROTHER") {
data = {
// root: node >= 0 ? [x.orgRootId] : null,
root: node >= 0 ? [x.orgRootId] : null,
child1: node >= 2 ? [x.orgChild1Id] : null,
child2: node >= 3 ? [x.orgChild2Id] : null,
child3: node >= 4 ? [x.orgChild3Id] : null,
privilege: "BROTHER",
};
} else if (privilege == "NORMAL") {
data = {
root: [x.orgRootId],
@ -185,38 +203,38 @@ class CheckAuth {
}
public async checkOrg(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/permission/checkOrg/${keycloakId}`,
false
)
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/permission/checkOrg/${keycloakId}`,
false,
);
const data = {
orgRootId: x.orgRootId,
orgChild1Id: x.orgChild1Id,
orgChild2Id: x.orgChild2Id,
orgChild3Id: x.orgChild3Id,
orgChild4Id: x.orgChild4Id,
}
const data = {
orgRootId: x.orgRootId,
orgChild1Id: x.orgChild1Id,
orgChild2Id: x.orgChild2Id,
orgChild3Id: x.orgChild3Id,
orgChild4Id: x.orgChild4Id,
};
return data
}
} catch (error) {
console.error("Error calling API:", error)
throw error
}
return data;
}
} catch (error) {
console.error("Error calling API:", error);
throw error;
}
}
public async PermissionCreate(req: RequestWithUser, system: string) {
return await this.Permission(req, system, "CREATE");