ปรับโครงสร้าง root

This commit is contained in:
Kittapath 2024-06-20 11:58:51 +07:00
parent 9de005c7ae
commit 7f21756928
5 changed files with 143 additions and 60 deletions

View file

@ -122,28 +122,30 @@ export class OrgChild1Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild1Rank");
}
const chkCode = await this.child1Repository.findOne({
where: {
orgRevisionId: rootIdExits.orgRevisionId,
orgRootId: requestBody.orgRootId,
orgChild1Code: requestBody.orgChild1Code,
},
});
if (chkCode != null) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"รหัสส่วนราชการนี้มีอยู่ในระบบแล้ว",
);
}
const chkShort = await this.child1Repository.findOne({
where: {
orgRevisionId: rootIdExits.orgRevisionId,
orgRootId: requestBody.orgRootId,
orgChild1ShortName: requestBody.orgChild1ShortName,
},
});
if (chkShort != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้มีอยู่ในระบบแล้ว");
if (rootIdExits.orgRootRankSub != "DISTRICT") {
const chkCode = await this.child1Repository.findOne({
where: {
orgRevisionId: rootIdExits.orgRevisionId,
orgRootId: requestBody.orgRootId,
orgChild1Code: requestBody.orgChild1Code,
},
});
if (chkCode != null) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"รหัสส่วนราชการนี้มีอยู่ในระบบแล้ว",
);
}
const chkShort = await this.child1Repository.findOne({
where: {
orgRevisionId: rootIdExits.orgRevisionId,
orgRootId: requestBody.orgRootId,
orgChild1ShortName: requestBody.orgChild1ShortName,
},
});
if (chkShort != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้มีอยู่ในระบบแล้ว");
}
}
// if (requestBody.orgChild1Code == rootIdExits.orgRootCode) {
@ -220,27 +222,30 @@ export class OrgChild1Controller {
if (!child1) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
const chkCode = await this.child1Repository.findOne({
where: {
id: Not(id),
orgRevisionId: rootIdExits.orgRevisionId,
orgRootId: requestBody.orgRootId,
orgChild1Code: requestBody.orgChild1Code,
},
});
if (chkCode != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสส่วนราชการนี้มีอยู่ในระบบแล้ว");
}
const chkShort = await this.child1Repository.findOne({
where: {
id: Not(id),
orgRevisionId: rootIdExits.orgRevisionId,
orgRootId: requestBody.orgRootId,
orgChild1ShortName: requestBody.orgChild1ShortName,
},
});
if (chkShort != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้มีอยู่ในระบบแล้ว");
if (rootIdExits.orgRootRankSub != "DISTRICT") {
const chkCode = await this.child1Repository.findOne({
where: {
id: Not(id),
orgRevisionId: rootIdExits.orgRevisionId,
orgRootId: requestBody.orgRootId,
orgChild1Code: requestBody.orgChild1Code,
},
});
if (chkCode != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสส่วนราชการนี้มีอยู่ในระบบแล้ว");
}
const chkShort = await this.child1Repository.findOne({
where: {
id: Not(id),
orgRevisionId: rootIdExits.orgRevisionId,
orgRootId: requestBody.orgRootId,
orgChild1ShortName: requestBody.orgChild1ShortName,
},
});
if (chkShort != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "อักษรย่อนี้มีอยู่ในระบบแล้ว");
}
}
// if(requestBody.orgChild1Code == rootIdExits.orgRootCode){

View file

@ -34,10 +34,10 @@ import { EmployeePosition } from "../entities/EmployeePosition";
@Security("bearerAuth")
export class OrgRootController extends Controller {
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
private orgChild1Repository = AppDataSource.getRepository(OrgChild1);
private orgChild2Repository = AppDataSource.getRepository(OrgChild2);
private orgChild3Repository = AppDataSource.getRepository(OrgChild3);
private orgChild4Repository = AppDataSource.getRepository(OrgChild4);
private child1Repository = AppDataSource.getRepository(OrgChild1);
private child2Repository = AppDataSource.getRepository(OrgChild2);
private child3Repository = AppDataSource.getRepository(OrgChild3);
private child4Repository = AppDataSource.getRepository(OrgChild4);
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
private posMasterRepository = AppDataSource.getRepository(PosMaster);
private positionRepository = AppDataSource.getRepository(Position);
@ -228,7 +228,7 @@ export class OrgRootController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้างระดับ Root นี้");
}
// const chkCodeChild1 = await this.orgChild1Repository.findOne({
// const chkCodeChild1 = await this.child1Repository.findOne({
// where:{
// orgRevisionId : requestBody.orgRevisionId,
// orgRootId: id,
@ -238,7 +238,7 @@ export class OrgRootController extends Controller {
// if(chkCodeChild1 != null){
// throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้ซ้ำกับรหัสส่วนราชการ");
// }
// const chkShortChild1 = await this.orgChild1Repository.findOne({
// const chkShortChild1 = await this.child1Repository.findOne({
// where:{
// orgRevisionId : requestBody.orgRevisionId,
// orgRootId: id,
@ -255,6 +255,62 @@ export class OrgRootController extends Controller {
this.orgRootRepository.merge(orgRoot, requestBody);
await this.orgRootRepository.save(orgRoot);
if (orgRoot.orgRootRankSub == "DISTRICT") {
const up_Child1 = await this.child1Repository.find({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: id,
},
});
if (up_Child1.length > 0) {
for (const _child1 of up_Child1) {
_child1.orgChild1ShortName = String(requestBody.orgRootShortName);
_child1.orgChild1Code = String(requestBody.orgRootCode);
}
await this.child1Repository.save(up_Child1);
}
const up_Child2 = await this.child2Repository.find({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: id,
},
});
if (up_Child2.length > 0) {
for (const _child2 of up_Child2) {
_child2.orgChild2ShortName = String(requestBody.orgRootShortName);
_child2.orgChild2Code = String(requestBody.orgRootCode);
}
await this.child2Repository.save(up_Child2);
}
const up_Child3 = await this.child3Repository.find({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: id,
},
});
if (up_Child3.length > 0) {
for (const _child3 of up_Child3) {
_child3.orgChild3ShortName = String(requestBody.orgRootShortName);
_child3.orgChild3Code = String(requestBody.orgRootCode);
}
await this.child3Repository.save(up_Child3);
}
const up_Child4 = await this.child4Repository.find({
where: {
orgRevisionId: orgRoot.orgRevisionId,
orgRootId: id,
},
});
if (up_Child4.length > 0) {
for (const _child4 of up_Child4) {
_child4.orgChild4ShortName = String(requestBody.orgRootShortName);
_child4.orgChild4Code = String(requestBody.orgRootCode);
}
await this.child4Repository.save(up_Child4);
}
}
return new HttpSuccess();
}
@ -272,7 +328,7 @@ export class OrgRootController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้างระดับ Root นี้");
}
// const orgChild1 = await this.orgChild1Repository.findOne({ where: { orgRootId: id } });
// const orgChild1 = await this.child1Repository.findOne({ where: { orgRootId: id } });
// if (orgChild1 != null) {
// throw new HttpError(
// HttpStatusCode.INTERNAL_SERVER_ERROR,
@ -312,10 +368,10 @@ export class OrgRootController extends Controller {
await this.empPosMasterRepository.remove(empPosMasters);
await this.positionRepository.remove(positions);
await this.posMasterRepository.remove(posMasters);
await this.orgChild4Repository.delete({ orgRootId: id });
await this.orgChild3Repository.delete({ orgRootId: id });
await this.orgChild2Repository.delete({ orgRootId: id });
await this.orgChild1Repository.delete({ orgRootId: id });
await this.child4Repository.delete({ orgRootId: id });
await this.child3Repository.delete({ orgRootId: id });
await this.child2Repository.delete({ orgRootId: id });
await this.child1Repository.delete({ orgRootId: id });
await this.orgRootRepository.delete({ id });
return new HttpSuccess();

View file

@ -3175,9 +3175,10 @@ export class OrganizationController extends Controller {
posMaster: await Promise.all(
orgRoot.posMasters
.filter(
(x) => x.orgChild1Id != null && x.current_holderId != null && x.posMasterOrder <= 3,
(x) => x.orgChild1Id == null && x.current_holderId != null && x.posMasterOrder <= 3,
)
.map(async (x) => ({
posmasterId: x.id,
orgTreeId: orgRoot.id,
orgLevel: 0,
fullNameCurrentHolder:
@ -3210,11 +3211,12 @@ export class OrganizationController extends Controller {
orgChild1.posMasters
.filter(
(x) =>
x.orgChild2Id != null &&
x.orgChild2Id == null &&
x.current_holderId != null &&
x.posMasterOrder <= 3,
)
.map(async (x) => ({
posmasterId: x.id,
orgTreeId: orgChild1.id,
orgLevel: 1,
fullNameCurrentHolder:
@ -3248,11 +3250,12 @@ export class OrganizationController extends Controller {
orgChild2.posMasters
.filter(
(x) =>
x.orgChild3Id != null &&
x.orgChild3Id == null &&
x.current_holderId != null &&
x.posMasterOrder <= 3,
)
.map(async (x) => ({
posmasterId: x.id,
orgTreeId: orgChild2.id,
orgLevel: 2,
fullNameCurrentHolder:
@ -3286,11 +3289,12 @@ export class OrganizationController extends Controller {
orgChild3.posMasters
.filter(
(x) =>
x.orgChild4Id != null &&
x.orgChild4Id == null &&
x.current_holderId != null &&
x.posMasterOrder <= 3,
)
.map(async (x) => ({
posmasterId: x.id,
orgTreeId: orgChild3.id,
orgLevel: 3,
fullNameCurrentHolder:
@ -3326,6 +3330,7 @@ export class OrganizationController extends Controller {
(x) => x.current_holderId != null && x.posMasterOrder <= 3,
)
.map(async (x) => ({
posmasterId: x.id,
orgTreeId: orgChild4.id,
orgLevel: 4,
fullNameCurrentHolder:

View file

@ -4466,4 +4466,21 @@ export class ProfileController extends Controller {
return new HttpSuccess({ data: mapDataProfile, total });
}
/**
*
* @summary (ADMIN)
*
*/
@Get("probation/{id}")
async getProbationProfile(@Path() id: string) {
const profile = await this.profileRepo.findOne({
where: { id },
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
profile.isProbation = true;
await this.profileRepo.save(profile);
return new HttpSuccess(profile);
}
}