Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add negative filters #328

Open
wants to merge 1 commit into
base: mistress
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add negative filters
majkus522 committed Jan 7, 2025
commit 97591b5507fabfcabad1a629004e722b22e4781e
32 changes: 21 additions & 11 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -41,20 +41,30 @@ router.get('/:type*/all', async (ctx) => {

ctx.body = entityObjects.filter((entity) => {
if (!entity) return;

for (const key of Object.keys(params)) {
const value = entity[key];

switch (typeof value) {
case 'string':
if (!value.includes(params[key] as string)) return false;
break;
default:
if (value != params[key]) return false;
break;
let negativeFilter = key.endsWith('!');
const value = entity[key.replace('!', '')];
if (negativeFilter) {
switch (typeof value) {
case 'string':
if (value.includes(params[key] as string)) return false;
break;
default:
console.log(value, params[key]);
if (value == params[key]) return false;
break;
}
} else {
switch (typeof value) {
case 'string':
if (!value.includes(params[key] as string)) return false;
break;
default:
if (value != params[key]) return false;
break;
}
}
}

return true;
});
} catch (e) {