1
0
Fork 0
mirror of synced 2024-06-28 11:00:55 +12:00

Error when searching global users using more than one filter per field

This commit is contained in:
Andrew Kingston 2023-12-12 11:15:29 +00:00
parent 635bf9acf2
commit f7b7f3efde
2 changed files with 35 additions and 1 deletions

View file

@ -195,7 +195,11 @@ export const search = async (ctx: Ctx<SearchUsersRequest>) => {
if (filters && typeof filters === "object") {
for (let [field, value] of Object.entries(filters)) {
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
}
}
}

View file

@ -617,6 +617,36 @@ describe("/api/global/users", () => {
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 () => {
const user = await config.createUser()
await config.api.users.searchUsers(