mirror of
https://github.com/fosrl/pangolin.git
synced 2026-09-11 13:31:27 +02:00
🗃️ create DB models
This commit is contained in:
@@ -205,7 +205,12 @@ export enum ActionsEnum {
|
|||||||
deleteVirtualApiKey = "deleteVirtualApiKey",
|
deleteVirtualApiKey = "deleteVirtualApiKey",
|
||||||
getVirtualApiKey = "getVirtualApiKey",
|
getVirtualApiKey = "getVirtualApiKey",
|
||||||
listVirtualApiKeys = "listVirtualApiKeys",
|
listVirtualApiKeys = "listVirtualApiKeys",
|
||||||
updateVirtualApiKey = "updateVirtualApiKey"
|
updateVirtualApiKey = "updateVirtualApiKey",
|
||||||
|
createRedirect = "createRedirect",
|
||||||
|
deleteRedirect = "deleteRedirect",
|
||||||
|
getRedirect = "getRedirect",
|
||||||
|
listRedirects = "listRedirects",
|
||||||
|
updateRedirect = "updateRedirect"
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function checkUserActionPermission(
|
export async function checkUserActionPermission(
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
aiProviders,
|
aiProviders,
|
||||||
clients,
|
clients,
|
||||||
db,
|
db,
|
||||||
|
redirects,
|
||||||
resourcePolicies,
|
resourcePolicies,
|
||||||
resources,
|
resources,
|
||||||
siteResources
|
siteResources
|
||||||
@@ -140,6 +141,30 @@ export async function getUniqueProviderName(orgId: string): Promise<string> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getUniqueRedirectName(orgId: string): Promise<string> {
|
||||||
|
let loops = 0;
|
||||||
|
while (true) {
|
||||||
|
if (loops > 100) {
|
||||||
|
throw new Error("Could not generate a unique name");
|
||||||
|
}
|
||||||
|
|
||||||
|
const name = generateName();
|
||||||
|
|
||||||
|
const redirectCount = await db
|
||||||
|
.select({
|
||||||
|
niceId: redirects.niceId,
|
||||||
|
orgId: redirects.orgId
|
||||||
|
})
|
||||||
|
.from(redirects)
|
||||||
|
.where(and(eq(redirects.niceId, name), eq(redirects.orgId, orgId)));
|
||||||
|
|
||||||
|
if (redirectCount.length === 0) {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
loops++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function getUniqueResourcePolicyName(
|
export async function getUniqueResourcePolicyName(
|
||||||
orgId: string
|
orgId: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ export const redirects = pgTable("redirects", {
|
|||||||
resourceId: integer("resourceId").references(() => resources.resourceId, {
|
resourceId: integer("resourceId").references(() => resources.resourceId, {
|
||||||
onDelete: "cascade"
|
onDelete: "cascade"
|
||||||
}),
|
}),
|
||||||
domainId: integer("domainId").references(() => domains.domainId, {
|
domainId: varchar("domainId").references(() => domains.domainId, {
|
||||||
onDelete: "cascade"
|
onDelete: "cascade"
|
||||||
}),
|
}),
|
||||||
niceId: text("niceId").notNull(),
|
niceId: text("niceId").notNull(),
|
||||||
@@ -2086,6 +2086,7 @@ export type ResourcePolicy = InferSelectModel<typeof resourcePolicies>;
|
|||||||
export type RolePolicy = InferSelectModel<typeof rolePolicies>;
|
export type RolePolicy = InferSelectModel<typeof rolePolicies>;
|
||||||
export type UserPolicy = InferSelectModel<typeof userPolicies>;
|
export type UserPolicy = InferSelectModel<typeof userPolicies>;
|
||||||
export type ResourcePolicyRule = InferSelectModel<typeof resourcePolicyRules>;
|
export type ResourcePolicyRule = InferSelectModel<typeof resourcePolicyRules>;
|
||||||
|
export type Redirect = InferSelectModel<typeof redirects>;
|
||||||
export type AiProvider = InferSelectModel<typeof aiProviders>;
|
export type AiProvider = InferSelectModel<typeof aiProviders>;
|
||||||
export type AiModel = InferSelectModel<typeof aiModels>;
|
export type AiModel = InferSelectModel<typeof aiModels>;
|
||||||
export type AiBudget = InferSelectModel<typeof aiBudgets>;
|
export type AiBudget = InferSelectModel<typeof aiBudgets>;
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ export const redirects = sqliteTable("redirects", {
|
|||||||
resourceId: integer("resourceId").references(() => resources.resourceId, {
|
resourceId: integer("resourceId").references(() => resources.resourceId, {
|
||||||
onDelete: "cascade"
|
onDelete: "cascade"
|
||||||
}),
|
}),
|
||||||
domainId: integer("domainId").references(() => domains.domainId, {
|
domainId: text("domainId").references(() => domains.domainId, {
|
||||||
onDelete: "cascade"
|
onDelete: "cascade"
|
||||||
}),
|
}),
|
||||||
niceId: text("niceId").notNull(),
|
niceId: text("niceId").notNull(),
|
||||||
@@ -2127,6 +2127,7 @@ export type ResourcePolicyHeaderAuth = InferSelectModel<
|
|||||||
>;
|
>;
|
||||||
export type RolePolicy = InferSelectModel<typeof rolePolicies>;
|
export type RolePolicy = InferSelectModel<typeof rolePolicies>;
|
||||||
export type UserPolicy = InferSelectModel<typeof userPolicies>;
|
export type UserPolicy = InferSelectModel<typeof userPolicies>;
|
||||||
|
export type Redirect = InferSelectModel<typeof redirects>;
|
||||||
export type AiProvider = InferSelectModel<typeof aiProviders>;
|
export type AiProvider = InferSelectModel<typeof aiProviders>;
|
||||||
export type AiModel = InferSelectModel<typeof aiModels>;
|
export type AiModel = InferSelectModel<typeof aiModels>;
|
||||||
export type AiBudget = InferSelectModel<typeof aiBudgets>;
|
export type AiBudget = InferSelectModel<typeof aiBudgets>;
|
||||||
|
|||||||
+2
-1
@@ -32,7 +32,8 @@ export enum OpenAPITags {
|
|||||||
AiProvider = "AI Provider",
|
AiProvider = "AI Provider",
|
||||||
AiModel = "AI Model",
|
AiModel = "AI Model",
|
||||||
AiBudget = "AI Budget",
|
AiBudget = "AI Budget",
|
||||||
VirtualApiKey = "Virtual API Key"
|
VirtualApiKey = "Virtual API Key",
|
||||||
|
Redirect = "Redirect"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Order here controls the order tags are displayed in Swagger UI
|
// Order here controls the order tags are displayed in Swagger UI
|
||||||
|
|||||||
Reference in New Issue
Block a user