mirror of
https://github.com/plankanban/planka.git
synced 2025-12-19 01:12:02 +03:00
feat: Track storage usage
This commit is contained in:
36
server/api/hooks/query-methods/helpers.js
Normal file
36
server/api/hooks/query-methods/helpers.js
Normal file
@@ -0,0 +1,36 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
const makeWhereQueryBuilder = (Model) => (criteria) => {
|
||||
if (_.isPlainObject(criteria)) {
|
||||
if (Object.keys(criteria).length === 0) {
|
||||
throw new Error('Empty criteria');
|
||||
}
|
||||
|
||||
const parts = [];
|
||||
const values = [];
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const [key, value] of Object.entries(criteria)) {
|
||||
// eslint-disable-next-line no-underscore-dangle
|
||||
const columnName = Model._transformer._transformations[key];
|
||||
|
||||
if (!columnName) {
|
||||
throw new Error('Unknown column');
|
||||
}
|
||||
|
||||
parts.push(`${columnName} = $${index + 1}`);
|
||||
values.push(value);
|
||||
}
|
||||
|
||||
return [parts.join(' AND '), values];
|
||||
}
|
||||
|
||||
return ['id = $1', [criteria]];
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
makeWhereQueryBuilder,
|
||||
};
|
||||
Reference in New Issue
Block a user