feat: add complex query

This commit is contained in:
Methapon Metanipat 2024-11-14 18:02:59 +07:00
parent 13ff6caadc
commit bbd2c23b12

View file

@ -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,
},