fix: empty query result in empty array

This commit is contained in:
Methapon Metanipat 2024-11-14 17:43:13 +07:00
parent 10a0ed0fc1
commit 927f972a91

View file

@ -10,7 +10,9 @@ export class EmploymentOfficeController extends Controller {
async getEmploymentOfficeList(@Query() districtId?: string, @Query() query: string = "") { async getEmploymentOfficeList(@Query() districtId?: string, @Query() query: string = "") {
return await prisma.employmentOffice.findMany({ return await prisma.employmentOffice.findMany({
where: { where: {
OR: [ OR:
!!districtId || !!query
? [
...(districtId ...(districtId
? [ ? [
{ {
@ -26,9 +28,12 @@ export class EmploymentOfficeController extends Controller {
}, },
] ]
: []), : []),
...(queryOrNot(query, [{ name: { contains: query } }, { nameEN: { contains: query } }]) ?? ...(queryOrNot(query, [
[]), { name: { contains: query } },
], { nameEN: { contains: query } },
]) ?? []),
]
: undefined,
}, },
orderBy: [{ provinceId: "asc" }, { id: "asc" }], orderBy: [{ provinceId: "asc" }, { id: "asc" }],
}); });