Type useTemplate as bool
This commit is contained in:
parent
5fe2a1d33e
commit
77c4140e76
|
@ -29,7 +29,7 @@ exports.createApp = async apiKey => {
|
|||
const body = {
|
||||
name,
|
||||
url: `/${name}`,
|
||||
useTemplate: "true",
|
||||
useTemplate: true,
|
||||
templateKey: "app/school-admin-panel",
|
||||
templateName: "School Admin Panel",
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ import {
|
|||
FieldType,
|
||||
BBReferenceFieldSubType,
|
||||
Row,
|
||||
BBRequest,
|
||||
} from "@budibase/types"
|
||||
import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts"
|
||||
import sdk from "../../sdk"
|
||||
|
@ -127,7 +128,7 @@ function checkAppName(
|
|||
}
|
||||
|
||||
interface AppTemplate {
|
||||
useTemplate?: string
|
||||
useTemplate?: boolean
|
||||
file?: {
|
||||
type?: string
|
||||
path: string
|
||||
|
@ -151,7 +152,7 @@ async function createInstance(appId: string, template: AppTemplate) {
|
|||
await createRoutingView()
|
||||
await createAllSearchIndex()
|
||||
|
||||
if (template && template.useTemplate === "true") {
|
||||
if (template && template.useTemplate) {
|
||||
await sdk.backups.importApp(appId, db, template)
|
||||
} else {
|
||||
// create the users table
|
||||
|
@ -428,21 +429,21 @@ async function updateUserColumns(
|
|||
})
|
||||
}
|
||||
|
||||
async function creationEvents(request: any, app: App) {
|
||||
async function creationEvents(request: BBRequest<CreateAppRequest>, app: App) {
|
||||
let creationFns: ((app: App) => Promise<void>)[] = []
|
||||
|
||||
const body = request.body
|
||||
if (body.useTemplate === "true") {
|
||||
const { useTemplate, templateKey, file } = request.body
|
||||
if (useTemplate) {
|
||||
// from template
|
||||
if (body.templateKey && body.templateKey !== "undefined") {
|
||||
creationFns.push(a => events.app.templateImported(a, body.templateKey))
|
||||
if (templateKey && templateKey !== "undefined") {
|
||||
creationFns.push(a => events.app.templateImported(a, templateKey))
|
||||
}
|
||||
// from file
|
||||
else if (request.files?.templateFile) {
|
||||
creationFns.push(a => events.app.fileImported(a))
|
||||
}
|
||||
// from server file path
|
||||
else if (request.body.file) {
|
||||
else if (file) {
|
||||
// explicitly pass in the newly created app id
|
||||
creationFns.push(a => events.app.duplicated(a, app.appId))
|
||||
}
|
||||
|
@ -452,16 +453,14 @@ async function creationEvents(request: any, app: App) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!request.duplicate) {
|
||||
creationFns.push(a => events.app.created(a))
|
||||
}
|
||||
creationFns.push(a => events.app.created(a))
|
||||
|
||||
for (let fn of creationFns) {
|
||||
await fn(app)
|
||||
}
|
||||
}
|
||||
|
||||
async function appPostCreate(ctx: UserCtx, app: App) {
|
||||
async function appPostCreate(ctx: UserCtx<CreateAppRequest, App>, app: App) {
|
||||
const tenantId = tenancy.getTenantId()
|
||||
await migrations.backPopulateMigrations({
|
||||
type: MigrationType.APP,
|
||||
|
@ -472,7 +471,7 @@ async function appPostCreate(ctx: UserCtx, app: App) {
|
|||
await creationEvents(ctx.request, app)
|
||||
|
||||
// app import, template creation and duplication
|
||||
if (ctx.request.body.useTemplate === "true") {
|
||||
if (ctx.request.body.useTemplate) {
|
||||
const { rows } = await getUniqueRows([app.appId])
|
||||
const rowCount = rows ? rows.length : 0
|
||||
if (rowCount) {
|
||||
|
@ -742,7 +741,7 @@ export async function duplicateApp(
|
|||
const createRequestBody: CreateAppRequest = {
|
||||
name: appName,
|
||||
url: possibleUrl,
|
||||
useTemplate: "true",
|
||||
useTemplate: true,
|
||||
// The app export path
|
||||
file: {
|
||||
path: tmpPath,
|
||||
|
|
|
@ -139,7 +139,7 @@ describe("/applications", () => {
|
|||
it("creates app from template", async () => {
|
||||
const app = await config.api.application.create({
|
||||
name: utils.newid(),
|
||||
useTemplate: "true",
|
||||
useTemplate: true,
|
||||
templateKey: "test",
|
||||
})
|
||||
expect(app._id).toBeDefined()
|
||||
|
@ -150,7 +150,7 @@ describe("/applications", () => {
|
|||
it("creates app from file", async () => {
|
||||
const app = await config.api.application.create({
|
||||
name: utils.newid(),
|
||||
useTemplate: "true",
|
||||
useTemplate: true,
|
||||
fileToImport: "src/api/routes/tests/data/export.txt",
|
||||
})
|
||||
expect(app._id).toBeDefined()
|
||||
|
@ -170,7 +170,7 @@ describe("/applications", () => {
|
|||
it("migrates navigation settings from old apps", async () => {
|
||||
const app = await config.api.application.create({
|
||||
name: utils.newid(),
|
||||
useTemplate: "true",
|
||||
useTemplate: true,
|
||||
fileToImport: "src/api/routes/tests/data/old-app.txt",
|
||||
})
|
||||
expect(app._id).toBeDefined()
|
||||
|
|
|
@ -95,7 +95,7 @@ describe("/templates", () => {
|
|||
const app = await config.api.application.create({
|
||||
name,
|
||||
url,
|
||||
useTemplate: "true",
|
||||
useTemplate: true,
|
||||
templateName: "Agency Client Portal",
|
||||
templateKey: "app/agency-client-portal",
|
||||
})
|
||||
|
|
|
@ -4,7 +4,7 @@ import type { Layout, App, Screen } from "../../documents"
|
|||
export interface CreateAppRequest {
|
||||
name: string
|
||||
url?: string
|
||||
useTemplate?: string
|
||||
useTemplate?: boolean
|
||||
templateName?: string
|
||||
templateKey?: string
|
||||
fileToImport?: string
|
||||
|
|
Loading…
Reference in New Issue