comment create org
This commit is contained in:
parent
4056a2aa7f
commit
0ee2c08f41
1 changed files with 30 additions and 20 deletions
|
|
@ -121,6 +121,7 @@ export class OrganizationController extends Controller {
|
|||
@Body() requestBody: CreateOrgRevision,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
//new main revision
|
||||
const revision = Object.assign(new OrgRevision(), requestBody) as OrgRevision;
|
||||
revision.orgRevisionIsDraft = true;
|
||||
revision.orgRevisionIsCurrent = false;
|
||||
|
|
@ -132,11 +133,13 @@ export class OrganizationController extends Controller {
|
|||
revision.lastUpdatedAt = new Date();
|
||||
await this.orgRevisionRepository.save(revision);
|
||||
|
||||
//cone tree
|
||||
if (
|
||||
requestBody.typeDraft.toUpperCase() == "ORG" ||
|
||||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
||||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON"
|
||||
) {
|
||||
//cone by revisionId
|
||||
if (requestBody.orgRevisionId == null)
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
const _revision = await this.orgRevisionRepository.findOne({
|
||||
|
|
@ -144,8 +147,7 @@ export class OrganizationController extends Controller {
|
|||
});
|
||||
if (!_revision) throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
|
||||
let positions: Position[] = [];
|
||||
//clone data
|
||||
//หา dna tree ถ้าไม่มีให้เอาตัวเองเป็น dna
|
||||
const orgRoot = await this.orgRootRepository.find({
|
||||
where: { orgRevisionId: requestBody.orgRevisionId },
|
||||
});
|
||||
|
|
@ -206,6 +208,7 @@ export class OrganizationController extends Controller {
|
|||
}));
|
||||
await this.child4Repository.save(_orgChild4);
|
||||
|
||||
//หา dna posmaster ถ้าไม่มีให้เอาตัวเองเป็น dna
|
||||
const orgPosMaster = await this.posMasterRepository.find({
|
||||
where: { orgRevisionId: requestBody.orgRevisionId },
|
||||
relations: ["positions"],
|
||||
|
|
@ -224,7 +227,7 @@ export class OrganizationController extends Controller {
|
|||
}));
|
||||
await this.posMasterRepository.save(_orgPosMaster);
|
||||
}
|
||||
|
||||
//create org
|
||||
_orgRoot.forEach(async (x: any) => {
|
||||
var dataId = x.id;
|
||||
delete x.id;
|
||||
|
|
@ -241,6 +244,7 @@ export class OrganizationController extends Controller {
|
|||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
||||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON"
|
||||
) {
|
||||
//create posmaster
|
||||
await Promise.all(
|
||||
_orgPosMaster
|
||||
.filter((x: PosMaster) => x.orgRootId == dataId && x.orgChild1Id == null)
|
||||
|
|
@ -265,6 +269,7 @@ export class OrganizationController extends Controller {
|
|||
posMaster.lastUpdatedAt = new Date();
|
||||
await this.posMasterRepository.save(posMaster);
|
||||
|
||||
//create position
|
||||
item.positions.map(async (pos: any) => {
|
||||
delete pos.id;
|
||||
const position = Object.assign(new Position(), pos);
|
||||
|
|
@ -278,13 +283,13 @@ export class OrganizationController extends Controller {
|
|||
position.lastUpdateUserId = request.user.sub;
|
||||
position.lastUpdateFullName = request.user.name;
|
||||
position.lastUpdatedAt = new Date();
|
||||
// positions.push(position);
|
||||
await this.positionRepository.save(position);
|
||||
});
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
//create org
|
||||
_orgChild1
|
||||
.filter((x: OrgChild1) => x.orgRootId == dataId)
|
||||
.forEach(async (x: any) => {
|
||||
|
|
@ -304,6 +309,7 @@ export class OrganizationController extends Controller {
|
|||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
||||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON"
|
||||
) {
|
||||
//create posmaster
|
||||
await Promise.all(
|
||||
_orgPosMaster
|
||||
.filter((x: PosMaster) => x.orgChild1Id == data1Id && x.orgChild2Id == null)
|
||||
|
|
@ -329,6 +335,7 @@ export class OrganizationController extends Controller {
|
|||
posMaster.lastUpdatedAt = new Date();
|
||||
await this.posMasterRepository.save(posMaster);
|
||||
|
||||
//create position
|
||||
item.positions.map(async (pos: any) => {
|
||||
delete pos.id;
|
||||
const position = Object.assign(new Position(), pos);
|
||||
|
|
@ -342,13 +349,13 @@ export class OrganizationController extends Controller {
|
|||
position.lastUpdateUserId = request.user.sub;
|
||||
position.lastUpdateFullName = request.user.name;
|
||||
position.lastUpdatedAt = new Date();
|
||||
// positions.push(position);
|
||||
await this.positionRepository.save(position);
|
||||
});
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
//create org
|
||||
_orgChild2
|
||||
.filter((x: OrgChild2) => x.orgChild1Id == data1Id)
|
||||
.forEach(async (x: any) => {
|
||||
|
|
@ -369,6 +376,7 @@ export class OrganizationController extends Controller {
|
|||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
||||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON"
|
||||
) {
|
||||
//create posmaster
|
||||
await Promise.all(
|
||||
_orgPosMaster
|
||||
.filter((x: PosMaster) => x.orgChild2Id == data2Id && x.orgChild3Id == null)
|
||||
|
|
@ -395,6 +403,7 @@ export class OrganizationController extends Controller {
|
|||
posMaster.lastUpdatedAt = new Date();
|
||||
await this.posMasterRepository.save(posMaster);
|
||||
|
||||
//create position
|
||||
item.positions.map(async (pos: any) => {
|
||||
delete pos.id;
|
||||
const position = Object.assign(new Position(), pos);
|
||||
|
|
@ -408,13 +417,13 @@ export class OrganizationController extends Controller {
|
|||
position.lastUpdateUserId = request.user.sub;
|
||||
position.lastUpdateFullName = request.user.name;
|
||||
position.lastUpdatedAt = new Date();
|
||||
// positions.push(position);
|
||||
await this.positionRepository.save(position);
|
||||
});
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
//create org
|
||||
_orgChild3
|
||||
.filter((x: OrgChild3) => x.orgChild2Id == data2Id)
|
||||
.forEach(async (x: any) => {
|
||||
|
|
@ -436,6 +445,7 @@ export class OrganizationController extends Controller {
|
|||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
||||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON"
|
||||
) {
|
||||
//create posmaster
|
||||
await Promise.all(
|
||||
_orgPosMaster
|
||||
.filter(
|
||||
|
|
@ -465,6 +475,7 @@ export class OrganizationController extends Controller {
|
|||
posMaster.lastUpdatedAt = new Date();
|
||||
await this.posMasterRepository.save(posMaster);
|
||||
|
||||
//create position
|
||||
item.positions.map(async (pos: any) => {
|
||||
delete pos.id;
|
||||
const position = Object.assign(new Position(), pos);
|
||||
|
|
@ -478,13 +489,13 @@ export class OrganizationController extends Controller {
|
|||
position.lastUpdateUserId = request.user.sub;
|
||||
position.lastUpdateFullName = request.user.name;
|
||||
position.lastUpdatedAt = new Date();
|
||||
// positions.push(position);
|
||||
await this.positionRepository.save(position);
|
||||
});
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
//create org
|
||||
_orgChild4
|
||||
.filter((x: OrgChild4) => x.orgChild3Id == data3Id)
|
||||
.forEach(async (x: any) => {
|
||||
|
|
@ -535,6 +546,7 @@ export class OrganizationController extends Controller {
|
|||
posMaster.lastUpdatedAt = new Date();
|
||||
await this.posMasterRepository.save(posMaster);
|
||||
|
||||
//create position
|
||||
item.positions.map(async (pos: any) => {
|
||||
delete pos.id;
|
||||
const position = Object.assign(new Position(), pos);
|
||||
|
|
@ -548,7 +560,6 @@ export class OrganizationController extends Controller {
|
|||
position.lastUpdateUserId = request.user.sub;
|
||||
position.lastUpdateFullName = request.user.name;
|
||||
position.lastUpdatedAt = new Date();
|
||||
// positions.push(position);
|
||||
await this.positionRepository.save(position);
|
||||
});
|
||||
}),
|
||||
|
|
@ -559,7 +570,6 @@ export class OrganizationController extends Controller {
|
|||
});
|
||||
});
|
||||
});
|
||||
// await this.positionRepository.save(positions);
|
||||
}
|
||||
|
||||
const _orgRevisions = await this.orgRevisionRepository.find({
|
||||
|
|
@ -606,7 +616,7 @@ export class OrganizationController extends Controller {
|
|||
if (!orgRevision) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
|
||||
const orgRootData = await AppDataSource.getRepository(OrgRoot)
|
||||
.createQueryBuilder("orgRoot")
|
||||
.where("orgRoot.orgRevisionId = :id", { id })
|
||||
|
|
@ -3567,11 +3577,11 @@ export class OrganizationController extends Controller {
|
|||
child3: null,
|
||||
child4: null,
|
||||
};
|
||||
|
||||
|
||||
if (!request.user.role.includes("SUPER_ADMIN")) {
|
||||
_data = await new permission().PermissionOrgList(request, "SYS_ACTING");
|
||||
}
|
||||
|
||||
|
||||
const orgRevision = await this.orgRevisionRepository.findOne({ where: { id } });
|
||||
if (!orgRevision) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
@ -3646,14 +3656,14 @@ export class OrganizationController extends Controller {
|
|||
.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,
|
||||
},
|
||||
_data.child3 != undefined && _data.child3 != null
|
||||
? _data.child3[0] != null
|
||||
? `orgChild3.id IN (:...node)`
|
||||
: `orgChild3.id is null`
|
||||
: "1=1",
|
||||
{
|
||||
node: _data.child3,
|
||||
},
|
||||
)
|
||||
.leftJoinAndSelect("orgChild3.posMasters", "posMasters")
|
||||
.leftJoinAndSelect("posMasters.current_holder", "current_holder")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue