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