Filter by tags
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- A unique constraint covering the columns `[loggedCallId,name]` on the table `LoggedCallTag` will be added. If there are existing duplicate values, this will fail.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE UNIQUE INDEX "LoggedCallTag_loggedCallId_name_key" ON "LoggedCallTag"("loggedCallId", "name");
|
||||||
@@ -331,6 +331,7 @@ model LoggedCallTag {
|
|||||||
loggedCallId String @db.Uuid
|
loggedCallId String @db.Uuid
|
||||||
loggedCall LoggedCall @relation(fields: [loggedCallId], references: [id], onDelete: Cascade)
|
loggedCall LoggedCall @relation(fields: [loggedCallId], references: [id], onDelete: Cascade)
|
||||||
|
|
||||||
|
@@unique([loggedCallId, name])
|
||||||
@@index([projectId, name])
|
@@index([projectId, name])
|
||||||
@@index([projectId, name, value])
|
@@index([projectId, name, value])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,7 +90,28 @@ export const loggedCallsRouter = createTRPCRouter({
|
|||||||
return eb.and(wheres);
|
return eb.and(wheres);
|
||||||
});
|
});
|
||||||
|
|
||||||
const rawCalls = await baseQuery
|
const tagFilters = input.filters.filter(
|
||||||
|
(filter) => !defaultFilterableFields.includes(filter.field),
|
||||||
|
);
|
||||||
|
|
||||||
|
let updatedBaseQuery = baseQuery;
|
||||||
|
|
||||||
|
for (let i = 0; i < tagFilters.length; i++) {
|
||||||
|
const filter = tagFilters[i];
|
||||||
|
if (!filter?.value) continue;
|
||||||
|
const tableAlias = `lct${i}`;
|
||||||
|
updatedBaseQuery = updatedBaseQuery
|
||||||
|
.leftJoin(`LoggedCallTag as ${tableAlias}`, (join) =>
|
||||||
|
join
|
||||||
|
.onRef("lc.id", "=", `${tableAlias}.loggedCallId`)
|
||||||
|
.on(`${tableAlias}.name`, "=", filter.field),
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
sql.raw(`${tableAlias}.value ${comparatorToSqlValue(filter.comparator, filter.value)}`),
|
||||||
|
) as unknown as typeof baseQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
const rawCalls = await updatedBaseQuery
|
||||||
.select([
|
.select([
|
||||||
"lc.id as id",
|
"lc.id as id",
|
||||||
"lc.requestedAt as requestedAt",
|
"lc.requestedAt as requestedAt",
|
||||||
@@ -129,7 +150,7 @@ export const loggedCallsRouter = createTRPCRouter({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const matchingLogIds = await baseQuery.select(["lc.id"]).execute();
|
const matchingLogIds = await updatedBaseQuery.select(["lc.id"]).execute();
|
||||||
|
|
||||||
const count = matchingLogIds.length;
|
const count = matchingLogIds.length;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user