FoundKey/packages/backend/src/server/api/common/generate-muted-note-thread-query.ts
Johann150 9384ce8cf5
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-08-02 16:59:21 +02:00

15 lines
604 B
TypeScript

import { User } from '@/models/entities/user.js';
import { NoteThreadMutings } from '@/models/index.js';
import { Brackets, SelectQueryBuilder } from 'typeorm';
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.id NOT IN (${ mutedQuery.getQuery() })`);
q.andWhere(`note.threadId NOT IN (${ mutedQuery.getQuery() })`);
q.setParameters(mutedQuery.getParameters());
}