jormungandr-bite/packages/backend/src/server/api/common/generate-muted-note-query.ts

17 lines
501 B
TypeScript
Raw Normal View History

2023-01-12 21:40:33 -07:00
import type { User } from "@/models/entities/user.js";
import { MutedNotes } from "@/models/index.js";
import type { SelectQueryBuilder } from "typeorm";
2023-01-12 21:40:33 -07:00
export function generateMutedNoteQuery(
q: SelectQueryBuilder<any>,
me: { id: User["id"] },
) {
const mutedQuery = MutedNotes.createQueryBuilder("muted")
.select("muted.noteId")
.where("muted.userId = :userId", { userId: me.id });
2023-01-12 21:40:33 -07:00
q.andWhere(`note.id NOT IN (${mutedQuery.getQuery()})`);
q.setParameters(mutedQuery.getParameters());
}