no message

This commit is contained in:
kittapath 2024-09-06 10:33:13 +07:00
parent 98ebf587a3
commit f23fd05c2a

View file

@ -218,37 +218,42 @@ export class PermissionOrgController extends Controller {
* *
* @param {string} id Id * @param {string} id Id
*/ */
@Get("{id}") @Post("profile")
async GetById( async GetById(
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
@Path() id: string, @Body()
@Query("page") page: number = 1, requestBody: {
@Query("pageSize") pageSize: number = 10, id: string | null;
@Query() page: number;
searchField?: "fullName" | "position" | "posNo" | "postype" | "poslevel", pageSize: number;
@Query() searchKeyword: string = "", searchField?: "fullName" | "position" | "posNo" | "postype" | "poslevel";
searchKeyword: string;
},
) { ) {
if (!request.user.role.includes("SUPER_ADMIN")) { if (!request.user.role.includes("SUPER_ADMIN")) {
throw new HttpError(HttpStatus.FORBIDDEN, "ไม่มีสิทธิ์ใช้งานระบบนี้"); throw new HttpError(HttpStatus.FORBIDDEN, "ไม่มีสิทธิ์ใช้งานระบบนี้");
} }
const _permissionOrg = await this.orgRootRepository.findOne({ let profiles: any = [];
where: { id }, if (requestBody.id != null) {
relations: ["permissionOrgRoots"], const _permissionOrg = await this.orgRootRepository.findOne({
}); where: { id: requestBody.id },
if (!_permissionOrg) { relations: ["permissionOrgRoots", "permissionOrgRoots.profileTree"],
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์โครงสร้างนี้"); });
if (!_permissionOrg) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์โครงสร้างนี้");
}
profiles = await _permissionOrg.permissionOrgRoots.map((x) => x.profileTree.id);
} }
let profiles = _permissionOrg.permissionOrgRoots.map((x) => x.profileTree);
let queryLike = let queryLike =
"CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword"; "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword";
if (searchField == "postype") { if (requestBody.searchField == "postype") {
queryLike = "posLevel.name LIKE :keyword"; queryLike = "posLevel.name LIKE :keyword";
} else if (searchField == "poslevel") { } else if (requestBody.searchField == "poslevel") {
queryLike = "posType.name LIKE :keyword"; queryLike = "posType.name LIKE :keyword";
} else if (searchField == "position") { } else if (requestBody.searchField == "position") {
queryLike = "profile.position LIKE :keyword"; queryLike = "profile.position LIKE :keyword";
} else if (searchField == "posNo") { } else if (requestBody.searchField == "posNo") {
queryLike = `CONCAT( queryLike = `CONCAT(
IFNULL(orgChild4.orgChild4ShortName, ''), IFNULL(orgChild4.orgChild4ShortName, ''),
IFNULL(orgChild3.orgChild3ShortName, ''), IFNULL(orgChild3.orgChild3ShortName, ''),
@ -269,19 +274,21 @@ export class PermissionOrgController extends Controller {
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2") .leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3") .leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4") .leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.andWhere(`current_holders.orgRootId IN (:...profiles)`, { .andWhere(`profile.id IN (:...profiles)`, {
profiles: profiles, profiles: profiles == null ? [] : profiles,
}) })
.andWhere( .andWhere(
searchKeyword != undefined && searchKeyword != null && searchKeyword != "" requestBody.searchKeyword != undefined &&
requestBody.searchKeyword != null &&
requestBody.searchKeyword != ""
? queryLike ? queryLike
: "1=1", : "1=1",
{ {
keyword: `%${searchKeyword}%`, keyword: `%${requestBody.searchKeyword}%`,
}, },
) )
.skip((page - 1) * pageSize) .skip((requestBody.page - 1) * requestBody.pageSize)
.take(pageSize) .take(requestBody.pageSize)
.getManyAndCount(); .getManyAndCount();
const findRevision = await this.orgRevisionRepository.findOne({ const findRevision = await this.orgRevisionRepository.findOne({
@ -392,14 +399,12 @@ export class PermissionOrgController extends Controller {
} }
const orgRoot = await this.orgRootRepository.findOne({ const orgRoot = await this.orgRootRepository.findOne({
where: { id: requestBody.nodeId }, where: { id: requestBody.nodeId },
relations: ["permissionOrgRoots"],
}); });
if (!orgRoot) { if (!orgRoot) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสำนัก"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสำนัก");
} }
const profile = await this.profileRepository.findOne({ const profile = await this.profileRepository.findOne({
where: { id: requestBody.personId }, where: { id: requestBody.personId },
relations: ["permissionOrgRoots"],
}); });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัติ"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัติ");