generate safe id for org

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-06-17 09:07:40 +02:00
parent da02b1ebcf
commit f417c0f682
2 changed files with 5 additions and 2 deletions

View File

@@ -2,7 +2,10 @@ import { slug } from '@openpanel/common';
import { db } from '../prisma-client'; import { db } from '../prisma-client';
export async function getId(tableName: 'project' | 'dashboard', name: string) { export async function getId(
tableName: 'project' | 'dashboard' | 'organization',
name: string
) {
const newId = slug(name); const newId = slug(name);
if (!db[tableName]) { if (!db[tableName]) {
throw new Error('Table does not exists'); throw new Error('Table does not exists');

View File

@@ -19,7 +19,7 @@ async function createOrGetOrganization(
if (input.organization) { if (input.organization) {
return db.organization.create({ return db.organization.create({
data: { data: {
id: slug(input.organization), id: await getId('organization', input.organization),
name: input.organization, name: input.organization,
createdByUserId: userId, createdByUserId: userId,
}, },