แก้สิด admin
This commit is contained in:
parent
ec036d4c59
commit
439564f04e
4 changed files with 70 additions and 83 deletions
|
|
@ -25,6 +25,7 @@ import { OrgChild3 } from "../entities/OrgChild3";
|
|||
import { OrgChild4 } from "../entities/OrgChild4";
|
||||
import { PosMaster } from "../entities/PosMaster";
|
||||
import { Position } from "../entities/Position";
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
import { ProfileSalary } from "../entities/ProfileSalary";
|
||||
import { Profile } from "../entities/Profile";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
|
|
@ -1419,39 +1420,62 @@ export class OrganizationController extends Controller {
|
|||
*/
|
||||
@Get("super-admin/{id}")
|
||||
async detailSuperAdmin(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
let _data: any = {
|
||||
root: null,
|
||||
child1: null,
|
||||
child2: null,
|
||||
child3: null,
|
||||
child4: null,
|
||||
};
|
||||
// let _data: any = {
|
||||
// root: null,
|
||||
// child1: null,
|
||||
// child2: null,
|
||||
// child3: null,
|
||||
// child4: null,
|
||||
// };
|
||||
|
||||
const orgRevision = await this.orgRevisionRepository.findOne({ where: { id } });
|
||||
if (!orgRevision) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
// const orgRevision = await this.orgRevisionRepository.findOne({ where: { id } });
|
||||
// if (!orgRevision) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
// }
|
||||
// if (!request.user.role.includes("SUPER_ADMIN")) {
|
||||
// if (orgRevision.orgRevisionIsDraft == true && orgRevision.orgRevisionIsCurrent == false) {
|
||||
// _data = await this.listAuthSysOrgFuncByRevisionIdN(request, "SYS_ORG", orgRevision.id);
|
||||
// } else {
|
||||
// _data = await this.listAuthSysOrgFuncByRevisionIdC(request, "SYS_ORG", orgRevision.id);
|
||||
// }
|
||||
// }
|
||||
|
||||
const orgRevision = await this.orgRevisionRepository.findOne({
|
||||
where: { id: id },
|
||||
relations: ["posMasters"],
|
||||
});
|
||||
if (!orgRevision) return new HttpSuccess([]);
|
||||
|
||||
let rootId: any = null;
|
||||
if (!request.user.role.includes("SUPER_ADMIN")) {
|
||||
if (orgRevision.orgRevisionIsDraft == true && orgRevision.orgRevisionIsCurrent == false) {
|
||||
_data = await this.listAuthSysOrgFuncByRevisionIdN(request, "SYS_ORG", orgRevision.id);
|
||||
} else {
|
||||
_data = await this.listAuthSysOrgFuncByRevisionIdC(request, "SYS_ORG", orgRevision.id);
|
||||
const profile = await this.profileRepo.findOne({
|
||||
where: {
|
||||
keycloak: request.user.sub,
|
||||
},
|
||||
});
|
||||
if (profile == null) return new HttpSuccess([]);
|
||||
|
||||
if (!request.user.role.includes("SUPER_ADMIN")) {
|
||||
if (orgRevision.orgRevisionIsDraft == true && orgRevision.orgRevisionIsCurrent == false) {
|
||||
rootId =
|
||||
orgRevision?.posMasters?.filter((x) => x.next_holderId == profile.id)[0]?.orgRootId ||
|
||||
null;
|
||||
if (!rootId) return new HttpSuccess([]);
|
||||
} else {
|
||||
rootId =
|
||||
orgRevision?.posMasters?.filter((x) => x.current_holderId == profile.id)[0]
|
||||
?.orgRootId || null;
|
||||
if (!rootId) return new HttpSuccess([]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const orgRootData = await AppDataSource.getRepository(OrgRoot)
|
||||
.createQueryBuilder("orgRoot")
|
||||
.where("orgRoot.orgRevisionId = :id", { id })
|
||||
.andWhere(
|
||||
_data.root != undefined && _data.root != null
|
||||
? _data.root[0] != null
|
||||
? `orgRoot.id IN (:...node)`
|
||||
: `orgRoot.id is null`
|
||||
: "1=1",
|
||||
{
|
||||
node: _data.root,
|
||||
},
|
||||
)
|
||||
.andWhere(rootId != null ? `orgRoot.id = :rootId` : "1=1", {
|
||||
rootId: rootId,
|
||||
})
|
||||
.select([
|
||||
"orgRoot.id",
|
||||
"orgRoot.orgRootName",
|
||||
|
|
@ -1474,16 +1498,6 @@ export class OrganizationController extends Controller {
|
|||
? await AppDataSource.getRepository(OrgChild1)
|
||||
.createQueryBuilder("orgChild1")
|
||||
.where("orgChild1.orgRootId IN (:...ids)", { ids: orgRootIds })
|
||||
// .andWhere(
|
||||
// _data.child1 != undefined && _data.child1 != null
|
||||
// ? _data.child1[0] != null
|
||||
// ? `orgChild1.id IN (:...node)`
|
||||
// : `orgChild1.id is null`
|
||||
// : "1=1",
|
||||
// {
|
||||
// node: _data.child1,
|
||||
// },
|
||||
// )
|
||||
.select([
|
||||
"orgChild1.id",
|
||||
"orgChild1.isOfficer",
|
||||
|
|
@ -1509,16 +1523,6 @@ export class OrganizationController extends Controller {
|
|||
? await AppDataSource.getRepository(OrgChild2)
|
||||
.createQueryBuilder("orgChild2")
|
||||
.where("orgChild2.orgChild1Id IN (:...ids)", { ids: orgChild1Ids })
|
||||
// .andWhere(
|
||||
// _data.child2 != undefined && _data.child2 != null
|
||||
// ? _data.child2[0] != null
|
||||
// ? `orgChild2.id IN (:...node)`
|
||||
// : `orgChild2.id is null`
|
||||
// : "1=1",
|
||||
// {
|
||||
// node: _data.child2,
|
||||
// },
|
||||
// )
|
||||
.select([
|
||||
"orgChild2.id",
|
||||
"orgChild2.orgChild2Name",
|
||||
|
|
@ -1544,16 +1548,6 @@ export class OrganizationController extends Controller {
|
|||
? await AppDataSource.getRepository(OrgChild3)
|
||||
.createQueryBuilder("orgChild3")
|
||||
.where("orgChild3.orgChild2Id IN (:...ids)", { ids: orgChild2Ids })
|
||||
// .andWhere(
|
||||
// _data.child3 != undefined && _data.child3 != null
|
||||
// ? _data.child3[0] != null
|
||||
// ? `orgChild3.id IN (:...node)`
|
||||
// : `orgChild3.id is null`
|
||||
// : "1=1",
|
||||
// {
|
||||
// node: _data.child3,
|
||||
// },
|
||||
// )
|
||||
.select([
|
||||
"orgChild3.id",
|
||||
"orgChild3.orgChild3Name",
|
||||
|
|
@ -1579,16 +1573,6 @@ export class OrganizationController extends Controller {
|
|||
? await AppDataSource.getRepository(OrgChild4)
|
||||
.createQueryBuilder("orgChild4")
|
||||
.where("orgChild4.orgChild3Id IN (:...ids)", { ids: orgChild3Ids })
|
||||
// .andWhere(
|
||||
// _data.child4 != undefined && _data.child4 != null
|
||||
// ? _data.child4[0] != null
|
||||
// ? `orgChild4.id IN (:...node)`
|
||||
// : `orgChild4.id is null`
|
||||
// : "1=1",
|
||||
// {
|
||||
// node: _data.child4,
|
||||
// },
|
||||
// )
|
||||
.select([
|
||||
"orgChild4.id",
|
||||
"orgChild4.orgChild4Name",
|
||||
|
|
|
|||
|
|
@ -56,32 +56,33 @@ export class PermissionOrgController extends Controller {
|
|||
*/
|
||||
@Get()
|
||||
async GetActiveRootIdAdmin(@Request() request: RequestWithUser) {
|
||||
// if (!request.user.role.includes("SUPER_ADMIN")) {
|
||||
// throw new HttpError(HttpStatus.FORBIDDEN, "ไม่มีสิทธิ์ใช้งานระบบนี้");
|
||||
// }
|
||||
const orgRevisionActive = await this.orgRevisionRepository.findOne({
|
||||
where: { orgRevisionIsCurrent: false, orgRevisionIsDraft: true },
|
||||
relations: ["posMasters"],
|
||||
});
|
||||
if (!orgRevisionActive) {
|
||||
return new HttpSuccess([]);
|
||||
}
|
||||
let _data: any = null;
|
||||
if (!orgRevisionActive) return new HttpSuccess([]);
|
||||
let rootId: any = null;
|
||||
if (!request.user.role.includes("SUPER_ADMIN")) {
|
||||
_data = await this.listAuthSysOrgFuncByRevisionId(request, "SYS_ORG", orgRevisionActive.id);
|
||||
const profile = await this.profileRepo.findOne({
|
||||
where: {
|
||||
keycloak: request.user.sub,
|
||||
},
|
||||
});
|
||||
if (profile == null) return new HttpSuccess([]);
|
||||
|
||||
if (!request.user.role.includes("SUPER_ADMIN")) {
|
||||
rootId =
|
||||
orgRevisionActive?.posMasters?.filter((x) => x.next_holderId == profile.id)[0]
|
||||
?.orgRootId || null;
|
||||
if (!rootId) return new HttpSuccess([]);
|
||||
}
|
||||
}
|
||||
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,
|
||||
},
|
||||
)
|
||||
.andWhere(rootId != null ? `orgRoot.id = :rootId` : "1=1", {
|
||||
rootId: rootId,
|
||||
})
|
||||
.orderBy("orgRoot.orgRootOrder", "ASC")
|
||||
.getMany();
|
||||
return new HttpSuccess(data);
|
||||
|
|
|
|||
|
|
@ -123,6 +123,7 @@ export class ProfileEditController extends Controller {
|
|||
const _data = getProfileEdit.map((item) => ({
|
||||
id: item.id,
|
||||
idcard: item.profile.citizenId,
|
||||
profileId: item.profile.id,
|
||||
topic: item.topic,
|
||||
detail: item.detail,
|
||||
status: item.status,
|
||||
|
|
|
|||
|
|
@ -130,6 +130,7 @@ export class ProfileEditEmployeeController extends Controller {
|
|||
const _data = getProfileEdit.map((item) => ({
|
||||
id: item.id,
|
||||
idcard: item.profile.citizenId,
|
||||
profileId: item.profile.id,
|
||||
topic: item.topic,
|
||||
detail: item.detail,
|
||||
status: item.status,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue