import { Inject, Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; import type { ChannelsRepository } from '@/models/index.js'; import { QueryService } from '@/core/QueryService.js'; import { ChannelEntityService } from '@/core/entities/ChannelEntityService.js'; import { DI } from '@/di-symbols.js'; // eslint-disable-next-line import/no-default-export @Injectable() export default class extends Endpoint<'channels/owned'> { name = 'channels/owned' as const; constructor( @Inject(DI.channelsRepository) private channelsRepository: ChannelsRepository, private channelEntityService: ChannelEntityService, private queryService: QueryService, ) { super(async (ps, me) => { const query = this.queryService.makePaginationQuery(this.channelsRepository.createQueryBuilder('channel'), ps.sinceId, ps.untilId) .andWhere('channel.isArchived = FALSE') .andWhere({ userId: me.id }); const channels = await query .take(ps.limit) .getMany(); return await Promise.all(channels.map(x => this.channelEntityService.pack(x, me))); }); } }