เช็คตำแหน่งซ้ำ
This commit is contained in:
parent
885e1e725c
commit
5df57fc4d6
3 changed files with 408 additions and 9 deletions
|
|
@ -356,6 +356,19 @@ export class PositionController extends Controller {
|
|||
},
|
||||
order: { posMasterOrder: "DESC" },
|
||||
});
|
||||
const dataDup: any = await this.posMasterRepository.findOne({
|
||||
where: {
|
||||
orgChild4Id: orgChild4.id,
|
||||
posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
||||
posMasterNo: requestBody.posMasterNo,
|
||||
posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
||||
},
|
||||
});
|
||||
if (dataDup != null)
|
||||
throw new HttpError(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||
);
|
||||
posMaster.posMasterOrder =
|
||||
order !== null && order !== undefined && order.posMasterOrder
|
||||
? order.posMasterOrder + 1
|
||||
|
|
@ -375,6 +388,20 @@ export class PositionController extends Controller {
|
|||
},
|
||||
order: { posMasterOrder: "DESC" },
|
||||
});
|
||||
const dataDup: any = await this.posMasterRepository.findOne({
|
||||
where: {
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: IsNull() || "",
|
||||
posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
||||
posMasterNo: requestBody.posMasterNo,
|
||||
posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
||||
},
|
||||
});
|
||||
if (dataDup != null)
|
||||
throw new HttpError(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||
);
|
||||
posMaster.posMasterOrder =
|
||||
order !== null && order !== undefined && order.posMasterOrder
|
||||
? order.posMasterOrder + 1
|
||||
|
|
@ -394,6 +421,21 @@ export class PositionController extends Controller {
|
|||
},
|
||||
order: { posMasterOrder: "DESC" },
|
||||
});
|
||||
const dataDup: any = await this.posMasterRepository.findOne({
|
||||
where: {
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
||||
posMasterNo: requestBody.posMasterNo,
|
||||
posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
||||
},
|
||||
});
|
||||
if (dataDup != null)
|
||||
throw new HttpError(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||
);
|
||||
posMaster.posMasterOrder =
|
||||
order !== null && order !== undefined && order.posMasterOrder
|
||||
? order.posMasterOrder + 1
|
||||
|
|
@ -413,6 +455,22 @@ export class PositionController extends Controller {
|
|||
},
|
||||
order: { posMasterOrder: "DESC" },
|
||||
});
|
||||
const dataDup: any = await this.posMasterRepository.findOne({
|
||||
where: {
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
||||
posMasterNo: requestBody.posMasterNo,
|
||||
posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
||||
},
|
||||
});
|
||||
if (dataDup != null)
|
||||
throw new HttpError(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||
);
|
||||
posMaster.posMasterOrder =
|
||||
order !== null && order !== undefined && order.posMasterOrder
|
||||
? order.posMasterOrder + 1
|
||||
|
|
@ -432,6 +490,23 @@ export class PositionController extends Controller {
|
|||
},
|
||||
order: { posMasterOrder: "DESC" },
|
||||
});
|
||||
const dataDup: any = await this.posMasterRepository.findOne({
|
||||
where: {
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: IsNull() || "",
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
||||
posMasterNo: requestBody.posMasterNo,
|
||||
posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
||||
},
|
||||
});
|
||||
if (dataDup != null)
|
||||
throw new HttpError(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||
);
|
||||
posMaster.posMasterOrder =
|
||||
order !== null && order !== undefined && order.posMasterOrder
|
||||
? order.posMasterOrder + 1
|
||||
|
|
@ -546,6 +621,20 @@ export class PositionController extends Controller {
|
|||
if (!orgChild4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
|
||||
} else {
|
||||
const dataDup: any = await this.posMasterRepository.findOne({
|
||||
where: {
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: IsNull() || "",
|
||||
posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
||||
posMasterNo: requestBody.posMasterNo,
|
||||
posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
||||
},
|
||||
});
|
||||
if (dataDup != null)
|
||||
throw new HttpError(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||
);
|
||||
posMaster.orgRootId = orgChild4.orgRootId;
|
||||
posMaster.orgChild1Id = orgChild4.orgChild1Id;
|
||||
posMaster.orgChild2Id = orgChild4.orgChild2Id;
|
||||
|
|
@ -554,6 +643,21 @@ export class PositionController extends Controller {
|
|||
posMaster.orgRevisionId = orgChild4.orgRevisionId;
|
||||
}
|
||||
} else {
|
||||
const dataDup: any = await this.posMasterRepository.findOne({
|
||||
where: {
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
||||
posMasterNo: requestBody.posMasterNo,
|
||||
posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
||||
},
|
||||
});
|
||||
if (dataDup != null)
|
||||
throw new HttpError(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||
);
|
||||
posMaster.orgRootId = orgChild3.orgRootId;
|
||||
posMaster.orgChild1Id = orgChild3.orgChild1Id;
|
||||
posMaster.orgChild2Id = orgChild3.orgChild2Id;
|
||||
|
|
@ -561,17 +665,67 @@ export class PositionController extends Controller {
|
|||
posMaster.orgRevisionId = orgChild3.orgRevisionId;
|
||||
}
|
||||
} else {
|
||||
const dataDup: any = await this.posMasterRepository.findOne({
|
||||
where: {
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
||||
posMasterNo: requestBody.posMasterNo,
|
||||
posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
||||
},
|
||||
});
|
||||
if (dataDup != null)
|
||||
throw new HttpError(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||
);
|
||||
posMaster.orgRootId = orgChild2.orgRootId;
|
||||
posMaster.orgChild1Id = orgChild2.orgChild1Id;
|
||||
posMaster.orgChild2Id = orgChild2.id;
|
||||
posMaster.orgRevisionId = orgChild2.orgRevisionId;
|
||||
}
|
||||
} else {
|
||||
const dataDup: any = await this.posMasterRepository.findOne({
|
||||
where: {
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: IsNull() || "",
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
||||
posMasterNo: requestBody.posMasterNo,
|
||||
posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
||||
},
|
||||
});
|
||||
if (dataDup != null)
|
||||
throw new HttpError(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||
);
|
||||
posMaster.orgRootId = orgChild1.orgRootId;
|
||||
posMaster.orgChild1Id = orgChild1.id;
|
||||
posMaster.orgRevisionId = orgChild1.orgRevisionId;
|
||||
}
|
||||
} else {
|
||||
const dataDup: any = await this.posMasterRepository.findOne({
|
||||
where: {
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: IsNull() || "",
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
posMasterNoPrefix: requestBody.posMasterNoPrefix,
|
||||
posMasterNo: requestBody.posMasterNo,
|
||||
posMasterNoSuffix: requestBody.posMasterNoSuffix,
|
||||
},
|
||||
});
|
||||
if (dataDup != null)
|
||||
throw new HttpError(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||
);
|
||||
posMaster.orgRootId = orgRoot.id;
|
||||
posMaster.orgRevisionId = orgRoot.orgRevisionId;
|
||||
}
|
||||
|
|
@ -1933,4 +2087,176 @@ export class PositionController extends Controller {
|
|||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API ค้นหาตำแหน่งในระบบสมัครสอบ
|
||||
*
|
||||
* @summary ค้นหาตำแหน่งในระบบสมัครสอบ
|
||||
*
|
||||
*/
|
||||
@Post("placement/search")
|
||||
async searchPlacement(@Body() body: { node: number; nodeId: string; position: string }) {
|
||||
let typeCondition: any = {};
|
||||
|
||||
if (body.node === 0) {
|
||||
typeCondition = {
|
||||
orgRootId: body.nodeId,
|
||||
orgChild1Id: IsNull(),
|
||||
next_holderId: IsNull(),
|
||||
};
|
||||
} else if (body.node === 1) {
|
||||
typeCondition = {
|
||||
orgChild1Id: body.nodeId,
|
||||
orgChild2Id: IsNull(),
|
||||
next_holderId: IsNull(),
|
||||
};
|
||||
} else if (body.node === 2) {
|
||||
typeCondition = {
|
||||
orgChild2Id: body.nodeId,
|
||||
orgChild3Id: IsNull(),
|
||||
next_holderId: IsNull(),
|
||||
};
|
||||
} else if (body.node === 3) {
|
||||
typeCondition = {
|
||||
orgChild3Id: body.nodeId,
|
||||
orgChild4Id: IsNull(),
|
||||
next_holderId: IsNull(),
|
||||
};
|
||||
} else if (body.node === 4) {
|
||||
typeCondition = {
|
||||
orgChild4Id: body.nodeId,
|
||||
next_holderId: IsNull(),
|
||||
};
|
||||
}
|
||||
|
||||
const [posMaster, total] = await AppDataSource.getRepository(PosMaster)
|
||||
.createQueryBuilder("posMaster")
|
||||
.leftJoinAndSelect("posMaster.orgRoot", "orgRoot")
|
||||
.leftJoinAndSelect("posMaster.orgChild1", "orgChild1")
|
||||
.leftJoinAndSelect("posMaster.orgChild2", "orgChild2")
|
||||
.leftJoinAndSelect("posMaster.orgChild3", "orgChild3")
|
||||
.leftJoinAndSelect("posMaster.orgChild4", "orgChild4")
|
||||
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
|
||||
.leftJoinAndSelect("posMaster.next_holder", "next_holder")
|
||||
.where(typeCondition)
|
||||
.orderBy("posMaster.posMasterOrder", "ASC")
|
||||
.getManyAndCount();
|
||||
|
||||
const formattedData = await Promise.all(
|
||||
posMaster.map(async (posMaster) => {
|
||||
const positions = await this.positionRepository.find({
|
||||
where: {
|
||||
posMasterId: posMaster.id,
|
||||
},
|
||||
relations: ["posLevel", "posType", "posExecutive"],
|
||||
});
|
||||
|
||||
let profile: any;
|
||||
const chkRevision = await this.orgRevisionRepository.findOne({
|
||||
where: { id: posMaster.orgRevisionId },
|
||||
});
|
||||
if (chkRevision?.orgRevisionIsCurrent && !chkRevision?.orgRevisionIsDraft) {
|
||||
profile = await this.profileRepository.findOne({
|
||||
where: { id: String(posMaster.current_holderId) },
|
||||
});
|
||||
} else if (!chkRevision?.orgRevisionIsCurrent && chkRevision?.orgRevisionIsDraft) {
|
||||
profile = await this.profileRepository.findOne({
|
||||
where: { id: String(posMaster.next_holderId) },
|
||||
});
|
||||
}
|
||||
const type = await this.posTypeRepository.findOne({
|
||||
where: { id: String(profile?.posTypeId) },
|
||||
});
|
||||
const level = await this.posLevelRepository.findOne({
|
||||
where: { id: String(profile?.posLevelId) },
|
||||
});
|
||||
|
||||
let shortName = "";
|
||||
|
||||
if (
|
||||
posMaster.orgRootId !== null &&
|
||||
posMaster.orgChild1Id == null &&
|
||||
posMaster.orgChild2Id == null &&
|
||||
posMaster.orgChild3Id == null
|
||||
) {
|
||||
body.node = 0;
|
||||
shortName = posMaster.orgRoot.orgRootShortName;
|
||||
} else if (
|
||||
posMaster.orgRootId !== null &&
|
||||
posMaster.orgChild1Id !== null &&
|
||||
posMaster.orgChild2Id == null &&
|
||||
posMaster.orgChild3Id == null
|
||||
) {
|
||||
body.node = 1;
|
||||
shortName = posMaster.orgChild1.orgChild1ShortName;
|
||||
} else if (
|
||||
posMaster.orgRootId !== null &&
|
||||
posMaster.orgChild1Id !== null &&
|
||||
posMaster.orgChild2Id !== null &&
|
||||
posMaster.orgChild3Id == null
|
||||
) {
|
||||
body.node = 2;
|
||||
shortName = posMaster.orgChild2.orgChild2ShortName;
|
||||
} else if (
|
||||
posMaster.orgRootId !== null &&
|
||||
posMaster.orgChild1Id !== null &&
|
||||
posMaster.orgChild2Id !== null &&
|
||||
posMaster.orgChild3Id !== null
|
||||
) {
|
||||
body.node = 3;
|
||||
shortName = posMaster.orgChild3.orgChild3ShortName;
|
||||
} else if (
|
||||
posMaster.orgRootId !== null &&
|
||||
posMaster.orgChild1Id !== null &&
|
||||
posMaster.orgChild2Id !== null &&
|
||||
posMaster.orgChild3Id !== null
|
||||
) {
|
||||
body.node = 4;
|
||||
shortName = posMaster.orgChild4.orgChild4ShortName;
|
||||
}
|
||||
|
||||
return {
|
||||
id: posMaster.id,
|
||||
orgRootId: posMaster.orgRootId,
|
||||
orgChild1Id: posMaster.orgChild1Id,
|
||||
orgChild2Id: posMaster.orgChild2Id,
|
||||
orgChild3Id: posMaster.orgChild3Id,
|
||||
orgChild4Id: posMaster.orgChild4Id,
|
||||
posMasterNoPrefix: posMaster.posMasterNoPrefix,
|
||||
posMasterNo: posMaster.posMasterNo,
|
||||
posMasterNoSuffix: posMaster.posMasterNoSuffix,
|
||||
fullNameCurrentHolder:
|
||||
posMaster.current_holder == null
|
||||
? null
|
||||
: `${posMaster.current_holder.prefix}${posMaster.current_holder.firstName} ${posMaster.current_holder.lastName}`,
|
||||
fullNameNextHolder:
|
||||
posMaster.next_holder == null
|
||||
? null
|
||||
: `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`,
|
||||
orgShortname: shortName,
|
||||
isSit: posMaster.isSit,
|
||||
profilePosition: profile == null || profile.position == null ? null : profile.position,
|
||||
profilePostype: type == null || type.posTypeName == null ? null : type.posTypeName,
|
||||
profilePoslevel: level == null || level.posLevelName == null ? null : level.posLevelName,
|
||||
isPosition: positions.filter((x) => x.positionName == body.position).length > 0,
|
||||
positions: positions.map((position) => ({
|
||||
id: position.id,
|
||||
positionName: position.positionName,
|
||||
positionField: position.positionField,
|
||||
posTypeId: position.posTypeId,
|
||||
posTypeName: position.posType == null ? null : position.posType.posTypeName,
|
||||
posLevelId: position.posLevelId,
|
||||
posLevelName: position.posLevel == null ? null : position.posLevel.posLevelName,
|
||||
posExecutiveId: position.posExecutiveId,
|
||||
posExecutiveName:
|
||||
position.posExecutive == null ? null : position.posExecutive.posExecutiveName,
|
||||
positionExecutiveField: position.positionExecutiveField,
|
||||
positionArea: position.positionArea,
|
||||
positionIsSelected: position.positionIsSelected,
|
||||
})),
|
||||
};
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess({ data: formattedData, total });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue