23 lines
628 B
TypeScript
23 lines
628 B
TypeScript
import { DATASQUIREL_LoggedInUser, UserType } from "../../../types";
|
|
|
|
type Param = {
|
|
user?: DATASQUIREL_LoggedInUser | UserType;
|
|
userId?: string | number | null;
|
|
dbSlug?: string;
|
|
};
|
|
|
|
export default function grabUserDbFullName({ dbSlug, user, userId }: Param) {
|
|
const finalUserId = user?.id || userId;
|
|
|
|
if (!finalUserId || !dbSlug)
|
|
throw new Error(
|
|
`Couldn't grab full DB name. Missing parameters finalUserId || dbSlug`
|
|
);
|
|
|
|
if (dbSlug.match(/[^a-zA-Z0-9-_]/)) {
|
|
throw new Error(`Invalid Database slug`);
|
|
}
|
|
|
|
return `datasquirel_user_${finalUserId}_${dbSlug}`;
|
|
}
|