generate safe id for org
This commit is contained in:
@@ -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');
|
||||||
|
|||||||
@@ -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,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user