fix: クエリとか修正

This commit is contained in:
鴇峰 朔華 2024-11-19 11:08:34 +09:00
parent ac95b12f0b
commit fd9b7edeff
5 changed files with 14 additions and 11 deletions

View File

@ -11,6 +11,7 @@ import type { UserProfilesRepository, FollowingsRepository, ChannelFollowingsRep
import { bindThis } from '@/decorators.js';
import { IdService } from '@/core/IdService.js';
import type { SelectQueryBuilder } from 'typeorm';
import {MiBlockingType} from "@/models/_.js";
@Injectable()
export class QueryService {
@ -73,7 +74,7 @@ export class QueryService {
const blockingQuery = this.blockingsRepository.createQueryBuilder('blocking')
.select('blocking.blockerId')
.where('blocking.blockeeId = :blockeeId', { blockeeId: me.id })
.andWhere('blocking.blockType = "user"');
.andWhere('blocking.blockType = :blockType', { blockType: MiBlockingType.User });
// 投稿の作者にブロックされていない かつ
// 投稿の返信先の作者にブロックされていない かつ
@ -99,7 +100,7 @@ export class QueryService {
const blockingQuery = this.blockingsRepository.createQueryBuilder('blocking')
.select('blocking.blockeeId')
.where('blocking.blockerId = :blockerId', { blockerId: me.id })
.andWhere('blocking.blockType = "user"');
.andWhere('blocking.blockType = :blockType', { blockType: MiBlockingType.User });
const blockedQuery = this.blockingsRepository.createQueryBuilder('blocking')
.select('blocking.blockerId')

View File

@ -291,25 +291,25 @@ export class UserEntityService implements OnModuleInit {
this.blockingsRepository.createQueryBuilder('b')
.select('b.blockeeId')
.where('b.blockerId = :me', { me })
.andWhere('b.blockType = "user"')
.andWhere('b.blockType = :type', { type: MiBlockingType.User })
.getRawMany<{ b_blockeeId: string }>()
.then(it => it.map(it => it.b_blockeeId)),
this.blockingsRepository.createQueryBuilder('b')
.select('b.blockerId')
.where('b.blockeeId = :me', { me })
.andWhere('b.blockType = "user"')
.andWhere('b.blockType = :type', { type: MiBlockingType.User })
.getRawMany<{ b_blockerId: string }>()
.then(it => it.map(it => it.b_blockerId)),
this.blockingsRepository.createQueryBuilder('b')
.select('b.blockeeId')
.where('b.blockerId = :me', { me })
.andWhere('b.blockType = "reaction"')
.andWhere('b.blockType = :type', { type: MiBlockingType.Reaction })
.getRawMany<{ b_blockeeId: string }>()
.then(it => it.map(it => it.b_blockeeId)),
this.blockingsRepository.createQueryBuilder('b')
.select('b.blockerId')
.where('b.blockeeId = :me', { me })
.andWhere('b.blockType = "reaction"')
.andWhere('b.blockType = :type', { type: MiBlockingType.Reaction })
.getRawMany<{ b_blockerId: string }>()
.then(it => it.map(it => it.b_blockerId)),
this.mutingsRepository.createQueryBuilder('m')

View File

@ -9,6 +9,7 @@ import type { BlockingsRepository } from '@/models/_.js';
import { QueryService } from '@/core/QueryService.js';
import { BlockingEntityService } from '@/core/entities/BlockingEntityService.js';
import { DI } from '@/di-symbols.js';
import { MiBlockingType } from '@/models/Blocking.js';
export const meta = {
tags: ['account'],
@ -50,7 +51,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
super(meta, paramDef, async (ps, me) => {
const query = this.queryService.makePaginationQuery(this.blockingsRepository.createQueryBuilder('blocking'), ps.sinceId, ps.untilId)
.andWhere('blocking.blockerId = :meId', { meId: me.id })
.andWhere('blocking.blockType = "reaction"');
.andWhere('blocking.blockType = :blockType', { blockType: MiBlockingType.Reaction });
const blockings = await query
.limit(ps.limit)

View File

@ -9,6 +9,7 @@ import type { BlockingsRepository } from '@/models/_.js';
import { QueryService } from '@/core/QueryService.js';
import { BlockingEntityService } from '@/core/entities/BlockingEntityService.js';
import { DI } from '@/di-symbols.js';
import { MiBlockingType } from '@/models/Blocking.js';
export const meta = {
tags: ['account'],
@ -50,7 +51,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
super(meta, paramDef, async (ps, me) => {
const query = this.queryService.makePaginationQuery(this.blockingsRepository.createQueryBuilder('blocking'), ps.sinceId, ps.untilId)
.andWhere('blocking.blockerId = :meId', { meId: me.id })
.andWhere('blocking.blockType = "user"');
.andWhere('blocking.blockType = :blockType', { blockType: MiBlockingType.User });
const blockings = await query
.limit(ps.limit)

View File

@ -12,7 +12,7 @@ import { secureRndstr } from '@/misc/secure-rndstr.js';
import { genAidx } from '@/misc/id/aidx.js';
import {
BlockingsRepository,
FollowingsRepository, FollowRequestsRepository,
FollowingsRepository, FollowRequestsRepository, MiBlockingType,
MiUserProfile, MutingsRepository, RenoteMutingsRepository,
UserMemoRepository,
UserProfilesRepository,
@ -115,7 +115,7 @@ describe('UserEntityService', () => {
id: genAidx(Date.now()),
blockerId: blocker.id,
blockeeId: blockee.id,
isReactionBlock: false,
blockType: MiBlockingType.User,
});
}
@ -124,7 +124,7 @@ describe('UserEntityService', () => {
id: genAidx(Date.now()),
blockerId: blocker.id,
blockeeId: blockee.id,
isReactionBlock: true,
blockType: MiBlockingType.Reaction,
});
}