summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/FlashService.ts
blob: 2a98225382b39317e07e50a6cf9e6beaf0551f2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
 * SPDX-FileCopyrightText: syuilo and misskey-project
 * SPDX-License-Identifier: AGPL-3.0-only
 */

import { Inject, Injectable } from '@nestjs/common';
import { DI } from '@/di-symbols.js';
import { type FlashsRepository } from '@/models/_.js';

/**
 * MisskeyPlay関係のService
 */
@Injectable()
export class FlashService {
	constructor(
		@Inject(DI.flashsRepository)
		private flashRepository: FlashsRepository,
	) {
	}

	/**
	 * 人気のあるPlay一覧を取得する.
	 */
	public async featured(opts?: { offset?: number, limit: number }) {
		const builder = this.flashRepository.createQueryBuilder('flash')
			.andWhere('flash.likedCount > 0')
			.andWhere('flash.visibility = :visibility', { visibility: 'public' })
			.addOrderBy('flash.likedCount', 'DESC')
			.addOrderBy('flash.updatedAt', 'DESC')
			.addOrderBy('flash.id', 'DESC');

		if (opts?.offset) {
			builder.skip(opts.offset);
		}

		builder.take(opts?.limit ?? 10);

		return await builder.getMany();
	}
}