🐛 Fix ORM query builder with $in option for postgres (#771)
This commit is contained in:
+11
-2
@@ -83,8 +83,17 @@ export class PostgresQueryBuilder {
|
||||
|
||||
// === IN ===
|
||||
options.$in?.forEach(e => {
|
||||
whereClause += `${e[0]} IN ($${e[1].map(() => idx++).join(",$")}) AND `;
|
||||
values.push(...e[1]);
|
||||
const [column, valuesArray] = e;
|
||||
|
||||
// throw an error if the values array is empty
|
||||
if (!valuesArray || valuesArray.length === 0) {
|
||||
throw new Error(
|
||||
`The $in operator for column '${column}' requires a non-empty array of values.`,
|
||||
);
|
||||
}
|
||||
|
||||
whereClause += `${column} IN ($${valuesArray.map(() => idx++).join(",$")}) AND `;
|
||||
values.push(...valuesArray);
|
||||
});
|
||||
|
||||
// === LIKE ====
|
||||
|
||||
@@ -169,7 +169,7 @@ export class UserServiceImpl {
|
||||
pagination,
|
||||
};
|
||||
|
||||
if (options?.userIds) {
|
||||
if (Array.isArray(options?.userIds) && options.userIds.length > 0) {
|
||||
findOptions.$in = [["id", options.userIds]];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user