148 lines
4.5 KiB
JavaScript
148 lines
4.5 KiB
JavaScript
/**
|
|
* Example seed data for Account object with UI metadata
|
|
* Run this after migrations to add UI metadata to existing Account fields
|
|
*/
|
|
|
|
exports.seed = async function(knex) {
|
|
// Get the Account object
|
|
const accountObj = await knex('object_definitions')
|
|
.where({ apiName: 'Account' })
|
|
.first();
|
|
|
|
if (!accountObj) {
|
|
console.log('Account object not found. Please run migrations first.');
|
|
return;
|
|
}
|
|
|
|
console.log(`Found Account object with ID: ${accountObj.id}`);
|
|
|
|
// Update existing Account fields with UI metadata
|
|
const fieldsToUpdate = [
|
|
{
|
|
apiName: 'name',
|
|
ui_metadata: JSON.stringify({
|
|
fieldType: 'TEXT',
|
|
placeholder: 'Enter account name',
|
|
helpText: 'The name of the organization or company',
|
|
showOnList: true,
|
|
showOnDetail: true,
|
|
showOnEdit: true,
|
|
sortable: true,
|
|
section: 'basic',
|
|
sectionLabel: 'Basic Information',
|
|
sectionOrder: 1,
|
|
validationRules: [
|
|
{ type: 'required', message: 'Account name is required' },
|
|
{ type: 'minLength', value: 2, message: 'Account name must be at least 2 characters' },
|
|
{ type: 'maxLength', value: 255, message: 'Account name cannot exceed 255 characters' }
|
|
]
|
|
})
|
|
},
|
|
{
|
|
apiName: 'website',
|
|
ui_metadata: JSON.stringify({
|
|
fieldType: 'URL',
|
|
placeholder: 'https://www.example.com',
|
|
helpText: 'Company website URL',
|
|
showOnList: true,
|
|
showOnDetail: true,
|
|
showOnEdit: true,
|
|
sortable: true,
|
|
section: 'basic',
|
|
sectionLabel: 'Basic Information',
|
|
sectionOrder: 1,
|
|
validationRules: [
|
|
{ type: 'url', message: 'Please enter a valid URL' }
|
|
]
|
|
})
|
|
},
|
|
{
|
|
apiName: 'phone',
|
|
ui_metadata: JSON.stringify({
|
|
fieldType: 'TEXT',
|
|
placeholder: '+1 (555) 000-0000',
|
|
helpText: 'Primary phone number',
|
|
showOnList: true,
|
|
showOnDetail: true,
|
|
showOnEdit: true,
|
|
sortable: false,
|
|
section: 'contact',
|
|
sectionLabel: 'Contact Information',
|
|
sectionOrder: 2,
|
|
validationRules: [
|
|
{ type: 'pattern', value: '^\\+?[0-9\\s\\-\\(\\)]+$', message: 'Please enter a valid phone number' }
|
|
]
|
|
})
|
|
},
|
|
{
|
|
apiName: 'industry',
|
|
ui_metadata: JSON.stringify({
|
|
fieldType: 'SELECT',
|
|
placeholder: 'Select industry',
|
|
helpText: 'The primary industry this account operates in',
|
|
showOnList: true,
|
|
showOnDetail: true,
|
|
showOnEdit: true,
|
|
sortable: true,
|
|
section: 'details',
|
|
sectionLabel: 'Account Details',
|
|
sectionOrder: 3,
|
|
options: [
|
|
{ value: 'technology', label: 'Technology' },
|
|
{ value: 'finance', label: 'Finance' },
|
|
{ value: 'healthcare', label: 'Healthcare' },
|
|
{ value: 'manufacturing', label: 'Manufacturing' },
|
|
{ value: 'retail', label: 'Retail' },
|
|
{ value: 'education', label: 'Education' },
|
|
{ value: 'government', label: 'Government' },
|
|
{ value: 'nonprofit', label: 'Non-Profit' },
|
|
{ value: 'other', label: 'Other' }
|
|
]
|
|
})
|
|
},
|
|
{
|
|
apiName: 'ownerId',
|
|
ui_metadata: JSON.stringify({
|
|
fieldType: 'SELECT',
|
|
placeholder: 'Select owner',
|
|
helpText: 'The user who owns this account',
|
|
showOnList: true,
|
|
showOnDetail: true,
|
|
showOnEdit: true,
|
|
sortable: true,
|
|
section: 'system',
|
|
sectionLabel: 'System Information',
|
|
sectionOrder: 4,
|
|
// This would be dynamically populated from the users table
|
|
// For now, providing static structure
|
|
isReference: true,
|
|
referenceObject: 'User',
|
|
referenceDisplayField: 'name'
|
|
})
|
|
}
|
|
];
|
|
|
|
// Update each field with UI metadata
|
|
for (const fieldUpdate of fieldsToUpdate) {
|
|
const result = await knex('field_definitions')
|
|
.where({
|
|
objectDefinitionId: accountObj.id,
|
|
apiName: fieldUpdate.apiName
|
|
})
|
|
.update({
|
|
ui_metadata: fieldUpdate.ui_metadata,
|
|
updated_at: knex.fn.now()
|
|
});
|
|
|
|
if (result > 0) {
|
|
console.log(`✓ Updated ${fieldUpdate.apiName} with UI metadata`);
|
|
} else {
|
|
console.log(`✗ Field ${fieldUpdate.apiName} not found`);
|
|
}
|
|
}
|
|
|
|
console.log('\n✅ Account fields UI metadata seed completed successfully!');
|
|
console.log('You can now fetch the Account object UI config via:');
|
|
console.log('GET /api/setup/objects/Account/ui-config');
|
|
};
|