Error when searching global users using more than one filter per field
This commit is contained in:
parent
635bf9acf2
commit
f7b7f3efde
|
@ -195,7 +195,11 @@ export const search = async (ctx: Ctx<SearchUsersRequest>) => {
|
||||||
if (filters && typeof filters === "object") {
|
if (filters && typeof filters === "object") {
|
||||||
for (let [field, value] of Object.entries(filters)) {
|
for (let [field, value] of Object.entries(filters)) {
|
||||||
delete filters[field]
|
delete filters[field]
|
||||||
filters[db.removeKeyNumbering(field)] = value
|
const cleanedField = db.removeKeyNumbering(field)
|
||||||
|
if (filters[cleanedField] !== undefined) {
|
||||||
|
ctx.throw(400, "Only 1 filter per field is supported")
|
||||||
|
}
|
||||||
|
filters[cleanedField] = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -617,6 +617,36 @@ describe("/api/global/users", () => {
|
||||||
expect(response.body.data[0]._id).toBe(user._id)
|
expect(response.body.data[0]._id).toBe(user._id)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should throw an error when using multiple filters on the same field", async () => {
|
||||||
|
const user = await config.createUser()
|
||||||
|
await config.api.users.searchUsers(
|
||||||
|
{
|
||||||
|
query: {
|
||||||
|
string: {
|
||||||
|
["1:email"]: user.email,
|
||||||
|
["2:email"]: "something else",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ status: 400 }
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should throw an error when using multiple filters on the same field without prefixes", async () => {
|
||||||
|
const user = await config.createUser()
|
||||||
|
await config.api.users.searchUsers(
|
||||||
|
{
|
||||||
|
query: {
|
||||||
|
string: {
|
||||||
|
["_id"]: user.email,
|
||||||
|
["999:_id"]: "something else",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ status: 400 }
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it("should throw an error when unimplemented options used", async () => {
|
it("should throw an error when unimplemented options used", async () => {
|
||||||
const user = await config.createUser()
|
const user = await config.createUser()
|
||||||
await config.api.users.searchUsers(
|
await config.api.users.searchUsers(
|
||||||
|
|
Loading…
Reference in New Issue