Compare commits
1 Commits
774dff11ba
...
605d3ac092
| Author | SHA1 | Date | |
|---|---|---|---|
| 605d3ac092 |
@@ -24,6 +24,7 @@ export class ChannelsController {
|
||||
guildId: body.guildId as string | undefined,
|
||||
name: body.name as string | undefined,
|
||||
kind: body.kind as string | undefined,
|
||||
xType: body.xType as string | undefined,
|
||||
isPublic: Boolean(body.isPublic),
|
||||
memberUserIds: Array.isArray(body.memberUserIds) ? (body.memberUserIds as string[]) : [],
|
||||
},
|
||||
|
||||
@@ -4,10 +4,14 @@ import { In, Repository } from 'typeorm';
|
||||
import { Channel } from '../entities/channel.entity';
|
||||
import { ChannelMember } from '../entities/channel-member.entity';
|
||||
|
||||
const X_TYPES = ['general', 'work', 'report', 'discuss', 'triage', 'custom'] as const;
|
||||
type XType = (typeof X_TYPES)[number];
|
||||
|
||||
type CreateChannelInput = {
|
||||
guildId?: string;
|
||||
name?: string;
|
||||
kind?: string;
|
||||
xType?: string;
|
||||
isPublic?: boolean;
|
||||
memberUserIds?: string[];
|
||||
};
|
||||
@@ -44,14 +48,20 @@ export class ChannelsService {
|
||||
async create(input: CreateChannelInput, creatorUserId: string) {
|
||||
const guildId = String(input.guildId ?? '').trim();
|
||||
const name = String(input.name ?? '').trim();
|
||||
const xType = String(input.xType ?? '').trim() as XType;
|
||||
if (!guildId) throw new BadRequestException('guildId is required');
|
||||
if (!name) throw new BadRequestException('name is required');
|
||||
if (!creatorUserId) throw new BadRequestException('creator is required');
|
||||
if (!input.xType) throw new BadRequestException('xType is required');
|
||||
if (!X_TYPES.includes(xType)) {
|
||||
throw new BadRequestException(`xType must be one of: ${X_TYPES.join(', ')}`);
|
||||
}
|
||||
|
||||
const channel = await this.channelRepo.save(
|
||||
this.channelRepo.create({
|
||||
guildId,
|
||||
name,
|
||||
xType,
|
||||
kind: input.kind === 'announcement' ? 'announcement' : 'text',
|
||||
isPrivate: !input.isPublic,
|
||||
isPublic: Boolean(input.isPublic),
|
||||
|
||||
@@ -13,6 +13,13 @@ export class Channel {
|
||||
@Column({ type: 'varchar', length: 120 })
|
||||
name!: string;
|
||||
|
||||
@Column({
|
||||
name: 'x_type',
|
||||
type: 'enum',
|
||||
enum: ['general', 'work', 'report', 'discuss', 'triage', 'custom'],
|
||||
})
|
||||
xType!: 'general' | 'work' | 'report' | 'discuss' | 'triage' | 'custom';
|
||||
|
||||
@Column({ type: 'varchar', length: 16, default: 'text' })
|
||||
kind!: 'text' | 'announcement';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user