no message
This commit is contained in:
parent
507b527c5e
commit
951b5a936e
2 changed files with 91 additions and 73 deletions
|
|
@ -24,7 +24,7 @@ import { PosType } from "../entities/PosType";
|
|||
import { PosLevel } from "../entities/PosLevel";
|
||||
import { CreatePosDict, PosDict } from "../entities/PosDict";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { Equal, ILike, In, IsNull, Like, Not ,Brackets } from "typeorm";
|
||||
import { Equal, ILike, In, IsNull, Like, Not, Brackets } from "typeorm";
|
||||
import { CreatePosMaster, PosMaster } from "../entities/PosMaster";
|
||||
import { OrgRevision } from "../entities/OrgRevision";
|
||||
import { OrgRoot } from "../entities/OrgRoot";
|
||||
|
|
@ -35,7 +35,7 @@ import { OrgChild4 } from "../entities/OrgChild4";
|
|||
import { Position } from "../entities/Position";
|
||||
@Route("api/v1/org/pos")
|
||||
@Tags("Position")
|
||||
// @Security("bearerAuth")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||
|
|
@ -112,52 +112,75 @@ export class PositionController extends Controller {
|
|||
}
|
||||
|
||||
const chk_posDictName = await this.posDictRepository.findOne({
|
||||
where: { posDictName: posDict.posDictName }
|
||||
})
|
||||
if(chk_posDictName){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ตำแหน่งในสายงาน: " + chk_posDictName.posDictName + " มีอยู่ในระบบแล้ว");
|
||||
where: { posDictName: posDict.posDictName },
|
||||
});
|
||||
if (chk_posDictName) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ตำแหน่งในสายงาน: " + chk_posDictName.posDictName + " มีอยู่ในระบบแล้ว",
|
||||
);
|
||||
}
|
||||
|
||||
const chk_posDictField = await this.posDictRepository.findOne({
|
||||
where: { posDictField: posDict.posDictField }
|
||||
})
|
||||
if(chk_posDictField){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "สายงาน: " + chk_posDictField.posDictField + " มีอยู่ในระบบแล้ว");
|
||||
where: { posDictField: posDict.posDictField },
|
||||
});
|
||||
if (chk_posDictField) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"สายงาน: " + chk_posDictField.posDictField + " มีอยู่ในระบบแล้ว",
|
||||
);
|
||||
}
|
||||
|
||||
const chk_posTypeId = await this.posDictRepository.findOne({
|
||||
where: { posTypeId: posDict.posTypeId }
|
||||
})
|
||||
if(chk_posTypeId){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ตำแหน่งประเภท: " + chk_posTypeId.posTypeId + " มีอยู่ในระบบแล้ว");
|
||||
where: { posTypeId: posDict.posTypeId },
|
||||
});
|
||||
if (chk_posTypeId) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ตำแหน่งประเภท: " + chk_posTypeId.posTypeId + " มีอยู่ในระบบแล้ว",
|
||||
);
|
||||
}
|
||||
|
||||
const chk_posLevelId = await this.posDictRepository.findOne({
|
||||
where: { posLevelId: posDict.posLevelId }
|
||||
})
|
||||
if(chk_posLevelId){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ระดับตำแหน่ง: " + chk_posLevelId.posLevelId + " มีอยู่ในระบบแล้ว");
|
||||
where: { posLevelId: posDict.posLevelId },
|
||||
});
|
||||
if (chk_posLevelId) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ระดับตำแหน่ง: " + chk_posLevelId.posLevelId + " มีอยู่ในระบบแล้ว",
|
||||
);
|
||||
}
|
||||
|
||||
const chk_posExecutiveId = await this.posDictRepository.findOne({
|
||||
where: { posExecutiveId: String(posDict.posExecutiveId) }
|
||||
})
|
||||
if(chk_posExecutiveId){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ตำแหน่งทางการบริหาร: " + chk_posExecutiveId.posExecutiveId + " มีอยู่ในระบบแล้ว");
|
||||
where: { posExecutiveId: String(posDict.posExecutiveId) },
|
||||
});
|
||||
if (chk_posExecutiveId) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ตำแหน่งทางการบริหาร: " + chk_posExecutiveId.posExecutiveId + " มีอยู่ในระบบแล้ว",
|
||||
);
|
||||
}
|
||||
|
||||
const chk_posDictExecutiveField = await this.posDictRepository.findOne({
|
||||
where: { posDictExecutiveField: posDict.posDictExecutiveField }
|
||||
})
|
||||
if(chk_posDictExecutiveField){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ด้านทางการบริหาร: " + chk_posDictExecutiveField.posDictExecutiveField + " มีอยู่ในระบบแล้ว");
|
||||
where: { posDictExecutiveField: posDict.posDictExecutiveField },
|
||||
});
|
||||
if (chk_posDictExecutiveField) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ด้านทางการบริหาร: " +
|
||||
chk_posDictExecutiveField.posDictExecutiveField +
|
||||
" มีอยู่ในระบบแล้ว",
|
||||
);
|
||||
}
|
||||
|
||||
const chk_posDictArea= await this.posDictRepository.findOne({
|
||||
where: { posDictArea: posDict.posDictArea }
|
||||
})
|
||||
if(chk_posDictArea){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ด้าน/สาขา: " + chk_posDictArea.posDictArea + " มีอยู่ในระบบแล้ว");
|
||||
const chk_posDictArea = await this.posDictRepository.findOne({
|
||||
where: { posDictArea: posDict.posDictArea },
|
||||
});
|
||||
if (chk_posDictArea) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ด้าน/สาขา: " + chk_posDictArea.posDictArea + " มีอยู่ในระบบแล้ว",
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
@ -650,6 +673,7 @@ export class PositionController extends Controller {
|
|||
const positions = await this.positionRepository.find({
|
||||
where: { posMasterId: posMaster.id },
|
||||
relations: ["posType", "posLevel", "posExecutive"],
|
||||
order: { lastUpdatedAt: "ASC" },
|
||||
});
|
||||
const formattedData = {
|
||||
id: posMaster.id,
|
||||
|
|
@ -808,19 +832,17 @@ export class PositionController extends Controller {
|
|||
}
|
||||
masterId = [...new Set(masterId)];
|
||||
}
|
||||
|
||||
|
||||
const conditions = [
|
||||
{
|
||||
...checkChildConditions,
|
||||
...typeCondition,
|
||||
...(body.keyword && (
|
||||
masterId.length > 0
|
||||
? { id: In(masterId)}
|
||||
: { posMasterNo: Like(`%${body.keyword}%`) }
|
||||
|
||||
)),
|
||||
...(body.keyword &&
|
||||
(masterId.length > 0
|
||||
? { id: In(masterId) }
|
||||
: { posMasterNo: Like(`%${body.keyword}%`) })),
|
||||
},
|
||||
]
|
||||
];
|
||||
|
||||
// if (body.keyword) {
|
||||
// conditions.push({
|
||||
|
|
@ -831,7 +853,7 @@ export class PositionController extends Controller {
|
|||
|
||||
// const [posMaster, total] = await this.posMasterRepository.findAndCount({
|
||||
// where: conditions,
|
||||
// order: { posMasterOrder: "ASC" },
|
||||
// order: { posMasterOrder: "ASC" },
|
||||
// relations: [
|
||||
// "orgRoot",
|
||||
// "orgChild1",
|
||||
|
|
@ -846,38 +868,34 @@ export class PositionController extends Controller {
|
|||
// });
|
||||
|
||||
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(conditions)
|
||||
// .orWhere('(current_holder.prefix LIKE :keyword OR current_holder.firstName LIKE :keyword OR current_holder.lastName LIKE :keyword)', { keyword: `%${body.keyword}%` })
|
||||
.orWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "current_holder.prefix LIKE :keyword OR current_holder.firstName LIKE :keyword OR current_holder.lastName LIKE :keyword OR :keyword LIKE current_holder.prefix OR :keyword LIKE current_holder.firstName OR :keyword LIKE current_holder.lastName"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
checkChildConditions
|
||||
)
|
||||
.andWhere(
|
||||
typeCondition
|
||||
);
|
||||
})
|
||||
)
|
||||
.orderBy('posMaster.posMasterOrder', 'ASC')
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize)
|
||||
.getManyAndCount();
|
||||
.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(conditions)
|
||||
// .orWhere('(current_holder.prefix LIKE :keyword OR current_holder.firstName LIKE :keyword OR current_holder.lastName LIKE :keyword)', { keyword: `%${body.keyword}%` })
|
||||
.orWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "current_holder.prefix LIKE :keyword OR current_holder.firstName LIKE :keyword OR current_holder.lastName LIKE :keyword OR :keyword LIKE current_holder.prefix OR :keyword LIKE current_holder.firstName OR :keyword LIKE current_holder.lastName"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.andWhere(checkChildConditions)
|
||||
.andWhere(typeCondition);
|
||||
}),
|
||||
)
|
||||
.orderBy("posMaster.posMasterOrder", "ASC")
|
||||
.skip((body.page - 1) * body.pageSize)
|
||||
.take(body.pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
const formattedData = await Promise.all(
|
||||
posMaster.map(async (posMaster) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue