2019-07-21 15:27:36 +02:00
|
|
|
import { User } from '../../../models/entities/user';
|
|
|
|
import { Blockings } from '../../../models';
|
|
|
|
import { SelectQueryBuilder } from 'typeorm';
|
|
|
|
|
2021-03-24 03:05:37 +01:00
|
|
|
export function generateBlockQueryForUsers(q: SelectQueryBuilder<any>, me: { id: User['id'] }) {
|
2019-07-21 15:27:36 +02:00
|
|
|
const blockingQuery = Blockings.createQueryBuilder('blocking')
|
|
|
|
.select('blocking.blockeeId')
|
|
|
|
.where('blocking.blockerId = :blockerId', { blockerId: me.id });
|
|
|
|
|
|
|
|
const blockedQuery = Blockings.createQueryBuilder('blocking')
|
|
|
|
.select('blocking.blockerId')
|
|
|
|
.where('blocking.blockeeId = :blockeeId', { blockeeId: me.id });
|
|
|
|
|
|
|
|
q.andWhere(`user.id NOT IN (${ blockingQuery.getQuery() })`);
|
|
|
|
q.setParameters(blockingQuery.getParameters());
|
|
|
|
|
|
|
|
q.andWhere(`user.id NOT IN (${ blockedQuery.getQuery() })`);
|
|
|
|
q.setParameters(blockedQuery.getParameters());
|
|
|
|
}
|