Wrap sample data creation with custom error catching and move link generation out of main controller
This commit is contained in:
parent
8906a159c6
commit
bbd9f607cd
|
@ -198,6 +198,19 @@ async function addSampleDataScreen() {
|
||||||
await db.put(screen)
|
await db.put(screen)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addSampleDataNavLinks(app: App) {
|
||||||
|
if (app.navigation) {
|
||||||
|
app.navigation.links = [
|
||||||
|
{
|
||||||
|
text: "Inventory",
|
||||||
|
url: "/inventory",
|
||||||
|
type: "link",
|
||||||
|
roleId: roles.BUILTIN_ROLE_IDS.BASIC,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const addSampleData = async (
|
export const addSampleData = async (
|
||||||
ctx: UserCtx<void, AddAppSampleDataResponse>
|
ctx: UserCtx<void, AddAppSampleDataResponse>
|
||||||
) => {
|
) => {
|
||||||
|
@ -311,18 +324,6 @@ async function performAppCreate(
|
||||||
await updateUserColumns(appId, db, ctx.user._id!)
|
await updateUserColumns(appId, db, ctx.user._id!)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add link to sample data page if required
|
|
||||||
const newLinks = addSampleData
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
text: "Inventory",
|
|
||||||
url: "/inventory",
|
|
||||||
type: "link",
|
|
||||||
roleId: roles.BUILTIN_ROLE_IDS.BASIC,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: []
|
|
||||||
|
|
||||||
const newApplication: App = {
|
const newApplication: App = {
|
||||||
_id: DocumentType.APP_METADATA,
|
_id: DocumentType.APP_METADATA,
|
||||||
_rev: undefined,
|
_rev: undefined,
|
||||||
|
@ -344,7 +345,7 @@ async function performAppCreate(
|
||||||
navWidth: "Large",
|
navWidth: "Large",
|
||||||
navBackground: "var(--spectrum-global-color-static-blue-800)",
|
navBackground: "var(--spectrum-global-color-static-blue-800)",
|
||||||
navTextColor: "var(--spectrum-global-color-static-white)",
|
navTextColor: "var(--spectrum-global-color-static-white)",
|
||||||
links: newLinks,
|
links: [],
|
||||||
},
|
},
|
||||||
theme: DefaultAppTheme,
|
theme: DefaultAppTheme,
|
||||||
customTheme: {
|
customTheme: {
|
||||||
|
@ -358,6 +359,10 @@ async function performAppCreate(
|
||||||
creationVersion: undefined,
|
creationVersion: undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (addSampleData) {
|
||||||
|
addSampleDataNavLinks(newApplication)
|
||||||
|
}
|
||||||
|
|
||||||
if (!isImport) {
|
if (!isImport) {
|
||||||
newApplication.creationVersion = envCore.VERSION
|
newApplication.creationVersion = envCore.VERSION
|
||||||
}
|
}
|
||||||
|
@ -406,8 +411,12 @@ async function performAppCreate(
|
||||||
|
|
||||||
// Add sample datasource and example screen for non-templates/non-imports
|
// Add sample datasource and example screen for non-templates/non-imports
|
||||||
if (addSampleData) {
|
if (addSampleData) {
|
||||||
await addSampleDataDocs()
|
try {
|
||||||
await addSampleDataScreen()
|
await addSampleDataDocs()
|
||||||
|
await addSampleDataScreen()
|
||||||
|
} catch (err) {
|
||||||
|
ctx.throw(400, "App created, but failed to add sample data")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const latestMigrationId = appMigrations.getLatestEnabledMigrationId()
|
const latestMigrationId = appMigrations.getLatestEnabledMigrationId()
|
||||||
|
|
Loading…
Reference in New Issue