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