import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { Channel } from '../entities/channel.entity'; @Injectable() export class ChannelsService { constructor( @InjectRepository(Channel) private readonly channelRepo: Repository, ) {} listByGuild(guildId: string) { return this.channelRepo.find({ where: { guildId }, order: { createdAt: 'ASC' }, take: 200, }); } listAll() { return this.channelRepo.find({ order: { createdAt: 'ASC' }, take: 200, }); } create(input: Partial) { const channel = this.channelRepo.create({ guildId: String(input.guildId ?? ''), name: String(input.name ?? ''), kind: input.kind === 'announcement' ? 'announcement' : 'text', isPrivate: Boolean(input.isPrivate), lastSeq: 0, }); return this.channelRepo.save(channel); } }