Renaming new type.

This commit is contained in:
mike12345567 2024-12-06 10:50:39 +00:00
parent 165ff4e768
commit a3df34b350
4 changed files with 34 additions and 32 deletions

View File

@ -3,7 +3,7 @@ import { downloadTemplate as dlTemplate } from "../../utilities/fileSystem"
import env from "../../environment"
import {
DownloadTemplateResponse,
FetchTemplateResponse,
FetchGlobalTemplateResponse,
UserCtx,
} from "@budibase/types"
@ -11,7 +11,7 @@ import {
const DEFAULT_TEMPLATES_BUCKET =
"prod-budi-templates.s3-eu-west-1.amazonaws.com"
export async function fetch(ctx: UserCtx<void, FetchTemplateResponse>) {
export async function fetch(ctx: UserCtx<void, FetchGlobalTemplateResponse>) {
let type = env.TEMPLATE_REPOSITORY
let response,
error = false

View File

@ -1,30 +1,30 @@
import { Document, Template } from "../../../documents"
import { Template } from "../../../documents"
export interface TemplateDefinition {
export interface GlobalTemplateDefinition {
name: string
description: string
category: string
}
export interface TemplateBinding {
export interface GlobalTemplateBinding {
name: string
description: string
}
export interface FetchTemplateDefinitionResponse {
info: Record<string, TemplateDefinition>
bindings: Record<string, TemplateBinding[]>
export interface FetchGlobalTemplateDefinitionResponse {
info: Record<string, GlobalTemplateDefinition>
bindings: Record<string, GlobalTemplateBinding[]>
}
export interface SaveTemplateRequest extends Template {}
export interface SaveTemplateResponse extends Template {}
export interface SaveGlobalTemplateRequest extends Template {}
export interface SaveGlobalTemplateResponse extends Template {}
export type FetchTemplateResponse = Template[]
export type FetchTemplateByTypeResponse = Template[]
export type FetchTemplateByOwnerIDResponse = Template[]
export type FetchGlobalTemplateResponse = Template[]
export type FetchGlobalTemplateByTypeResponse = Template[]
export type FetchGlobalTemplateByOwnerIDResponse = Template[]
export interface FindTemplateResponse extends Template {}
export interface FindGlobalTemplateResponse extends Template {}
export interface DeleteTemplateResponse {
export interface DeleteGlobalTemplateResponse {
message: string
}

View File

@ -6,21 +6,21 @@ import {
import { getTemplateByID, getTemplates } from "../../../constants/templates"
import { tenancy, db as dbCore } from "@budibase/backend-core"
import {
DeleteTemplateResponse,
FetchTemplateByOwnerIDResponse,
FetchTemplateByTypeResponse,
FetchTemplateDefinitionResponse,
FetchTemplateResponse,
FindTemplateResponse,
SaveTemplateRequest,
SaveTemplateResponse,
DeleteGlobalTemplateResponse,
FetchGlobalTemplateByOwnerIDResponse,
FetchGlobalTemplateByTypeResponse,
FetchGlobalTemplateDefinitionResponse,
FetchGlobalTemplateResponse,
FindGlobalTemplateResponse,
SaveGlobalTemplateRequest,
SaveGlobalTemplateResponse,
TemplateBinding,
TemplateDefinition,
UserCtx,
} from "@budibase/types"
export async function save(
ctx: UserCtx<SaveTemplateRequest, SaveTemplateResponse>
ctx: UserCtx<SaveGlobalTemplateRequest, SaveGlobalTemplateResponse>
) {
const db = tenancy.getGlobalDB()
let template = ctx.request.body
@ -39,7 +39,7 @@ export async function save(
}
export async function definitions(
ctx: UserCtx<void, FetchTemplateDefinitionResponse>
ctx: UserCtx<void, FetchGlobalTemplateDefinitionResponse>
) {
const bindings: Record<string, TemplateBinding[]> = {}
const info: Record<string, TemplateDefinition> = {}
@ -61,12 +61,12 @@ export async function definitions(
}
}
export async function fetch(ctx: UserCtx<void, FetchTemplateResponse>) {
export async function fetch(ctx: UserCtx<void, FetchGlobalTemplateResponse>) {
ctx.body = await getTemplates()
}
export async function fetchByType(
ctx: UserCtx<void, FetchTemplateByTypeResponse>
ctx: UserCtx<void, FetchGlobalTemplateByTypeResponse>
) {
ctx.body = await getTemplates({
type: ctx.params.type,
@ -74,7 +74,7 @@ export async function fetchByType(
}
export async function fetchByOwner(
ctx: UserCtx<void, FetchTemplateByOwnerIDResponse>
ctx: UserCtx<void, FetchGlobalTemplateByOwnerIDResponse>
) {
// @ts-ignore
ctx.body = await getTemplates({
@ -82,11 +82,13 @@ export async function fetchByOwner(
})
}
export async function find(ctx: UserCtx<void, FindTemplateResponse>) {
export async function find(ctx: UserCtx<void, FindGlobalTemplateResponse>) {
ctx.body = await getTemplateByID(ctx.params.id)
}
export async function destroy(ctx: UserCtx<void, DeleteTemplateResponse>) {
export async function destroy(
ctx: UserCtx<void, DeleteGlobalTemplateResponse>
) {
const db = tenancy.getGlobalDB()
await db.remove(ctx.params.id, ctx.params.rev)
ctx.body = { message: `Template ${ctx.params.id} deleted.` }

View File

@ -1,12 +1,12 @@
import env from "../environment"
import { constants, utils } from "@budibase/backend-core"
import { BBContext } from "@budibase/types"
import { UserCtx } from "@budibase/types"
/**
* This is a restricted endpoint in the cloud.
* Ensure that the correct API key has been supplied.
*/
export default async (ctx: BBContext, next: any) => {
export default async (ctx: UserCtx, next: any) => {
if (!env.SELF_HOSTED && !env.DISABLE_ACCOUNT_PORTAL) {
const apiKey = ctx.request.headers[constants.Header.API_KEY]
if (!apiKey) {