api test สิทธิ์

This commit is contained in:
kittapath 2024-08-20 13:33:03 +07:00
parent 99255ff36b
commit bd1f889fba
3 changed files with 119 additions and 2 deletions

View file

@ -217,7 +217,7 @@ export class PermissionController extends Controller {
const getAsync = promisify(redisClient.get).bind(redisClient);
const profile = await this.profileRepo.findOne({
// select: ["id"],
select: ["id"],
where: { keycloak: request.user.sub },
});
if (!profile) {
@ -252,4 +252,49 @@ export class PermissionController extends Controller {
return new HttpSuccess(reply);
}
@Get("user/{id}")
public async listOrgUser(@Request() request: RequestWithUser,@Path() id: string) {
const redisClient = await this.redis.createClient({
host: REDIS_HOST,
port: REDIS_PORT,
});
const getAsync = promisify(redisClient.get).bind(redisClient);
const profile = await this.profileRepo.findOne({
select: ["id"],
where: { id: id },
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
}
let reply = await getAsync("user_" + profile.id);
if (reply != null) {
reply = JSON.parse(reply);
} else {
const posMaster = await this.posMasterRepository.findOne({
where: {
current_holderId: profile.id,
orgRevision: {
orgRevisionIsDraft: false,
orgRevisionIsCurrent: true,
},
},
});
if (!posMaster) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งในโครงสร้าง");
}
reply = {
orgRootId: posMaster.orgRootId,
orgChild1Id: posMaster.orgChild1Id,
orgChild2Id: posMaster.orgChild2Id,
orgChild3Id: posMaster.orgChild3Id,
orgChild4Id: posMaster.orgChild4Id,
};
redisClient.setex("user_" + profile.id, 86400, JSON.stringify(reply));
}
return new HttpSuccess(reply);
}
}