fix(guild): validate channel create payload and return 400
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { Channel } from '../entities/channel.entity';
|
import { Channel } from '../entities/channel.entity';
|
||||||
@@ -26,9 +26,14 @@ export class ChannelsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
create(input: Partial<Channel>) {
|
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({
|
const channel = this.channelRepo.create({
|
||||||
guildId: String(input.guildId ?? ''),
|
guildId,
|
||||||
name: String(input.name ?? ''),
|
name,
|
||||||
kind: input.kind === 'announcement' ? 'announcement' : 'text',
|
kind: input.kind === 'announcement' ? 'announcement' : 'text',
|
||||||
isPrivate: Boolean(input.isPrivate),
|
isPrivate: Boolean(input.isPrivate),
|
||||||
lastSeq: 0,
|
lastSeq: 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user