เพิ่มเงื่อนไขการสร้างแบบร่างโครงสร้าง #1024

This commit is contained in:
AdisakKanthawilang 2024-10-15 16:54:18 +07:00
parent cd9f17867a
commit 766888d01c

View file

@ -33,6 +33,7 @@ import permission from "../interfaces/permission";
import { PermissionOrg } from "../entities/PermissionOrg";
import FunctionMain from "../interfaces/functionMain";
import { setLogDataDiff } from "../interfaces/utils";
import { AuthRole } from "../entities/AuthRole";
@Route("api/v1/org")
@Tags("Organization")
@ -54,6 +55,7 @@ export class OrganizationController extends Controller {
private positionRepository = AppDataSource.getRepository(Position);
private salaryRepository = AppDataSource.getRepository(ProfileSalary);
private profileRepo = AppDataSource.getRepository(Profile);
private authRoleRepo = AppDataSource.getRepository(AuthRole);
/**
* API
@ -114,7 +116,7 @@ export class OrganizationController extends Controller {
}
/**
* API 4
* API
*
* @summary ORG_022 - #23
*
@ -124,6 +126,7 @@ export class OrganizationController extends Controller {
@Body() requestBody: CreateOrgRevision,
@Request() request: RequestWithUser,
) {
console.log("fucntion draft");
//new main revision
const before = null;
const revision = Object.assign(new OrgRevision(), requestBody) as OrgRevision;
@ -141,7 +144,9 @@ export class OrganizationController extends Controller {
if (
requestBody.typeDraft.toUpperCase() == "ORG" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON"
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
//cone by revisionId
if (requestBody.orgRevisionId == null)
@ -217,10 +222,13 @@ export class OrganizationController extends Controller {
where: { orgRevisionId: requestBody.orgRevisionId },
relations: ["positions"],
});
let _orgPosMaster: PosMaster[];
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON"
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
_orgPosMaster = orgPosMaster.map((x) => ({
...x,
@ -246,7 +254,9 @@ export class OrganizationController extends Controller {
await this.orgRootRepository.save(data);
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON"
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
//create posmaster
await Promise.all(
@ -256,12 +266,23 @@ export class OrganizationController extends Controller {
delete item.id;
const posMaster = Object.assign(new PosMaster(), item);
posMaster.positions = [];
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON") {
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
posMaster.next_holderId = item.current_holderId;
} else {
posMaster.next_holderId = null;
posMaster.isSit = false;
}
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
posMaster.authRoleId = item.authRoleId;
} else {
posMaster.authRoleId = null;
}
posMaster.current_holderId = null;
posMaster.orgRevisionId = revision.id;
posMaster.orgRootId = data.id;
@ -278,7 +299,10 @@ export class OrganizationController extends Controller {
delete pos.id;
const position = Object.assign(new Position(), pos);
position.posMasterId = posMaster.id;
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
) {
position.positionIsSelected = false;
}
position.createdUserId = request.user.sub;
@ -321,12 +345,23 @@ export class OrganizationController extends Controller {
delete item.id;
const posMaster = Object.assign(new PosMaster(), item);
posMaster.positions = [];
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON") {
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
posMaster.next_holderId = item.current_holderId;
} else {
posMaster.next_holderId = null;
posMaster.isSit = false;
}
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
posMaster.authRoleId = item.authRoleId;
} else {
posMaster.authRoleId = null;
}
posMaster.current_holderId = null;
posMaster.orgRevisionId = revision.id;
posMaster.orgRootId = data.id;
@ -344,7 +379,10 @@ export class OrganizationController extends Controller {
delete pos.id;
const position = Object.assign(new Position(), pos);
position.posMasterId = posMaster.id;
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
) {
position.positionIsSelected = false;
}
position.createdUserId = request.user.sub;
@ -388,12 +426,23 @@ export class OrganizationController extends Controller {
delete item.id;
const posMaster = Object.assign(new PosMaster(), item);
posMaster.positions = [];
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON") {
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
posMaster.next_holderId = item.current_holderId;
} else {
posMaster.next_holderId = null;
posMaster.isSit = false;
}
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
posMaster.authRoleId = item.authRoleId;
} else {
posMaster.authRoleId = null;
}
posMaster.current_holderId = null;
posMaster.orgRevisionId = revision.id;
posMaster.orgRootId = data.id;
@ -412,7 +461,10 @@ export class OrganizationController extends Controller {
delete pos.id;
const position = Object.assign(new Position(), pos);
position.posMasterId = posMaster.id;
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
) {
position.positionIsSelected = false;
}
position.createdUserId = request.user.sub;
@ -459,12 +511,23 @@ export class OrganizationController extends Controller {
delete item.id;
const posMaster = Object.assign(new PosMaster(), item);
posMaster.positions = [];
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON") {
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
posMaster.next_holderId = item.current_holderId;
} else {
posMaster.next_holderId = null;
posMaster.isSit = false;
}
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
posMaster.authRoleId = item.authRoleId;
} else {
posMaster.authRoleId = null;
}
posMaster.current_holderId = null;
posMaster.orgRevisionId = revision.id;
posMaster.orgRootId = data.id;
@ -484,7 +547,10 @@ export class OrganizationController extends Controller {
delete pos.id;
const position = Object.assign(new Position(), pos);
position.posMasterId = posMaster.id;
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
) {
position.positionIsSelected = false;
}
position.createdUserId = request.user.sub;
@ -529,12 +595,23 @@ export class OrganizationController extends Controller {
delete item.id;
const posMaster = Object.assign(new PosMaster(), item);
posMaster.positions = [];
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON") {
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
posMaster.next_holderId = item.current_holderId;
} else {
posMaster.next_holderId = null;
posMaster.isSit = false;
}
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
posMaster.authRoleId = item.authRoleId;
} else {
posMaster.authRoleId = null;
}
posMaster.current_holderId = null;
posMaster.orgRevisionId = revision.id;
posMaster.orgRootId = data.id;
@ -555,7 +632,10 @@ export class OrganizationController extends Controller {
delete pos.id;
const position = Object.assign(new Position(), pos);
position.posMasterId = posMaster.id;
if (requestBody.typeDraft.toUpperCase() == "ORG_POSITION") {
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
) {
position.positionIsSelected = false;
}
position.createdUserId = request.user.sub;
@ -575,7 +655,7 @@ export class OrganizationController extends Controller {
});
});
}
const _orgRevisions = await this.orgRevisionRepository.find({
where: [{ orgRevisionIsDraft: true, id: Not(revision.id) }],
});