เลือกคนลงตำแหน่ง
This commit is contained in:
parent
d9a730e6c6
commit
513fb2838b
1 changed files with 70 additions and 53 deletions
|
|
@ -1237,10 +1237,9 @@ export class PositionController extends Controller {
|
|||
) {
|
||||
await new permission().PermissionUpdate(request, "SYS_ORG");
|
||||
const posMaster = await this.posMasterRepository.findOne({
|
||||
relations: ["positions"],
|
||||
where: { id: id }
|
||||
}
|
||||
);
|
||||
relations: ["positions", "orgRevision"],
|
||||
where: { id: id },
|
||||
});
|
||||
if (!posMaster) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลอัตรากำลัง");
|
||||
}
|
||||
|
|
@ -1402,21 +1401,21 @@ export class PositionController extends Controller {
|
|||
if (match) {
|
||||
match.positionIsSelected = x.positionIsSelected ?? false;
|
||||
match.orderNo = x.orderNo ?? null;
|
||||
return match
|
||||
return match;
|
||||
} else {
|
||||
x.id = x.id ?? undefined;
|
||||
x.posMasterId = posMaster.id;
|
||||
x.orderNo = x.orderNo ?? null;
|
||||
x.positionName = x.posDictName;
|
||||
x.positionField = x.posDictField;
|
||||
x.posExecutiveId = x.posExecutiveId || null
|
||||
x.posExecutiveId = x.posExecutiveId || null;
|
||||
x.createdUserId = request.user.sub;
|
||||
x.createdFullName = request.user.name;
|
||||
x.lastUpdateUserId = request.user.sub;
|
||||
x.lastUpdateFullName = request.user.name;
|
||||
x.createdAt = new Date();
|
||||
x.lastUpdatedAt = new Date();
|
||||
return x
|
||||
return x;
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
@ -1430,6 +1429,22 @@ export class PositionController extends Controller {
|
|||
}
|
||||
}),
|
||||
);
|
||||
|
||||
if (posMaster.orgRevision?.orgRevisionIsDraft != false) {
|
||||
const _position = posMaster.positions.find((p) => p.positionIsSelected == true);
|
||||
if (_position) {
|
||||
const current_holderId: any = posMaster.current_holderId;
|
||||
const _profile = await this.profileRepository.findOne({
|
||||
where: { id: current_holderId },
|
||||
});
|
||||
if (_profile) {
|
||||
_profile.position = _position.positionName;
|
||||
_profile.posTypeId = _position.posTypeId;
|
||||
_profile.posLevelId = _position.posLevelId;
|
||||
await this.profileRepository.save(_profile);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new HttpSuccess(posMaster.id);
|
||||
}
|
||||
|
||||
|
|
@ -1524,7 +1539,7 @@ export class PositionController extends Controller {
|
|||
// posLevel: {
|
||||
// posLevelRank: "ASC",
|
||||
// },
|
||||
orderNo: "ASC"
|
||||
orderNo: "ASC",
|
||||
},
|
||||
});
|
||||
const formattedData = {
|
||||
|
|
@ -2974,7 +2989,7 @@ export class PositionController extends Controller {
|
|||
where: {
|
||||
// orgRevisionIsDraft: true,
|
||||
// orgRevisionIsCurrent: false,
|
||||
id: posMaster.orgRevisionId
|
||||
id: posMaster.orgRevisionId,
|
||||
},
|
||||
});
|
||||
const _orgRoot = await this.orgRootRepository.find({
|
||||
|
|
@ -3614,24 +3629,23 @@ export class PositionController extends Controller {
|
|||
});
|
||||
if (chkRevision?.orgRevisionIsCurrent) {
|
||||
const _profile = await this.profileRepository.findOne({
|
||||
where: { id: requestBody.profileId }
|
||||
where: { id: requestBody.profileId },
|
||||
});
|
||||
if (_profile) {
|
||||
let _position = await this.positionRepository.findOne({
|
||||
where: { id: requestBody.position, posMasterId: requestBody.posMaster }
|
||||
where: { id: requestBody.position, posMasterId: requestBody.posMaster },
|
||||
});
|
||||
if (_position) {
|
||||
_profile.position = _position.positionName
|
||||
_profile.posTypeId = _position.posTypeId
|
||||
_profile.posLevelId = _position.posLevelId
|
||||
_profile.position = _position.positionName;
|
||||
_profile.posTypeId = _position.posTypeId;
|
||||
_profile.posLevelId = _position.posLevelId;
|
||||
await this.profileRepository.save(_profile);
|
||||
setLogDataDiff(request, { before, after: _profile });
|
||||
}
|
||||
}
|
||||
dataMaster.current_holderId = requestBody.profileId;
|
||||
dataMaster.next_holderId = _null;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
dataMaster.next_holderId = requestBody.profileId;
|
||||
dataMaster.current_holderId = _null;
|
||||
}
|
||||
|
|
@ -3658,7 +3672,7 @@ export class PositionController extends Controller {
|
|||
if (!dataMaster) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
|
||||
}
|
||||
let _profileId: string = ""
|
||||
let _profileId: string = "";
|
||||
if (dataMaster?.current_holderId) {
|
||||
_profileId = dataMaster?.current_holderId;
|
||||
}
|
||||
|
|
@ -3674,24 +3688,24 @@ export class PositionController extends Controller {
|
|||
positionIsSelected: false,
|
||||
});
|
||||
});
|
||||
//เช็คถ้า revision ปัจจุบันให้ปั๊มที่ profile
|
||||
const chkRevision = await this.orgRevisionRepository.findOne({
|
||||
where: { id: dataMaster.orgRevisionId },
|
||||
});
|
||||
if (chkRevision?.orgRevisionIsCurrent) {
|
||||
const _profile = await this.profileRepository.findOne({
|
||||
where: { id: _profileId }
|
||||
});
|
||||
if (_profile) {
|
||||
const _null: any = null;
|
||||
const before = null;
|
||||
_profile.position = _null
|
||||
_profile.posTypeId = _null
|
||||
_profile.posLevelId = _null
|
||||
await this.profileRepository.save(_profile);
|
||||
setLogDataDiff(request, { before, after: _profile });
|
||||
}
|
||||
}
|
||||
// //เช็คถ้า revision ปัจจุบันให้ปั๊มที่ profile
|
||||
// const chkRevision = await this.orgRevisionRepository.findOne({
|
||||
// where: { id: dataMaster.orgRevisionId },
|
||||
// });
|
||||
// if (chkRevision?.orgRevisionIsCurrent) {
|
||||
// const _profile = await this.profileRepository.findOne({
|
||||
// where: { id: _profileId }
|
||||
// });
|
||||
// if (_profile) {
|
||||
// const _null: any = null;
|
||||
// const before = null;
|
||||
// _profile.position = _null
|
||||
// _profile.posTypeId = _null
|
||||
// _profile.posLevelId = _null
|
||||
// await this.profileRepository.save(_profile);
|
||||
// setLogDataDiff(request, { before, after: _profile });
|
||||
// }
|
||||
// }
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -3703,11 +3717,12 @@ export class PositionController extends Controller {
|
|||
*/
|
||||
@Post("dna")
|
||||
async dna(
|
||||
@Body() requestBody: {
|
||||
@Body()
|
||||
requestBody: {
|
||||
draftRevisionId?: string | null; //ใช้เฉพาะเคสสืบทอดจากโครงสร้างปัจจุบัน
|
||||
draftPositionId: string; //ในเคสสืบทอดจากโครงสร้างปัจจุบันจะ "ตำแหน่งที่แบบร่าง" จะเป็น "ตำแหน่งปัจจุบัน" ใช้ draftRevisionId เพื่อเช็คว่าเป็นโครงสร้างปัจจุบันไหม
|
||||
publishRevisionId?: string | null; //ใช้เฉพาะเคสสืบทอดจากโครงสร้างปัจจุบัน
|
||||
publishPositionId: string //ในเคสสืบทอดจากโครงสร้างปัจจุบันจะ "ตำแหน่งปัจจุบัน" จะเป็น "ตำแหน่งที่ต้องการจะสืบทอด" ตาม publishRevisionId ที่ส่งมา
|
||||
publishPositionId: string; //ในเคสสืบทอดจากโครงสร้างปัจจุบันจะ "ตำแหน่งปัจจุบัน" จะเป็น "ตำแหน่งที่ต้องการจะสืบทอด" ตาม publishRevisionId ที่ส่งมา
|
||||
},
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
|
|
@ -3732,11 +3747,12 @@ export class PositionController extends Controller {
|
|||
// ถ้ามี publishPositionId ค่อยเพิ่มเข้าไป ***อันนี้อาจไม่ต้องทำเพราะใช้ publishPositionId where ได้โดยตรง (!!รอดูหน้าบ้าน!!)***
|
||||
if (requestBody.publishRevisionId) {
|
||||
whereConditionPub.id = requestBody.publishPositionId;
|
||||
whereConditionPub.orgRevisionId = requestBody.publishRevisionId
|
||||
whereConditionPub.orgRevisionId = requestBody.publishRevisionId;
|
||||
} else {
|
||||
whereConditionPub.id = requestBody.publishPositionId;
|
||||
}
|
||||
const dataPublish = await this.posMasterRepository.findOne({ //เคสโครงสร้างปัจจุบัน: ตัวที่ต้องการจะสืบทอด
|
||||
const dataPublish = await this.posMasterRepository.findOne({
|
||||
//เคสโครงสร้างปัจจุบัน: ตัวที่ต้องการจะสืบทอด
|
||||
where: whereConditionPub,
|
||||
});
|
||||
if (!dataPublish) {
|
||||
|
|
@ -3747,11 +3763,12 @@ export class PositionController extends Controller {
|
|||
// ถ้ามี publishPositionId ค่อยเพิ่มเข้าไป ***อันนี้อาจไม่ต้องทำเพราะใช้ draftPositionId where ได้โดยตรง (!!รอดูหน้าบ้าน!!)***
|
||||
if (requestBody.draftRevisionId) {
|
||||
whereConditionDraft.id = requestBody.draftPositionId;
|
||||
whereConditionDraft.orgRevisionId = requestBody.draftRevisionId
|
||||
whereConditionDraft.orgRevisionId = requestBody.draftRevisionId;
|
||||
} else {
|
||||
whereConditionDraft.id = requestBody.draftPositionId;
|
||||
}
|
||||
const dataDraft = await this.posMasterRepository.findOne({ //เคสโครงสร้างปัจจุบัน: ตัวปัจจุบัน
|
||||
const dataDraft = await this.posMasterRepository.findOne({
|
||||
//เคสโครงสร้างปัจจุบัน: ตัวปัจจุบัน
|
||||
where: whereConditionDraft,
|
||||
});
|
||||
if (!dataDraft) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue