feat: add normal search for employment office

This commit is contained in:
Methapon Metanipat 2024-11-14 15:21:28 +07:00
parent 401d376a63
commit c1fdf26b39

View file

@ -1,11 +1,12 @@
import { Controller, Get, Query, Route, Tags } from "tsoa";
import prisma from "../db";
import { queryOrNot } from "../utils/relation";
@Route("/api/v1/employment-office")
@Tags("Employment Office")
export class EmploymentOfficeController extends Controller {
@Get()
async getEmploymentOfficeList(@Query() districtId?: string) {
async getEmploymentOfficeList(@Query() districtId?: string, @Query() query: string = "") {
return await prisma.employmentOffice.findMany({
where: {
OR: [
@ -20,6 +21,7 @@ export class EmploymentOfficeController extends Controller {
some: { districtId },
},
},
...(queryOrNot(query, [{ name: query }, { nameEN: query }]) ?? []),
],
},
orderBy: [{ provinceId: "asc" }, { id: "asc" }],