generate safe id for org
This commit is contained in:
@@ -2,7 +2,10 @@ import { slug } from '@openpanel/common';
|
||||
|
||||
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);
|
||||
if (!db[tableName]) {
|
||||
throw new Error('Table does not exists');
|
||||
|
||||
@@ -19,7 +19,7 @@ async function createOrGetOrganization(
|
||||
if (input.organization) {
|
||||
return db.organization.create({
|
||||
data: {
|
||||
id: slug(input.organization),
|
||||
id: await getId('organization', input.organization),
|
||||
name: input.organization,
|
||||
createdByUserId: userId,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user