feat: add complex query
This commit is contained in:
parent
13ff6caadc
commit
bbd2c23b12
1 changed files with 15 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { Controller, Get, Path, Query, Route, Tags } from "tsoa";
|
import { Body, Controller, Get, Path, Post, Query, Route, Tags } from "tsoa";
|
||||||
import prisma from "../db";
|
import prisma from "../db";
|
||||||
import { queryOrNot } from "../utils/relation";
|
import { queryOrNot } from "../utils/relation";
|
||||||
import { notFoundError } from "../utils/error";
|
import { notFoundError } from "../utils/error";
|
||||||
|
|
@ -8,10 +8,22 @@ import { notFoundError } from "../utils/error";
|
||||||
export class EmploymentOfficeController extends Controller {
|
export class EmploymentOfficeController extends Controller {
|
||||||
@Get()
|
@Get()
|
||||||
async getEmploymentOfficeList(@Query() districtId?: string, @Query() query: string = "") {
|
async getEmploymentOfficeList(@Query() districtId?: string, @Query() query: string = "") {
|
||||||
|
this.getEmploymentOfficeListByCriteria(districtId, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post("list")
|
||||||
|
async getEmploymentOfficeListByCriteria(
|
||||||
|
@Query() districtId?: string,
|
||||||
|
@Query() query: string = "",
|
||||||
|
@Body()
|
||||||
|
body?: {
|
||||||
|
id?: string[];
|
||||||
|
},
|
||||||
|
) {
|
||||||
return await prisma.employmentOffice.findMany({
|
return await prisma.employmentOffice.findMany({
|
||||||
where: {
|
where: {
|
||||||
OR:
|
OR:
|
||||||
districtId || query
|
districtId || query || body?.id
|
||||||
? [
|
? [
|
||||||
...queryOrNot(
|
...queryOrNot(
|
||||||
!!districtId,
|
!!districtId,
|
||||||
|
|
@ -33,6 +45,7 @@ export class EmploymentOfficeController extends Controller {
|
||||||
[{ name: { contains: query } }, { nameEN: { contains: query } }],
|
[{ name: { contains: query } }, { nameEN: { contains: query } }],
|
||||||
[],
|
[],
|
||||||
),
|
),
|
||||||
|
...queryOrNot(!!body?.id, [{ id: { in: body?.id } }], []),
|
||||||
]
|
]
|
||||||
: undefined,
|
: undefined,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue