feat(medusa): Add support for filtering with gt, lt, gte and lte (#190)
- Add support for filtering with lt, gt, lte, gte in the following format: created_at[gt]=01-26-1997 - Add middleware for cleaning request queries - Add order query validation - Temp. disables tags in claim integration tests
This commit is contained in:
1 parent
bb7dcbd706
commit
dd0491f521
8 files changed
+357
-71
No files matched your search
@@ -11,9 +11,6 @@ describe("BaseService", () => {
|
||||
id: "1234",
|
||||
test1: ["123", "12", "1"],
|
||||
test2: Not("this"),
|
||||
rec: {
|
||||
first: ["1", "2", "3"],
|
||||
},
|
||||
},
|
||||
{
|
||||
relations: ["1234"],
|
||||
@@ -25,9 +22,6 @@ describe("BaseService", () => {
|
||||
id: "1234",
|
||||
test1: In(["123", "12", "1"]),
|
||||
test2: Not("this"),
|
||||
rec: {
|
||||
first: In(["1", "2", "3"]),
|
||||
},
|
||||
},
|
||||
relations: ["1234"],
|
||||
})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
import { In, FindOperator, getManager } from "typeorm"
|
||||
import { In, FindOperator, Raw } from "typeorm"
|
||||
|
||||
/**
|
||||
* Common functionality for Services
|
||||
@@ -29,7 +29,32 @@ class BaseService {
|
||||
acc[key] = In([...value])
|
||||
break
|
||||
case value !== null && typeof value === "object":
|
||||
acc[key] = build(value)
|
||||
const subquery = []
|
||||
|
||||
Object.entries(value).map(([modifier, val]) => {
|
||||
switch (modifier) {
|
||||
case "lt":
|
||||
subquery.push({ operator: "<", value: val })
|
||||
break
|
||||
case "gt":
|
||||
subquery.push({ operator: ">", value: val })
|
||||
break
|
||||
case "lte":
|
||||
subquery.push({ operator: "<=", value: val })
|
||||
break
|
||||
case "gte":
|
||||
subquery.push({ operator: ">=", value: val })
|
||||
break
|
||||
}
|
||||
})
|
||||
|
||||
acc[key] = Raw(
|
||||
a =>
|
||||
subquery
|
||||
.map((s, index) => `${a} ${s.operator} :${index}`)
|
||||
.join(" AND "),
|
||||
subquery.map(s => s.value)
|
||||
)
|
||||
break
|
||||
default:
|
||||
acc[key] = value
|
||||
|
||||
Reference in new issue
Block a user