เช็ค ข้อมูลหลัก #809 (เรื่อง search)
This commit is contained in:
parent
5e8b372323
commit
39b82dfa0a
3 changed files with 53 additions and 8 deletions
|
|
@ -11,12 +11,14 @@ import {
|
|||
Request,
|
||||
Response,
|
||||
Get,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { CommandSys, CreateCommandSys, UpdateCommandSys } from "../entities/CommandSys";
|
||||
import { Like } from "typeorm";
|
||||
|
||||
@Route("api/v1/org/commandSys")
|
||||
@Tags("CommandSys")
|
||||
|
|
@ -35,8 +37,12 @@ export class CommandSysController extends Controller {
|
|||
*
|
||||
*/
|
||||
@Get("list")
|
||||
async GetResult() {
|
||||
async GetResult(
|
||||
@Query("keyword") keyword?: string | null
|
||||
) {
|
||||
const condition = keyword && keyword.length > 0 ? { sysName: Like(`%${keyword}%`) } : {};
|
||||
const _commandSys = await this.commandSysRepository.find({
|
||||
where: condition,
|
||||
select: [
|
||||
"id",
|
||||
"sysName",
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import { CommandType, CreateCommandType, UpdateCommandType } from "../entities/CommandType";
|
||||
import { CommandSys } from "../entities/CommandSys";
|
||||
import { Brackets } from "typeorm";
|
||||
|
||||
@Route("api/v1/org/commandType")
|
||||
@Tags("CommandType")
|
||||
|
|
@ -73,6 +74,7 @@ export class CommandTypeController extends Controller {
|
|||
async GetAdmin(
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query("keyword") keyword?: string | null ,
|
||||
@Query() isActive?: boolean | null,
|
||||
) {
|
||||
const [commandTypes, total] = await this.commandTypeRepository
|
||||
|
|
@ -84,6 +86,22 @@ export class CommandTypeController extends Controller {
|
|||
isActive == null || isActive == undefined ? null : `${isActive == true ? 1 : 0}`,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
keyword != null && keyword != "" ? "commandType.name LIKE :keyword" : "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
keyword != null && keyword != "" ? "commandType.detailBody LIKE :keyword" : "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
})
|
||||
)
|
||||
.orderBy("commandType.order", "ASC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
|
|
|
|||
|
|
@ -562,10 +562,11 @@ export class PositionController extends Controller {
|
|||
@Get("position")
|
||||
async findPosition(@Query("keyword") keyword?: string, @Query("type") type?: string) {
|
||||
let findPosDict: any;
|
||||
if(keyword && keyword?.length > 0){
|
||||
switch (type) {
|
||||
case "positionName":
|
||||
findPosDict = await this.posDictRepository.find({
|
||||
where: { posDictName: Like(`%${keyword}%`) },
|
||||
where: { posDictName: keyword && keyword.length > 0?Like(`%${keyword}%`):"1=1" },
|
||||
relations: ["posType", "posLevel", "posExecutive"],
|
||||
order: {
|
||||
posDictName: "ASC",
|
||||
|
|
@ -587,7 +588,7 @@ export class PositionController extends Controller {
|
|||
|
||||
case "positionField":
|
||||
findPosDict = await this.posDictRepository.find({
|
||||
where: { posDictField: Like(`%${keyword}%`) },
|
||||
where: { posDictField: keyword && keyword.length > 0?Like(`%${keyword}%`):"1=1" },
|
||||
relations: ["posType", "posLevel", "posExecutive"],
|
||||
order: {
|
||||
posDictField: "ASC",
|
||||
|
|
@ -609,7 +610,7 @@ export class PositionController extends Controller {
|
|||
|
||||
case "positionType":
|
||||
const findTypes: PosType[] = await this.posTypeRepository.find({
|
||||
where: { posTypeName: Like(`%${keyword}%`) },
|
||||
where: { posTypeName: keyword && keyword.length > 0?Like(`%${keyword}%`):"1=1" },
|
||||
order: {
|
||||
// posTypeName: "ASC"
|
||||
posTypeRank: "ASC",
|
||||
|
|
@ -640,7 +641,7 @@ export class PositionController extends Controller {
|
|||
|
||||
case "positionLevel":
|
||||
const findLevel: PosLevel[] = await this.posLevelRepository.find({
|
||||
where: { posLevelName: Like(`%${keyword}%`) },
|
||||
where: { posLevelName: keyword && keyword.length > 0?Like(`%${keyword}%`):"1=1" },
|
||||
order: {
|
||||
// posLevelName: "ASC"
|
||||
posLevelRank: "ASC",
|
||||
|
|
@ -671,7 +672,7 @@ export class PositionController extends Controller {
|
|||
|
||||
case "positionExecutive":
|
||||
const findExecutive: PosExecutive[] = await this.posExecutiveRepository.find({
|
||||
where: { posExecutiveName: Like(`%${keyword}%`) },
|
||||
where: { posExecutiveName: keyword && keyword.length > 0?Like(`%${keyword}%`):"1=1" },
|
||||
select: ["id"],
|
||||
});
|
||||
findPosDict = await this.posDictRepository.find({
|
||||
|
|
@ -697,7 +698,7 @@ export class PositionController extends Controller {
|
|||
|
||||
case "positionExecutiveField":
|
||||
findPosDict = await this.posDictRepository.find({
|
||||
where: { posDictExecutiveField: Like(`%${keyword}%`) },
|
||||
where: { posDictExecutiveField: keyword && keyword.length > 0?Like(`%${keyword}%`):"1=1" },
|
||||
relations: ["posType", "posLevel", "posExecutive"],
|
||||
order: {
|
||||
posDictName: "ASC",
|
||||
|
|
@ -719,7 +720,7 @@ export class PositionController extends Controller {
|
|||
|
||||
case "positionArea":
|
||||
findPosDict = await this.posDictRepository.find({
|
||||
where: { posDictArea: Like(`%${keyword}%`) },
|
||||
where: { posDictArea: keyword && keyword.length > 0?Like(`%${keyword}%`):"1=1" },
|
||||
relations: ["posType", "posLevel", "posExecutive"],
|
||||
order: {
|
||||
posDictName: "ASC",
|
||||
|
|
@ -807,6 +808,26 @@ export class PositionController extends Controller {
|
|||
},
|
||||
});
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
findPosDict = await this.posDictRepository.find({
|
||||
relations: ["posType", "posLevel", "posExecutive"],
|
||||
order: {
|
||||
posDictName: "ASC",
|
||||
createdAt: "DESC",
|
||||
posType:{
|
||||
posTypeRank: "ASC",
|
||||
createdAt: "DESC"
|
||||
},
|
||||
posLevel: {
|
||||
posLevelRank: "ASC",
|
||||
createdAt: "DESC"
|
||||
},
|
||||
posExecutive: {
|
||||
posExecutivePriority: "ASC"
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const mapDataPosDict = await Promise.all(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue