แบบร่างลูกจ้าง

This commit is contained in:
kittapath 2025-02-26 17:05:13 +07:00
parent 5dab73c141
commit a064753efd
3 changed files with 757 additions and 2 deletions

View file

@ -34,6 +34,7 @@ import { PosMasterAssign } from "../entities/PosMasterAssign";
import { PosMasterAct } from "../entities/PosMasterAct";
import { EmployeePosition } from "../entities/EmployeePosition";
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster";
@Route("api/v1/org")
@Tags("Organization")
@ -57,6 +58,7 @@ export class OrganizationController extends Controller {
private profileRepo = AppDataSource.getRepository(Profile);
private employeePosMasterRepository = AppDataSource.getRepository(EmployeePosMaster);
private employeePositionRepository = AppDataSource.getRepository(EmployeePosition);
private employeeTempPosMasterRepository = AppDataSource.getRepository(EmployeeTempPosMaster);
/**
* API
@ -243,6 +245,53 @@ export class OrganizationController extends Controller {
}));
await this.posMasterRepository.save(_orgPosMaster);
}
//หา dna posmaster ถ้าไม่มีให้เอาตัวเองเป็น dna
const orgemployeePosMaster = await this.employeePosMasterRepository.find({
where: { orgRevisionId: requestBody.orgRevisionId },
relations: ["positions"],
});
let _orgemployeePosMaster: EmployeePosMaster[];
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
_orgemployeePosMaster = orgemployeePosMaster.map((x) => ({
...x,
ancestorDNA:
x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
? x.id
: x.ancestorDNA,
}));
await this.employeePosMasterRepository.save(_orgemployeePosMaster);
}
//หา dna posmaster ถ้าไม่มีให้เอาตัวเองเป็น dna
const orgemployeeTempPosMaster = await this.employeeTempPosMasterRepository.find({
where: { orgRevisionId: requestBody.orgRevisionId },
relations: ["positions"],
});
let _orgemployeeTempPosMaster: EmployeeTempPosMaster[];
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
_orgemployeeTempPosMaster = orgemployeeTempPosMaster.map((x) => ({
...x,
ancestorDNA:
x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
? x.id
: x.ancestorDNA,
}));
await this.employeeTempPosMasterRepository.save(_orgemployeeTempPosMaster);
}
//create org
_orgRoot.forEach(async (x: any) => {
var dataId = x.id;
@ -319,6 +368,126 @@ export class OrganizationController extends Controller {
});
}),
);
//create employeePosmaster
await Promise.all(
_orgemployeePosMaster
.filter((x: EmployeePosMaster) => x.orgRootId == dataId && x.orgChild1Id == null)
.map(async (item: any) => {
delete item.id;
const employeePosMaster = Object.assign(new EmployeePosMaster(), item);
employeePosMaster.positions = [];
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
// employeePosMaster.next_holderId = item.current_holderId;
} else {
// employeePosMaster.next_holderId = null;
employeePosMaster.isSit = false;
}
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
employeePosMaster.authRoleId = item.authRoleId;
} else {
employeePosMaster.authRoleId = null;
}
// employeePosMaster.current_holderId = null;
employeePosMaster.orgRevisionId = revision.id;
employeePosMaster.orgRootId = data.id;
employeePosMaster.createdUserId = request.user.sub;
employeePosMaster.createdFullName = request.user.name;
employeePosMaster.createdAt = new Date();
employeePosMaster.lastUpdateUserId = request.user.sub;
employeePosMaster.lastUpdateFullName = request.user.name;
employeePosMaster.lastUpdatedAt = new Date();
await this.employeePosMasterRepository.save(employeePosMaster);
//create employeePosition
item.positions.map(async (pos: any) => {
delete pos.id;
const employeePosition: EmployeePosition = Object.assign(
new EmployeePosition(),
pos,
);
employeePosition.posMasterId = employeePosMaster.id;
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
) {
employeePosition.positionIsSelected = false;
}
employeePosition.createdUserId = request.user.sub;
employeePosition.createdFullName = request.user.name;
employeePosition.createdAt = new Date();
employeePosition.lastUpdateUserId = request.user.sub;
employeePosition.lastUpdateFullName = request.user.name;
employeePosition.lastUpdatedAt = new Date();
await this.employeePositionRepository.save(employeePosition);
});
}),
);
//create employeeTempPosmaster
await Promise.all(
_orgemployeeTempPosMaster
.filter((x: EmployeeTempPosMaster) => x.orgRootId == dataId && x.orgChild1Id == null)
.map(async (item: any) => {
delete item.id;
const employeeTempPosMaster = Object.assign(new EmployeeTempPosMaster(), item);
employeeTempPosMaster.positions = [];
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
// employeeTempPosMaster.next_holderId = item.current_holderId;
} else {
// employeeTempPosMaster.next_holderId = null;
employeeTempPosMaster.isSit = false;
}
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
employeeTempPosMaster.authRoleId = item.authRoleId;
} else {
employeeTempPosMaster.authRoleId = null;
}
// employeeTempPosMaster.current_holderId = null;
employeeTempPosMaster.orgRevisionId = revision.id;
employeeTempPosMaster.orgRootId = data.id;
employeeTempPosMaster.createdUserId = request.user.sub;
employeeTempPosMaster.createdFullName = request.user.name;
employeeTempPosMaster.createdAt = new Date();
employeeTempPosMaster.lastUpdateUserId = request.user.sub;
employeeTempPosMaster.lastUpdateFullName = request.user.name;
employeeTempPosMaster.lastUpdatedAt = new Date();
await this.employeeTempPosMasterRepository.save(employeeTempPosMaster);
//create employeePosition
item.positions.map(async (pos: any) => {
delete pos.id;
const employeePosition: EmployeePosition = Object.assign(
new EmployeePosition(),
pos,
);
employeePosition.posMasterTempId = employeeTempPosMaster.id;
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
) {
employeePosition.positionIsSelected = false;
}
employeePosition.createdUserId = request.user.sub;
employeePosition.createdFullName = request.user.name;
employeePosition.createdAt = new Date();
employeePosition.lastUpdateUserId = request.user.sub;
employeePosition.lastUpdateFullName = request.user.name;
employeePosition.lastUpdatedAt = new Date();
await this.employeePositionRepository.save(employeePosition);
});
}),
);
}
//create org
@ -401,6 +570,130 @@ export class OrganizationController extends Controller {
});
}),
);
//create employeePosmaster
await Promise.all(
_orgemployeePosMaster
.filter(
(x: EmployeePosMaster) => x.orgChild1Id == data1Id && x.orgChild2Id == null,
)
.map(async (item: any) => {
delete item.id;
const employeePosMaster = Object.assign(new EmployeePosMaster(), item);
employeePosMaster.positions = [];
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
// employeePosMaster.next_holderId = item.current_holderId;
} else {
// employeePosMaster.next_holderId = null;
employeePosMaster.isSit = false;
}
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
employeePosMaster.authRoleId = item.authRoleId;
} else {
employeePosMaster.authRoleId = null;
}
// employeePosMaster.current_holderId = null;
employeePosMaster.orgRevisionId = revision.id;
employeePosMaster.orgRootId = data.id;
employeePosMaster.createdUserId = request.user.sub;
employeePosMaster.createdFullName = request.user.name;
employeePosMaster.createdAt = new Date();
employeePosMaster.lastUpdateUserId = request.user.sub;
employeePosMaster.lastUpdateFullName = request.user.name;
employeePosMaster.lastUpdatedAt = new Date();
await this.employeePosMasterRepository.save(employeePosMaster);
//create employeePosition
item.positions.map(async (pos: any) => {
delete pos.id;
const employeePosition: EmployeePosition = Object.assign(
new EmployeePosition(),
pos,
);
employeePosition.posMasterId = employeePosMaster.id;
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
) {
employeePosition.positionIsSelected = false;
}
employeePosition.createdUserId = request.user.sub;
employeePosition.createdFullName = request.user.name;
employeePosition.createdAt = new Date();
employeePosition.lastUpdateUserId = request.user.sub;
employeePosition.lastUpdateFullName = request.user.name;
employeePosition.lastUpdatedAt = new Date();
await this.employeePositionRepository.save(employeePosition);
});
}),
);
//create employeeTempPosmaster
await Promise.all(
_orgemployeeTempPosMaster
.filter(
(x: EmployeeTempPosMaster) => x.orgChild1Id == data1Id && x.orgChild2Id == null,
)
.map(async (item: any) => {
delete item.id;
const employeeTempPosMaster = Object.assign(new EmployeeTempPosMaster(), item);
employeeTempPosMaster.positions = [];
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
// employeeTempPosMaster.next_holderId = item.current_holderId;
} else {
// employeeTempPosMaster.next_holderId = null;
employeeTempPosMaster.isSit = false;
}
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
employeeTempPosMaster.authRoleId = item.authRoleId;
} else {
employeeTempPosMaster.authRoleId = null;
}
// employeeTempPosMaster.current_holderId = null;
employeeTempPosMaster.orgRevisionId = revision.id;
employeeTempPosMaster.orgRootId = data.id;
employeeTempPosMaster.createdUserId = request.user.sub;
employeeTempPosMaster.createdFullName = request.user.name;
employeeTempPosMaster.createdAt = new Date();
employeeTempPosMaster.lastUpdateUserId = request.user.sub;
employeeTempPosMaster.lastUpdateFullName = request.user.name;
employeeTempPosMaster.lastUpdatedAt = new Date();
await this.employeeTempPosMasterRepository.save(employeeTempPosMaster);
//create employeePosition
item.positions.map(async (pos: any) => {
delete pos.id;
const employeePosition: EmployeePosition = Object.assign(
new EmployeePosition(),
pos,
);
employeePosition.posMasterTempId = employeeTempPosMaster.id;
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
) {
employeePosition.positionIsSelected = false;
}
employeePosition.createdUserId = request.user.sub;
employeePosition.createdFullName = request.user.name;
employeePosition.createdAt = new Date();
employeePosition.lastUpdateUserId = request.user.sub;
employeePosition.lastUpdateFullName = request.user.name;
employeePosition.lastUpdatedAt = new Date();
await this.employeePositionRepository.save(employeePosition);
});
}),
);
}
//create org
@ -485,6 +778,134 @@ export class OrganizationController extends Controller {
});
}),
);
//create employeePosmaster
await Promise.all(
_orgemployeePosMaster
.filter(
(x: EmployeePosMaster) => x.orgChild2Id == data2Id && x.orgChild3Id == null,
)
.map(async (item: any) => {
delete item.id;
const employeePosMaster = Object.assign(new EmployeePosMaster(), item);
employeePosMaster.positions = [];
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
// employeePosMaster.next_holderId = item.current_holderId;
} else {
// employeePosMaster.next_holderId = null;
employeePosMaster.isSit = false;
}
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
employeePosMaster.authRoleId = item.authRoleId;
} else {
employeePosMaster.authRoleId = null;
}
// employeePosMaster.current_holderId = null;
employeePosMaster.orgRevisionId = revision.id;
employeePosMaster.orgRootId = data.id;
employeePosMaster.createdUserId = request.user.sub;
employeePosMaster.createdFullName = request.user.name;
employeePosMaster.createdAt = new Date();
employeePosMaster.lastUpdateUserId = request.user.sub;
employeePosMaster.lastUpdateFullName = request.user.name;
employeePosMaster.lastUpdatedAt = new Date();
await this.employeePosMasterRepository.save(employeePosMaster);
//create employeePosition
item.positions.map(async (pos: any) => {
delete pos.id;
const employeePosition: EmployeePosition = Object.assign(
new EmployeePosition(),
pos,
);
employeePosition.posMasterId = employeePosMaster.id;
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
) {
employeePosition.positionIsSelected = false;
}
employeePosition.createdUserId = request.user.sub;
employeePosition.createdFullName = request.user.name;
employeePosition.createdAt = new Date();
employeePosition.lastUpdateUserId = request.user.sub;
employeePosition.lastUpdateFullName = request.user.name;
employeePosition.lastUpdatedAt = new Date();
await this.employeePositionRepository.save(employeePosition);
});
}),
);
//create employeeTempPosmaster
await Promise.all(
_orgemployeeTempPosMaster
.filter(
(x: EmployeeTempPosMaster) =>
x.orgChild2Id == data2Id && x.orgChild3Id == null,
)
.map(async (item: any) => {
delete item.id;
const employeeTempPosMaster = Object.assign(
new EmployeeTempPosMaster(),
item,
);
employeeTempPosMaster.positions = [];
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
// employeeTempPosMaster.next_holderId = item.current_holderId;
} else {
// employeeTempPosMaster.next_holderId = null;
employeeTempPosMaster.isSit = false;
}
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
employeeTempPosMaster.authRoleId = item.authRoleId;
} else {
employeeTempPosMaster.authRoleId = null;
}
// employeeTempPosMaster.current_holderId = null;
employeeTempPosMaster.orgRevisionId = revision.id;
employeeTempPosMaster.orgRootId = data.id;
employeeTempPosMaster.createdUserId = request.user.sub;
employeeTempPosMaster.createdFullName = request.user.name;
employeeTempPosMaster.createdAt = new Date();
employeeTempPosMaster.lastUpdateUserId = request.user.sub;
employeeTempPosMaster.lastUpdateFullName = request.user.name;
employeeTempPosMaster.lastUpdatedAt = new Date();
await this.employeeTempPosMasterRepository.save(employeeTempPosMaster);
//create employeePosition
item.positions.map(async (pos: any) => {
delete pos.id;
const employeePosition: EmployeePosition = Object.assign(
new EmployeePosition(),
pos,
);
employeePosition.posMasterTempId = employeeTempPosMaster.id;
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
) {
employeePosition.positionIsSelected = false;
}
employeePosition.createdUserId = request.user.sub;
employeePosition.createdFullName = request.user.name;
employeePosition.createdAt = new Date();
employeePosition.lastUpdateUserId = request.user.sub;
employeePosition.lastUpdateFullName = request.user.name;
employeePosition.lastUpdatedAt = new Date();
await this.employeePositionRepository.save(employeePosition);
});
}),
);
}
//create org
@ -573,6 +994,135 @@ export class OrganizationController extends Controller {
});
}),
);
//create employeePosmaster
await Promise.all(
_orgemployeePosMaster
.filter(
(x: EmployeePosMaster) =>
x.orgChild3Id == data3Id && x.orgChild4Id == null,
)
.map(async (item: any) => {
delete item.id;
const employeePosMaster = Object.assign(new EmployeePosMaster(), item);
employeePosMaster.positions = [];
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
// employeePosMaster.next_holderId = item.current_holderId;
} else {
// employeePosMaster.next_holderId = null;
employeePosMaster.isSit = false;
}
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
employeePosMaster.authRoleId = item.authRoleId;
} else {
employeePosMaster.authRoleId = null;
}
// employeePosMaster.current_holderId = null;
employeePosMaster.orgRevisionId = revision.id;
employeePosMaster.orgRootId = data.id;
employeePosMaster.createdUserId = request.user.sub;
employeePosMaster.createdFullName = request.user.name;
employeePosMaster.createdAt = new Date();
employeePosMaster.lastUpdateUserId = request.user.sub;
employeePosMaster.lastUpdateFullName = request.user.name;
employeePosMaster.lastUpdatedAt = new Date();
await this.employeePosMasterRepository.save(employeePosMaster);
//create employeePosition
item.positions.map(async (pos: any) => {
delete pos.id;
const employeePosition: EmployeePosition = Object.assign(
new EmployeePosition(),
pos,
);
employeePosition.posMasterId = employeePosMaster.id;
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
) {
employeePosition.positionIsSelected = false;
}
employeePosition.createdUserId = request.user.sub;
employeePosition.createdFullName = request.user.name;
employeePosition.createdAt = new Date();
employeePosition.lastUpdateUserId = request.user.sub;
employeePosition.lastUpdateFullName = request.user.name;
employeePosition.lastUpdatedAt = new Date();
await this.employeePositionRepository.save(employeePosition);
});
}),
);
//create employeeTempPosmaster
await Promise.all(
_orgemployeeTempPosMaster
.filter(
(x: EmployeeTempPosMaster) =>
x.orgChild3Id == data3Id && x.orgChild4Id == null,
)
.map(async (item: any) => {
delete item.id;
const employeeTempPosMaster = Object.assign(
new EmployeeTempPosMaster(),
item,
);
employeeTempPosMaster.positions = [];
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
// employeeTempPosMaster.next_holderId = item.current_holderId;
} else {
// employeeTempPosMaster.next_holderId = null;
employeeTempPosMaster.isSit = false;
}
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
employeeTempPosMaster.authRoleId = item.authRoleId;
} else {
employeeTempPosMaster.authRoleId = null;
}
// employeeTempPosMaster.current_holderId = null;
employeeTempPosMaster.orgRevisionId = revision.id;
employeeTempPosMaster.orgRootId = data.id;
employeeTempPosMaster.createdUserId = request.user.sub;
employeeTempPosMaster.createdFullName = request.user.name;
employeeTempPosMaster.createdAt = new Date();
employeeTempPosMaster.lastUpdateUserId = request.user.sub;
employeeTempPosMaster.lastUpdateFullName = request.user.name;
employeeTempPosMaster.lastUpdatedAt = new Date();
await this.employeeTempPosMasterRepository.save(employeeTempPosMaster);
//create employeePosition
item.positions.map(async (pos: any) => {
delete pos.id;
const employeePosition: EmployeePosition = Object.assign(
new EmployeePosition(),
pos,
);
employeePosition.posMasterTempId = employeeTempPosMaster.id;
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
) {
employeePosition.positionIsSelected = false;
}
employeePosition.createdUserId = request.user.sub;
employeePosition.createdFullName = request.user.name;
employeePosition.createdAt = new Date();
employeePosition.lastUpdateUserId = request.user.sub;
employeePosition.lastUpdateFullName = request.user.name;
employeePosition.lastUpdatedAt = new Date();
await this.employeePositionRepository.save(employeePosition);
});
}),
);
}
//create org
@ -661,6 +1211,134 @@ export class OrganizationController extends Controller {
});
}),
);
//create employeePosmaster
await Promise.all(
_orgemployeePosMaster
.filter((x: EmployeePosMaster) => x.orgChild4Id == data4Id)
.map(async (item: any) => {
delete item.id;
const employeePosMaster = Object.assign(
new EmployeePosMaster(),
item,
);
employeePosMaster.positions = [];
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
// employeePosMaster.next_holderId = item.current_holderId;
} else {
// employeePosMaster.next_holderId = null;
employeePosMaster.isSit = false;
}
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
employeePosMaster.authRoleId = item.authRoleId;
} else {
employeePosMaster.authRoleId = null;
}
// employeePosMaster.current_holderId = null;
employeePosMaster.orgRevisionId = revision.id;
employeePosMaster.orgRootId = data.id;
employeePosMaster.createdUserId = request.user.sub;
employeePosMaster.createdFullName = request.user.name;
employeePosMaster.createdAt = new Date();
employeePosMaster.lastUpdateUserId = request.user.sub;
employeePosMaster.lastUpdateFullName = request.user.name;
employeePosMaster.lastUpdatedAt = new Date();
await this.employeePosMasterRepository.save(employeePosMaster);
//create employeePosition
item.positions.map(async (pos: any) => {
delete pos.id;
const employeePosition: EmployeePosition = Object.assign(
new EmployeePosition(),
pos,
);
employeePosition.posMasterId = employeePosMaster.id;
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
) {
employeePosition.positionIsSelected = false;
}
employeePosition.createdUserId = request.user.sub;
employeePosition.createdFullName = request.user.name;
employeePosition.createdAt = new Date();
employeePosition.lastUpdateUserId = request.user.sub;
employeePosition.lastUpdateFullName = request.user.name;
employeePosition.lastUpdatedAt = new Date();
await this.employeePositionRepository.save(employeePosition);
});
}),
);
//create employeeTempPosmaster
await Promise.all(
_orgemployeeTempPosMaster
.filter((x: EmployeeTempPosMaster) => x.orgChild4Id == data4Id)
.map(async (item: any) => {
delete item.id;
const employeeTempPosMaster = Object.assign(
new EmployeeTempPosMaster(),
item,
);
employeeTempPosMaster.positions = [];
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
// employeeTempPosMaster.next_holderId = item.current_holderId;
} else {
// employeeTempPosMaster.next_holderId = null;
employeeTempPosMaster.isSit = false;
}
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
employeeTempPosMaster.authRoleId = item.authRoleId;
} else {
employeeTempPosMaster.authRoleId = null;
}
// employeeTempPosMaster.current_holderId = null;
employeeTempPosMaster.orgRevisionId = revision.id;
employeeTempPosMaster.orgRootId = data.id;
employeeTempPosMaster.createdUserId = request.user.sub;
employeeTempPosMaster.createdFullName = request.user.name;
employeeTempPosMaster.createdAt = new Date();
employeeTempPosMaster.lastUpdateUserId = request.user.sub;
employeeTempPosMaster.lastUpdateFullName = request.user.name;
employeeTempPosMaster.lastUpdatedAt = new Date();
await this.employeeTempPosMasterRepository.save(
employeeTempPosMaster,
);
//create employeePosition
item.positions.map(async (pos: any) => {
delete pos.id;
const employeePosition: EmployeePosition = Object.assign(
new EmployeePosition(),
pos,
);
employeePosition.posMasterTempId = employeeTempPosMaster.id;
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
) {
employeePosition.positionIsSelected = false;
}
employeePosition.createdUserId = request.user.sub;
employeePosition.createdFullName = request.user.name;
employeePosition.createdAt = new Date();
employeePosition.lastUpdateUserId = request.user.sub;
employeePosition.lastUpdateFullName = request.user.name;
employeePosition.lastUpdatedAt = new Date();
await this.employeePositionRepository.save(employeePosition);
});
}),
);
}
});
});