Skip to content

Commit

Permalink
FIxed some typos
Browse files Browse the repository at this point in the history
  • Loading branch information
Nil2000 committed Sep 14, 2024
1 parent 8078c20 commit 3a34103
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions apps/api/src/common/slug-generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('generateEntitySlug', () => {
it('should convert name to slug format', () => {
expect(generateSlugName('Hello World')).toBe('hello-world')
expect(generateSlugName('Entity with 123')).toBe('entity-with-123')
expect(generateSlugName('Special #Name!')).toBe('special--name-')
expect(generateSlugName('Special #Name!')).toBe('special-name')
})
})

Expand Down Expand Up @@ -106,10 +106,10 @@ describe('generateEntitySlug', () => {
})

it('should generate a unique slug for API_KEY', async () => {
prisma.apiKey.findMany.mockResolvedValue([{ slug: 'api--key-09' }])
prisma.apiKey.findMany.mockResolvedValue([{ slug: 'api-key-09' }])

const slug = await generateEntitySlug('Api @Key', 'API_KEY', prisma)
expect(slug).toBe('api--key-0a')
expect(slug).toBe('api-key-0a')
})
})
})
28 changes: 14 additions & 14 deletions apps/api/src/common/slug-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { PrismaService } from '@/prisma/prisma.service'
import { Workspace } from '@prisma/client'

export const incrementSlugSuffix = (
foundSlug: string,
existingSlug: string,
baseSlug: string
): string => {
const charset = '0123456789abcdefghijklmnopqrstuvwxyz'

let suffix = ''

if (foundSlug) {
suffix = foundSlug.substring(baseSlug.length + 1)
if (existingSlug) {
suffix = existingSlug.substring(baseSlug.length + 1)
}

if (!suffix) {
Expand Down Expand Up @@ -61,7 +61,7 @@ export const generateSlugName = (name: string): string => {
const hyphenatedName = lowerCaseName.replace(/\s+/g, '-')

// Replace all non-alphanumeric characters with hyphens
const alphanumericName = hyphenatedName.replace(/[^a-zA-Z0-9-]/g, '-')
const alphanumericName = hyphenatedName.replace(/[^a-zA-Z0-9-]/g, '')

return alphanumericName
}
Expand Down Expand Up @@ -257,32 +257,32 @@ export default async function generateEntitySlug(
prisma: PrismaService
): Promise<string> {
const baseSlug = generateSlugName(name)
let foundSlug = ''
let existingSlug = ''
switch (entityType) {
case 'WORKSPACE_ROLE':
foundSlug = await getWorkspaceRoleIfSlugExists(baseSlug, prisma)
existingSlug = await getWorkspaceRoleIfSlugExists(baseSlug, prisma)
break
case 'WORKSPACE':
foundSlug = await getWorkspaceSlugExists(baseSlug, prisma)
existingSlug = await getWorkspaceSlugExists(baseSlug, prisma)
break
case 'PROJECT':
foundSlug = await getProjectSlugExists(baseSlug, prisma)
existingSlug = await getProjectSlugExists(baseSlug, prisma)
break
case 'VARIABLE':
foundSlug = await getVariableSlugExists(baseSlug, prisma)
existingSlug = await getVariableSlugExists(baseSlug, prisma)
break
case 'SECRET':
foundSlug = await getSecretSlugExists(baseSlug, prisma)
existingSlug = await getSecretSlugExists(baseSlug, prisma)
break
case 'INTEGRATION':
foundSlug = await getIntegrationSlugExists(baseSlug, prisma)
existingSlug = await getIntegrationSlugExists(baseSlug, prisma)
break
case 'ENVIRONMENT':
foundSlug = await getEnvironmentSlugExists(baseSlug, prisma)
existingSlug = await getEnvironmentSlugExists(baseSlug, prisma)
break
case 'API_KEY':
foundSlug = await getApiKeySlugExists(baseSlug, prisma)
existingSlug = await getApiKeySlugExists(baseSlug, prisma)
break
}
return incrementSlugSuffix(foundSlug, baseSlug)
return incrementSlugSuffix(existingSlug, baseSlug)
}

0 comments on commit 3a34103

Please sign in to comment.