feat: add granular filters to machines inventory export
This commit is contained in:
parent
a3d431efa8
commit
3880ff57bd
2 changed files with 272 additions and 18 deletions
|
|
@ -20,6 +20,8 @@ export async function GET(request: Request) {
|
|||
|
||||
const { searchParams } = new URL(request.url)
|
||||
const companyId = searchParams.get("companyId") ?? undefined
|
||||
const machineIdParams = searchParams.getAll("machineId").filter(Boolean)
|
||||
const machineIdFilter = machineIdParams.length > 0 ? new Set(machineIdParams) : null
|
||||
|
||||
const client = new ConvexHttpClient(convexUrl)
|
||||
const tenantId = session.user.tenantId ?? DEFAULT_TENANT_ID
|
||||
|
|
@ -50,8 +52,16 @@ export async function GET(request: Request) {
|
|||
})) as MachineInventoryRecord[]
|
||||
|
||||
const filtered = machines.filter((machine) => {
|
||||
if (!companyId) return true
|
||||
return String(machine.companyId ?? "") === companyId || machine.companySlug === companyId
|
||||
if (companyId) {
|
||||
const companyMatches = String(machine.companyId ?? "") === companyId || (machine.companySlug ?? "") === companyId
|
||||
if (!companyMatches) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if (machineIdFilter && !machineIdFilter.has(String(machine.id))) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
const companyFilterLabel = (() => {
|
||||
if (!companyId) return null
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue