From 27d1d96c9d3348ff9b41a239f84722b93a3e376c Mon Sep 17 00:00:00 2001 From: naskya Date: Sun, 7 May 2023 09:13:37 +0900 Subject: [PATCH] Modify backend for Calckey --- .../server/api/endpoints/channels/search.ts | 67 ++++++++----------- packages/client/src/pages/channels.vue | 17 ++--- 2 files changed, 36 insertions(+), 48 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/channels/search.ts b/packages/backend/src/server/api/endpoints/channels/search.ts index 5527adb9b4..5758d81a67 100644 --- a/packages/backend/src/server/api/endpoints/channels/search.ts +++ b/packages/backend/src/server/api/endpoints/channels/search.ts @@ -1,9 +1,8 @@ -import { Inject, Injectable } from "@nestjs/common"; +import define from "../../define.js"; import { Brackets } from "typeorm"; import { Endpoint } from "@/server/api/endpoint-base.js"; -import { QueryService } from "@/core/QueryService.js"; -import type { ChannelsRepository } from "@/models/index.js"; -import { ChannelEntityService } from "@/core/entities/ChannelEntityService.js"; +import { makePaginationQuery } from "@/server/api/common/make-pagination-query.js"; +import { Channels } from "@/models/index.js"; import { DI } from "@/di-symbols.js"; import { sqlLikeEscape } from "@/misc/sql-like-escape.js"; @@ -41,44 +40,32 @@ export const paramDef = { required: ["query"], } as const; -// eslint-disable-next-line import/no-default-export -@Injectable() -export default class extends Endpoint { - constructor( - @Inject(DI.channelsRepository) - private channelsRepository: ChannelsRepository, +export default define(meta, paramDef, async (ps, me) => { + const query = makePaginationQuery( + Channels.createQueryBuilder("channel"), + ps.sinceId, + ps.untilId, + ); - private channelEntityService: ChannelEntityService, - private queryService: QueryService, - ) { - super(meta, paramDef, async (ps, me) => { - const query = this.queryService.makePaginationQuery( - this.channelsRepository.createQueryBuilder("channel"), - ps.sinceId, - ps.untilId, - ); - - if (ps.type === "nameAndDescription") { - query.andWhere( - new Brackets((qb) => { - qb.where("channel.name ILIKE :q", { - q: `%${sqlLikeEscape(ps.query)}%`, - }).orWhere("channel.description ILIKE :q", { - q: `%${sqlLikeEscape(ps.query)}%`, - }); - }), - ); - } else { - query.andWhere("channel.name ILIKE :q", { + if (ps.type === "nameAndDescription") { + query.andWhere( + new Brackets((qb) => { + qb.where("channel.name ILIKE :q", { + q: `%${sqlLikeEscape(ps.query)}%`, + }).orWhere("channel.description ILIKE :q", { q: `%${sqlLikeEscape(ps.query)}%`, }); - } - - const channels = await query.take(ps.limit).getMany(); - - return await Promise.all( - channels.map((x) => this.channelEntityService.pack(x, me)), - ); + }), + ); + } else { + query.andWhere("channel.name ILIKE :q", { + q: `%${sqlLikeEscape(ps.query)}%`, }); } -} + + const channels = await query.take(ps.limit).getMany(); + + return await Promise.all( + channels.map((x) => Channels.pack(x, me)), + ); +}); diff --git a/packages/client/src/pages/channels.vue b/packages/client/src/pages/channels.vue index f188fb1daf..5c87027878 100644 --- a/packages/client/src/pages/channels.vue +++ b/packages/client/src/pages/channels.vue @@ -22,7 +22,6 @@ >