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 { queryOrNot } from "../utils/relation";
|
||||
import { notFoundError } from "../utils/error";
|
||||
|
|
@ -8,10 +8,22 @@ import { notFoundError } from "../utils/error";
|
|||
export class EmploymentOfficeController extends Controller {
|
||||
@Get()
|
||||
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({
|
||||
where: {
|
||||
OR:
|
||||
districtId || query
|
||||
districtId || query || body?.id
|
||||
? [
|
||||
...queryOrNot(
|
||||
!!districtId,
|
||||
|
|
@ -33,6 +45,7 @@ export class EmploymentOfficeController extends Controller {
|
|||
[{ name: { contains: query } }, { nameEN: { contains: query } }],
|
||||
[],
|
||||
),
|
||||
...queryOrNot(!!body?.id, [{ id: { in: body?.id } }], []),
|
||||
]
|
||||
: undefined,
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue