no message

This commit is contained in:
kittapath 2024-10-10 00:35:17 +07:00
parent 46b3df5e95
commit e43c29dbc4
9 changed files with 1095 additions and 29 deletions

View file

@ -25,6 +25,10 @@ import { RequestWithUser } from "../middlewares/user";
import { PermissionOrg } from "../entities/PermissionOrg";
import { Profile } from "../entities/Profile";
import HttpStatus from "../interfaces/http-status";
import permission from "../interfaces/permission";
import { PosMaster } from "../entities/PosMaster";
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { ProfileEmployee } from "../entities/ProfileEmployee";
@Route("api/v1/org/permission-org")
@Tags("PermissionOrg")
@ -39,6 +43,10 @@ export class PermissionOrgController extends Controller {
private profileRepository = AppDataSource.getRepository(Profile);
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
private permissionOrgRepository = AppDataSource.getRepository(PermissionOrg);
private posMasterRepository = AppDataSource.getRepository(PosMaster);
private posMasterEmpRepository = AppDataSource.getRepository(EmployeePosMaster);
private profileRepo = AppDataSource.getRepository(Profile);
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
/**
* API
@ -55,15 +63,28 @@ export class PermissionOrgController extends Controller {
where: { orgRevisionIsCurrent: false, orgRevisionIsDraft: true },
});
if (!orgRevisionActive) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบโครงสร้างที่แบบร่างอยู่ตอนนี้");
return new HttpSuccess([]);
}
const data = await this.orgRootRepository.find({
where: { orgRevisionId: orgRevisionActive.id },
order: {
orgRootOrder: "ASC",
},
});
let _data: any = [null];
if (!request.user.role.includes("SUPER_ADMIN")) {
_data = await this.listAuthSysOrgFuncByRevisionId(request, "SYS_ORG", orgRevisionActive.id);
}
console.log(_data);
const data = await AppDataSource.getRepository(OrgRoot)
.createQueryBuilder("orgRoot")
.where("orgRoot.orgRevisionId = :id", { id: orgRevisionActive.id })
.andWhere(
_data != undefined && _data != null
? _data[0] != null
? `orgRoot.id IN (:...node)`
: `orgRoot.id is null`
: "1=1",
{
node: _data,
},
)
.orderBy("orgRoot.orgRootOrder", "ASC")
.getMany();
return new HttpSuccess(data);
}
@ -500,4 +521,44 @@ export class PermissionOrgController extends Controller {
await this.permissionOrgRepository.delete(_delPermissionOrg.id);
return new HttpSuccess();
}
public async listAuthSysOrgFuncByRevisionId(
request: RequestWithUser,
system: string,
revisionId: string,
) {
let profile = await this.profileRepo.findOne({
where: {
keycloak: request.user.sub,
// current_holders: { orgRevisionId: revisionId },
},
relations: ["next_holders", "next_holders.authRole", "next_holders.authRole.authRoles"],
});
console.log(request.user.sub);
console.log(revisionId);
console.log(profile);
if (!profile) {
return [null];
}
let attrOwnership =
profile?.next_holders
.filter((x) => x.orgRevisionId == revisionId)[0]
?.authRole?.authRoles?.filter((x) => x.authSysId == system)[0]?.attrOwnership || null;
const posMaster = await this.posMasterRepository.findOne({
where: {
next_holderId: profile.id,
orgRevisionId: revisionId,
},
});
console.log(posMaster);
console.log(attrOwnership);
if (!posMaster) {
return [null];
} else if (attrOwnership == "OWNER") {
return null;
} else {
return [posMaster.orgRootId];
}
}
}