42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { Controller, Get, Path, Query, Route, Tags } from "tsoa";
|
|
import prisma from "../db";
|
|
import { queryOrNot } from "../utils/relation";
|
|
import { notFoundError } from "../utils/error";
|
|
|
|
@Route("/api/v1/employment-office")
|
|
@Tags("Employment Office")
|
|
export class EmploymentOfficeController extends Controller {
|
|
@Get()
|
|
async getEmploymentOfficeList(@Query() districtId?: string, @Query() query: string = "") {
|
|
return await prisma.employmentOffice.findMany({
|
|
where: {
|
|
OR: [
|
|
{
|
|
province: {
|
|
district: { some: { id: districtId } },
|
|
},
|
|
district: { none: {} },
|
|
},
|
|
{
|
|
district: {
|
|
some: { districtId },
|
|
},
|
|
},
|
|
...(queryOrNot(query, [{ name: query }, { nameEN: query }]) ?? []),
|
|
],
|
|
},
|
|
orderBy: [{ provinceId: "asc" }, { id: "asc" }],
|
|
});
|
|
}
|
|
|
|
@Get("{employmentOfficeId}")
|
|
async getEmploymentOffice(@Path() employmentOfficeId: string) {
|
|
const record = await prisma.employmentOffice.findFirst({
|
|
where: { id: employmentOfficeId },
|
|
});
|
|
|
|
if (!record) throw notFoundError("Employment Office");
|
|
|
|
return record;
|
|
}
|
|
}
|