feat(filters): add No tags filter to transactions and shared pages
This commit is contained in:
+12
-4
@@ -115,8 +115,14 @@ export async function getTransactions(ownerId: number, filters: TransactionFilte
|
||||
}
|
||||
}
|
||||
if (filters.tag_ids?.length) {
|
||||
conditions.push(`EXISTS (SELECT 1 FROM transaction_tags tt2 WHERE tt2.transaction_id = t.id AND tt2.tag_id = ANY($${paramIdx++}::int[]))`);
|
||||
params.push(filters.tag_ids.map(Number));
|
||||
const noTags = filters.tag_ids.includes("untagged");
|
||||
const realTagIds = filters.tag_ids.filter((id) => id !== "untagged").map(Number);
|
||||
if (noTags) {
|
||||
conditions.push(`NOT EXISTS (SELECT 1 FROM transaction_tags tt2 WHERE tt2.transaction_id = t.id)`);
|
||||
} else if (realTagIds.length > 0) {
|
||||
conditions.push(`EXISTS (SELECT 1 FROM transaction_tags tt2 WHERE tt2.transaction_id = t.id AND tt2.tag_id = ANY($${paramIdx++}::int[]))`);
|
||||
params.push(realTagIds);
|
||||
}
|
||||
}
|
||||
if (filters.transaction_types?.length) {
|
||||
conditions.push(`t.transaction_type = ANY($${paramIdx++}::text[])`);
|
||||
@@ -343,10 +349,12 @@ export async function getTags() {
|
||||
`);
|
||||
}
|
||||
|
||||
export async function getSharedTransactions(ownerId: number, tagIds?: number[]) {
|
||||
export async function getSharedTransactions(ownerId: number, tagIds?: number[], noTags?: boolean) {
|
||||
const params: unknown[] = [ownerId];
|
||||
let tagClause = "";
|
||||
if (tagIds?.length) {
|
||||
if (noTags) {
|
||||
tagClause = `AND NOT EXISTS (SELECT 1 FROM transaction_tags tt WHERE tt.transaction_id = t.id)`;
|
||||
} else if (tagIds?.length) {
|
||||
params.push(tagIds);
|
||||
tagClause = `AND EXISTS (SELECT 1 FROM transaction_tags tt WHERE tt.transaction_id = t.id AND tt.tag_id = ANY($2::int[]))`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user