Skip to content

Commit

Permalink
refactor: re-use vordr where query
Browse files Browse the repository at this point in the history
  • Loading branch information
omBratteng committed Aug 8, 2024
1 parent d9ae55e commit 82ea686
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/common/feedGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
import graphorm from '../graphorm';
import { mapArrayToOjbect } from './object';
import { runInSpan } from '../telemetry';
import { vordrFilter } from './vordr';

export const WATERCOOLER_ID = 'fd062672-63b7-4a10-87bd-96dcd10e9613';

Expand Down Expand Up @@ -538,13 +539,12 @@ export const sourceFeedBuilder = (

builder.andWhere(
new Brackets((qb) => {
const filter = vordrFilter(alias);
return qb
.where(`${alias}.authorId = :userId OR ${alias}.scoutId = :userId`, {
userId: ctx.userId,
})
.orWhere(
`COALESCE((${alias}.flags ->> 'vordr')::boolean, false) = false`,
);
.orWhere(filter);
}),
);

Expand Down
9 changes: 6 additions & 3 deletions src/common/vordr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,17 @@ export const checkWithVordr = async (
return false;
};

export const vordrFilter = (alias: string): string =>
`COALESCE((${alias}.flags ->> 'vordr')::boolean, false) = false`;

export const whereVordrFilter = (alias: string, userId?: string) =>
new Brackets((qb) => {
const vordrFilter = `COALESCE((${alias}.flags ->> 'vordr')::boolean, false) = false`;
const filter = vordrFilter(alias);
isNullOrUndefined(userId)
? qb.where(vordrFilter)
? qb.where(filter)
: qb
.where(`${alias}.userId = :userId`, {
userId: userId,
})
.orWhere(vordrFilter);
.orWhere(filter);
});

0 comments on commit 82ea686

Please sign in to comment.