Budibase is an open-source low-code platform for creating internal apps in minutes. Supports PostgreSQL, MySQL, MSSQL, MongoDB, Rest API, Docker, K8s 🚀
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

52 lines
1.5 KiB

import { getMemoryTemplateApi, appFromTempalteApi } from "./specHelpers"
import { getFlattenedHierarchy } from "../src/templateApi/hierarchy"
import { initialiseData } from "../src/appInitialise/initialiseData"
export const setup = async store => {
const { templateApi } = await getMemoryTemplateApi(store)
const root = templateApi.getNewRootLevel()
const contact = templateApi.getNewModelTemplate(root, "contact", true)
contact.collectionName = "contacts"
const nameField = templateApi.getNewField("string")
nameField.name = "name"
const statusField = templateApi.getNewField("string")
statusField.name = "status"
templateApi.addField(contact, nameField)
templateApi.addField(contact, statusField)
const lead = templateApi.getNewModelTemplate(root, "lead", true)
lead.collectionName = "leads"
const deal = templateApi.getNewModelTemplate(contact, "deal", true)
deal.collectionName = "deals"
templateApi.addField(deal, { ...nameField })
templateApi.addField(deal, { ...statusField })
templateApi.addField(lead, { ...nameField })
getFlattenedHierarchy(root)
if (!store)
await initialiseData(templateApi._storeHandle, {
hierarchy: root,
actions: [],
triggers: [],
})
const app = await appFromTempalteApi(templateApi)
app.hierarchy = root
return {
root,
contact,
lead,
app,
deal,
templateApi,
store: templateApi._storeHandle,
all_contacts: root.indexes[0],
all_leads: root.indexes[1],
deals_for_contacts: contact.indexes[0],
}
}