2020-04-08 18:00:27 +02:00
|
|
|
import { newModel } from "../src/schema/models.mjs"
|
|
|
|
import { newView } from "../src/schema/views.mjs"
|
|
|
|
import { getNewField } from "../src/schema/fields.mjs"
|
|
|
|
import { fullSchema } from "../src/schema/fullSchema.mjs"
|
2020-04-09 17:42:55 +02:00
|
|
|
import { commonRecordValidationRules } from "../src/records/recordValidationRules.mjs"
|
2020-04-08 18:00:27 +02:00
|
|
|
|
|
|
|
export function testSchema() {
|
|
|
|
const addFieldToModel = (model, { type, name }) => {
|
|
|
|
const field = getNewField(type || "string")
|
|
|
|
field.name = name
|
|
|
|
model.fields.push(field)
|
|
|
|
}
|
|
|
|
|
|
|
|
const contactModel = newModel()
|
|
|
|
contactModel.name = "Contact"
|
|
|
|
contactModel.primaryField = "Name"
|
|
|
|
|
|
|
|
addFieldToModel(contactModel, { name: "Name" })
|
|
|
|
addFieldToModel(contactModel, { name: "Is Active", type: "bool" })
|
|
|
|
addFieldToModel(contactModel, { name: "Created", type: "datetime" })
|
2020-04-09 17:42:55 +02:00
|
|
|
addFieldToModel(contactModel, { name: "Status", type: "string" })
|
2020-04-08 18:00:27 +02:00
|
|
|
|
2020-04-09 11:13:19 +02:00
|
|
|
contactModel.validationRules.push(
|
2020-04-09 17:42:55 +02:00
|
|
|
commonRecordValidationRules.fieldNotEmpty("Name")
|
2020-04-09 11:13:19 +02:00
|
|
|
)
|
|
|
|
|
2020-04-08 18:00:27 +02:00
|
|
|
const activeContactsView = newView(contactModel.id)
|
|
|
|
activeContactsView.name = "Active Contacts"
|
|
|
|
activeContactsView.map = "if (doc['Is Active']) emit(doc.Name, doc)"
|
|
|
|
|
|
|
|
const dealModel = newModel()
|
|
|
|
dealModel.name = "Deal"
|
|
|
|
addFieldToModel(dealModel, { name: "Name" })
|
|
|
|
addFieldToModel(dealModel, { name: "Estimated Value", type: "number" })
|
|
|
|
addFieldToModel(dealModel, { name: "Contact", type: "link" })
|
|
|
|
|
|
|
|
return fullSchema([contactModel, dealModel], [activeContactsView])
|
|
|
|
}
|