fix(guild): validate channel create payload and return 400

This commit is contained in:
nav
2026-05-14 16:49:56 +00:00
parent 9ad6ccaa3d
commit 78d2179e8c

View File

@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { BadRequestException, Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Channel } from '../entities/channel.entity';
@@ -26,9 +26,14 @@ export class ChannelsService {
}
create(input: Partial<Channel>) {
const guildId = String(input.guildId ?? '').trim();
const name = String(input.name ?? '').trim();
if (!guildId) throw new BadRequestException('guildId is required');
if (!name) throw new BadRequestException('name is required');
const channel = this.channelRepo.create({
guildId: String(input.guildId ?? ''),
name: String(input.name ?? ''),
guildId,
name,
kind: input.kind === 'announcement' ? 'announcement' : 'text',
isPrivate: Boolean(input.isPrivate),
lastSeq: 0,