From 78d2179e8c9c6b2940e04cf33e72295220be7578 Mon Sep 17 00:00:00 2001 From: nav Date: Thu, 14 May 2026 16:49:56 +0000 Subject: [PATCH] fix(guild): validate channel create payload and return 400 --- src/channels/channels.service.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/channels/channels.service.ts b/src/channels/channels.service.ts index 169225e..48d2456 100644 --- a/src/channels/channels.service.ts +++ b/src/channels/channels.service.ts @@ -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) { + 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,