2022-09-18 03:27:08 +09:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
2022-09-21 05:33:11 +09:00
|
|
|
import type { ChannelsRepository } from '@/models/index.js';
|
2022-09-18 03:27:08 +09:00
|
|
|
import { QueryService } from '@/core/QueryService.js';
|
|
|
|
|
import { ChannelEntityService } from '@/core/entities/ChannelEntityService.js';
|
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2020-08-18 22:44:21 +09:00
|
|
|
|
2022-01-03 02:12:50 +09:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-09-18 03:27:08 +09:00
|
|
|
@Injectable()
|
2023-06-04 17:42:10 +00:00
|
|
|
export default class extends Endpoint<'channels/owned'> {
|
|
|
|
|
name = 'channels/owned' as const;
|
2022-09-18 03:27:08 +09:00
|
|
|
constructor(
|
|
|
|
|
@Inject(DI.channelsRepository)
|
|
|
|
|
private channelsRepository: ChannelsRepository,
|
|
|
|
|
|
|
|
|
|
private channelEntityService: ChannelEntityService,
|
|
|
|
|
private queryService: QueryService,
|
|
|
|
|
) {
|
2023-06-04 17:42:10 +00:00
|
|
|
super(async (ps, me) => {
|
2023-05-08 07:59:06 +09:00
|
|
|
const query = this.queryService.makePaginationQuery(this.channelsRepository.createQueryBuilder('channel'), ps.sinceId, ps.untilId)
|
2023-05-06 08:15:17 +09:00
|
|
|
.andWhere('channel.isArchived = FALSE')
|
2022-09-18 03:27:08 +09:00
|
|
|
.andWhere({ userId: me.id });
|
|
|
|
|
|
|
|
|
|
const channels = await query
|
|
|
|
|
.take(ps.limit)
|
|
|
|
|
.getMany();
|
|
|
|
|
|
|
|
|
|
return await Promise.all(channels.map(x => this.channelEntityService.pack(x, me)));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|