Merge branch 'develop' of github.com:Frappet/bma-ehr-development into develop

# Conflicts:
#	tsoa.json
This commit is contained in:
Kittapath 2024-04-03 18:59:32 +07:00
commit 2e5d98d546
2 changed files with 87 additions and 8 deletions

View file

@ -13,7 +13,7 @@ import {
Query, Query,
} from "tsoa"; } from "tsoa";
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import { Not } from "typeorm"; import { Brackets, Not } from "typeorm";
import HttpSuccess from "../interfaces/http-success"; import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import HttpStatusCode from "../interfaces/http-status"; import HttpStatusCode from "../interfaces/http-status";
@ -189,16 +189,95 @@ export class DevelopmentOfficerHistoryController extends Controller {
const type = "OFFICER"; const type = "OFFICER";
const [development, total] = await AppDataSource.getRepository(DevelopmentHistory) const [development, total] = await AppDataSource.getRepository(DevelopmentHistory)
.createQueryBuilder("developmentHistory") .createQueryBuilder("developmentHistory")
// .andWhere(year == null ? "developmentHistory.year LIKE :year" : "1=1", { year: `${year}` }) .leftJoinAndSelect("developmentHistory.development", "development")
// .orWhere("developmentHistory.projectName LIKE :keyword", { keyword: `${keyword}` }) .leftJoinAndSelect("developmentHistory.posLevel", "posLevel")
// .select(["development.id", "development.projectName", "development.year"]) .leftJoinAndSelect("developmentHistory.posType", "posType")
// .orderBy("developmentHistory.year", "DESC") .andWhere("development.year = :year", { year: year })
.andWhere("developmentHistory.type = :type", { type: type })
.andWhere(
new Brackets((qb) => {
qb.where(
keyword != null && keyword != ""
? "developmentHistory.prefix LIKE :keyword"
: "1=1",
{
keyword: `%${keyword}%`,
},
)
.orWhere(
keyword != null && keyword != ""
? "developmentHistory.firstName LIKE :keyword"
: "1=1",
{
keyword: `%${keyword}%`,
},
)
.orWhere(
keyword != null && keyword != ""
? "developmentHistory.lastName LIKE :keyword"
: "1=1",
{
keyword: `%${keyword}%`,
},
)
.orWhere(
keyword != null && keyword != ""
? "developmentHistory.position LIKE :keyword"
: "1=1",
{
keyword: `%${keyword}%`,
},
)
.orWhere(
keyword != null && keyword != ""
? "developmentHistory.position LIKE :keyword"
: "1=1",
{
keyword: `%${keyword}%`,
},
)
.orWhere(
keyword != null && keyword != ""
? "development.projectName LIKE :keyword"
: "1=1",
{
keyword: `%${keyword}%`,
},
)
.orWhere(
keyword != null && keyword != ""
? "posType.posTypeName LIKE :keyword"
: "1=1",
{
keyword: `%${keyword}%`,
},
)
.orWhere(
keyword != null && keyword != ""
? "posLevel.posLevelName LIKE :keyword"
: "1=1",
{
keyword: `%${keyword}%`,
},
);
}),
)
.orderBy("developmentHistory.createdAt", "DESC") .orderBy("developmentHistory.createdAt", "DESC")
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
.take(pageSize) .take(pageSize)
.getManyAndCount(); .getManyAndCount();
const formattedData = development.map(item => ({
id: item.id,
citizenId: item.citizenId,
fullName: item.prefix+item.firstName+" "+item.lastName,
position: item.position,
posType: item.posType.posTypeName,
posLevel: item.posLevel.posLevelName,
projectName: item.development.projectName,
}));
return new HttpSuccess({ data: development, total }); return new HttpSuccess({ data: formattedData, total });
} }
/** /**

View file

@ -33,10 +33,10 @@
"name": "Development", "description": "ชื่อโครงการ/กิจกรรม/หลักสูตร" "name": "Development", "description": "ชื่อโครงการ/กิจกรรม/หลักสูตร"
}, },
{ {
"name": "DevelopmentOfficerHistory", "description": "ประวัติการฝึกอบรม/ดูงานข้าราชการ" "name": "DevelopmentOfficerHistory", "description": "ประวัติการฝึกอบรม/ดูงาน ขรก."
}, },
{ {
"name": "DevelopmentEmployeeHistory", "description": "ประวัติการฝึกอบรม/ดูงานลูกจ้าง" "name": "DevelopmentEmployeeHistory", "description": "ประวัติการฝึกอบรม/ดูงานลูกจ้าง."
} }
] ]
}, },