no message

This commit is contained in:
Bright 2024-06-13 17:37:57 +07:00
parent e6539edaec
commit fdaf457a08

View file

@ -165,8 +165,8 @@ export class ChangePositionController extends Controller {
.createQueryBuilder("changePosition") .createQueryBuilder("changePosition")
.leftJoinAndSelect("changePosition.profileChangePosition", "profileChangePosition") .leftJoinAndSelect("changePosition.profileChangePosition", "profileChangePosition")
.where( .where(
searchKeyword ? searchKeyword
"changePosition.name LIKE :keyword OR changePosition.date LIKE :keyword OR changePosition.status LIKE :keyword" ? "changePosition.name LIKE :keyword OR changePosition.date LIKE :keyword OR changePosition.status LIKE :keyword"
: "1=1", : "1=1",
{ keyword: `%${searchKeyword}%` } { keyword: `%${searchKeyword}%` }
) )
@ -262,33 +262,68 @@ export class ChangePositionController extends Controller {
@Query() searchKeyword: string = "", @Query() searchKeyword: string = "",
) { ) {
const findData = await this.profileChangePositionRepository.find({
where: { changePositionId: changePositionId }
});
if (!findData) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง");
const [profileChangePosition, total] = await AppDataSource.getRepository(ProfileChangePosition) const [profileChangePosition, total] = await AppDataSource.getRepository(ProfileChangePosition)
.createQueryBuilder("profileChangePosition") .createQueryBuilder("profileChangePosition")
.where("profileChangePosition.changePositionId LIKE :id", { id: changePositionId }) .where({ changePositionId: changePositionId })
.andWhere( .andWhere(
searchKeyword ? new Brackets((qb) => {
"CONCAT(profileChangePosition.prefix, profileChangePosition.firstName, ' ', profileChangePosition.lastName) LIKE :keyword" qb.where(
: "1=1", searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
{ ? "profileChangePosition.prefix LIKE :keyword"
keyword: `%${searchKeyword}%`, : "1=1",
}, {
) keyword: `%${searchKeyword}%`,
.andWhere( },
searchKeyword ? )
"profileChangePosition.citizenId LIKE :keyword OR profileChangePosition.status LIKE :keyword" .orWhere(
: "1=1", searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
{ keyword: `%${searchKeyword}%` } ? "profileChangePosition.firstName LIKE :keyword"
) : "1=1",
.andWhere( {
searchKeyword ? keyword: `%${searchKeyword}%`,
"profileChangePosition.birthDate LIKE :keyword OR profileChangePosition.lastUpdatedAt LIKE :keyword" },
: "1=1", )
{ keyword: `%${searchKeyword}%` } .orWhere(
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
? "profileChangePosition.lastName LIKE :keyword"
: "1=1",
{
keyword: `%${searchKeyword}%`,
},
)
.orWhere(
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
? "profileChangePosition.citizenId LIKE :keyword"
: "1=1",
{
keyword: `%${searchKeyword}%`,
},
)
.orWhere(
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
? "profileChangePosition.birthDate LIKE :keyword"
: "1=1",
{
keyword: `%${searchKeyword}%`,
},
)
.orWhere(
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
? "profileChangePosition.lastUpdatedAt LIKE :keyword"
: "1=1",
{
keyword: `%${searchKeyword}%`,
},
)
.orWhere(
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
? "profileChangePosition.status LIKE :keyword"
: "1=1",
{
keyword: `%${searchKeyword}%`,
},
)
}),
) )
.orderBy("profileChangePosition.createdAt", "ASC") .orderBy("profileChangePosition.createdAt", "ASC")
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)