43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { PrismaService } from '@/src/core/prisma/prisma.service'
|
|
import { Injectable, NotFoundException } from '@nestjs/common'
|
|
|
|
@Injectable()
|
|
export class ChannelService {
|
|
constructor(
|
|
private readonly prismaService: PrismaService,
|
|
) {
|
|
}
|
|
|
|
public async findRecommendedChannel() {
|
|
return this.prismaService.user.findMany({
|
|
where: { isDeactivated: false },
|
|
orderBy: { followings: { _count: 'desc' } },
|
|
include: { stream: true },
|
|
take: 7,
|
|
})
|
|
}
|
|
|
|
public async findByUsername(name: string) {
|
|
const channel = await this.prismaService.user.findUnique({
|
|
where: { name, isDeactivated: false },
|
|
include: {
|
|
socialLink: { orderBy: { position: 'desc' } },
|
|
stream: { include: { category: true } },
|
|
followings: true,
|
|
},
|
|
})
|
|
|
|
if (!channel) {
|
|
throw new NotFoundException('Канал не найден')
|
|
}
|
|
|
|
return channel
|
|
}
|
|
|
|
public async findFollowersCountByChannel(channelId: string) {
|
|
return this.prismaService.follow.count({
|
|
where: { following: { id: channelId } },
|
|
})
|
|
}
|
|
}
|