This commit is contained in:
Philipinho
2024-05-19 09:06:06 +01:00
parent 9c7c2f1163
commit 6287f41ef6
6 changed files with 22 additions and 20 deletions

View File

@ -10,7 +10,8 @@ export class CreateSpaceDto {
@IsString()
description?: string;
@IsOptional()
@MinLength(4)
@MaxLength(64)
@IsString()
slug?: string;
slug: string;
}

View File

@ -10,8 +10,6 @@ import { KyselyTransaction } from '@docmost/db/types/kysely.types';
import { Space } from '@docmost/db/types/entity.types';
import { PaginationResult } from '@docmost/db/pagination/pagination';
import { UpdateSpaceDto } from '../dto/update-space.dto';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { slugify } = require('fix-esm').require('@sindresorhus/slugify');
@Injectable()
export class SpaceService {
@ -23,14 +21,14 @@ export class SpaceService {
createSpaceDto: CreateSpaceDto,
trx?: KyselyTransaction,
): Promise<Space> {
const slug = slugify(
createSpaceDto?.slug?.toLowerCase() ?? createSpaceDto.name.toLowerCase(),
const slugExists = await this.spaceRepo.slugExists(
createSpaceDto.slug,
workspaceId,
trx,
);
const slugExists = await this.spaceRepo.slugExists(slug, workspaceId, trx);
if (slugExists) {
throw new BadRequestException(
'Slug exist. Please use a unique space slug',
'Slug exists. Please use a unique space slug',
);
}
@ -40,7 +38,7 @@ export class SpaceService {
description: createSpaceDto.description ?? '',
creatorId: userId,
workspaceId: workspaceId,
slug: slug,
slug: createSpaceDto.slug,
},
trx,
);

View File

@ -104,6 +104,7 @@ export class WorkspaceService {
// create default space
const spaceInfo: CreateSpaceDto = {
name: 'General',
slug: 'general',
};
const createdSpace = await this.spaceService.create(