FoundKey/packages/backend/src/server/api/common/generate-muted-note-thread-query.ts
Johann150 457bd5ee3f
refactor: properly migrate thread ids
Commit fc65190ef7 introduced thread ids but
did not add the thread id to previous notes. This is fixed by this commit.

The original notes in each thread should also have a thread id set which will
be the same as their ID.

These two migrations allow the threadId column be a NOT NULL column.
2022-10-31 14:55:35 +01:00

14 lines
544 B
TypeScript

import { Brackets, SelectQueryBuilder } from 'typeorm';
import { User } from '@/models/entities/user.js';
import { NoteThreadMutings } from '@/models/index.js';
export function generateMutedNoteThreadQuery(q: SelectQueryBuilder<any>, me: { id: User['id'] }) {
const mutedQuery = NoteThreadMutings.createQueryBuilder('threadMuted')
.select('threadMuted.threadId')
.where('threadMuted.userId = :userId', { userId: me.id });
q.andWhere(`note.threadId NOT IN (${ mutedQuery.getQuery() })`);
q.setParameters(mutedQuery.getParameters());
}