mizzkey/packages/backend/src/server/api/endpoints/channels/owned.ts

32 lines
1.1 KiB
TypeScript
Raw Normal View History

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';
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) => {
const query = this.queryService.makePaginationQuery(this.channelsRepository.createQueryBuilder('channel'), ps.sinceId, ps.untilId)
.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)));
});
}
}