Skip to content

Commit 395c2f6

Browse files
committed
Enhance CRM data model and seeding process; add latitude and longitude fields to Account and Contact objects, update seeding logic to rely on manifest configuration.
1 parent f101484 commit 395c2f6

4 files changed

Lines changed: 117 additions & 48 deletions

File tree

examples/crm/objectstack.config.ts

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,18 +255,103 @@ export default defineStack({
255255
object: 'account',
256256
mode: 'upsert',
257257
records: [
258-
{ _id: "1", name: "TechCorp", industry: "Technology", type: "Customer", billing_address: "100 Tech Blvd, Silicon Valley, CA", website: "https://techcorp.com", phone: "555-0100" },
259-
{ _id: "2", name: "Software Inc", industry: "Technology", type: "Partner", billing_address: "200 Cloud Way, Seattle, WA", website: "https://softwareinc.com", phone: "555-0200" },
260-
{ _id: "3", name: "Good Grief LLC", industry: "Retail", type: "Customer", billing_address: "300 Peanut Ave, Minneapolis, MN", website: "https://peanuts.com", phone: "555-0300" }
258+
{
259+
_id: "1",
260+
name: "ObjectStack HQ",
261+
industry: "Technology",
262+
type: "Partner",
263+
billing_address: "44 Tehama St, San Francisco, CA 94105",
264+
latitude: 37.7879,
265+
longitude: -122.3961,
266+
website: "https://objectstack.com",
267+
phone: "555-0101"
268+
},
269+
{
270+
_id: "2",
271+
name: "Salesforce Tower",
272+
industry: "Technology",
273+
type: "Customer",
274+
billing_address: "415 Mission St, San Francisco, CA 94105",
275+
latitude: 37.7897,
276+
longitude: -122.3972,
277+
website: "https://salesforce.com",
278+
phone: "555-0102"
279+
},
280+
{
281+
_id: "3",
282+
name: "Central Park Office",
283+
industry: "Finance",
284+
type: "Customer",
285+
billing_address: "New York, NY",
286+
latitude: 40.7829,
287+
longitude: -73.9654,
288+
website: "https://finance.example.com",
289+
phone: "555-0103"
290+
},
291+
{
292+
_id: "4",
293+
name: "London Branch",
294+
industry: "Finance",
295+
type: "Partner",
296+
billing_address: "London, UK",
297+
latitude: 51.5074,
298+
longitude: -0.1278,
299+
website: "https://uk.example.com",
300+
phone: "555-0104"
301+
},
302+
{
303+
_id: "5",
304+
name: "Tokyo Innovation Center",
305+
industry: "Technology",
306+
type: "Vendor",
307+
billing_address: "Tokyo, Japan",
308+
latitude: 35.6762,
309+
longitude: 139.6503,
310+
website: "https://jp.example.com",
311+
phone: "555-0105"
312+
}
261313
]
262314
},
263315
{
264316
object: 'contact',
265317
mode: 'upsert',
266318
records: [
267-
{ _id: "1", name: "Alice Johnson", email: "alice@example.com", phone: "555-0101", title: "VP Sales", company: "TechCorp", status: "Active" },
268-
{ _id: "2", name: "Bob Smith", email: "bob@tech.com", phone: "555-0102", title: "Developer", company: "Software Inc", status: "Lead" },
269-
{ _id: "3", name: "Charlie Brown", email: "charlie@peanuts.com", phone: "555-0103", title: "Manager", company: "Good Grief LLC", status: "Customer" }
319+
{
320+
_id: "1",
321+
name: "Alice Johnson",
322+
email: "alice@example.com",
323+
phone: "555-0101",
324+
title: "VP Sales",
325+
company: "TechCorp",
326+
status: "Active",
327+
latitude: 40.7128,
328+
longitude: -74.0060, // NYC
329+
address: "New York, NY"
330+
},
331+
{
332+
_id: "2",
333+
name: "Bob Smith",
334+
email: "bob@tech.com",
335+
phone: "555-0102",
336+
title: "Developer",
337+
company: "Software Inc",
338+
status: "Lead",
339+
latitude: 47.6062,
340+
longitude: -122.3321, // Seattle
341+
address: "Seattle, WA"
342+
},
343+
{
344+
_id: "3",
345+
name: "Charlie Brown",
346+
email: "charlie@peanuts.com",
347+
phone: "555-0103",
348+
title: "Manager",
349+
company: "Good Grief LLC",
350+
status: "Customer",
351+
latitude: 44.9778,
352+
longitude: -93.2650, // Minneapolis
353+
address: "Minneapolis, MN"
354+
}
270355
]
271356
},
272357
{

examples/crm/server.ts

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -54,45 +54,10 @@ async function startServer() {
5454

5555
// Seed Data
5656
try {
57-
// Products
58-
const products = await memoryDriver.find('product');
59-
if (!products || products.length === 0) {
60-
logger.info('🌱 Seeding Products...');
61-
const dummyProducts = [
62-
{ name: 'MacBook Pro 16"', sku: 'MBP16', category: 'Electronics', price: 2499, stock: 45, image: 'https://images.unsplash.com/photo-1517336714731-489689fd1ca4?auto=format&fit=crop&q=80&w=1000' },
63-
{ name: 'Ergonomic Office Chair', sku: 'CHAIR-v2', category: 'Furniture', price: 599, stock: 120, image: 'https://images.unsplash.com/photo-1505843490538-5133c6c7d0e1?auto=format&fit=crop&q=80&w=1000' },
64-
{ name: 'Wireless Noise Canceling Headphones', sku: 'AUDIO-X1', category: 'Electronics', price: 349, stock: 85, image: 'https://images.unsplash.com/photo-1505740420928-5e560c06d30e?auto=format&fit=crop&q=80&w=1000' },
65-
{ name: 'Standing Desk', sku: 'DESK-PRO', category: 'Furniture', price: 799, stock: 30, image: 'https://images.unsplash.com/photo-1595515106969-1ce29566ff1c?auto=format&fit=crop&q=80&w=1000' },
66-
{ name: 'Smart Watch Series 7', sku: 'WATCH-S7', category: 'Electronics', price: 399, stock: 200, image: 'https://images.unsplash.com/photo-1546868871-7041f2a55e12?auto=format&fit=crop&q=80&w=1000' },
67-
{ name: 'Bluetooth Speaker', sku: 'SPK-BT', category: 'Electronics', price: 129, stock: 150, image: 'https://images.unsplash.com/photo-1608043152269-423dbba4e7e1?auto=format&fit=crop&q=80&w=1000' },
68-
];
69-
for (const p of dummyProducts) {
70-
await memoryDriver.create('product', p);
71-
}
72-
}
73-
74-
// Events
75-
const events = await memoryDriver.find('event');
76-
if (!events || events.length === 0) {
77-
logger.info('🌱 Seeding Events...');
78-
const now = new Date();
79-
const dummyEvents = [
80-
{ subject: 'Client Meeting', start: now, end: new Date(now.getTime() + 3600000), location: 'Zoom', type: 'Meeting' },
81-
{ subject: 'Project Kickoff', start: new Date(now.getTime() + 86400000), end: new Date(now.getTime() + 90000000), location: 'Conference Room', type: 'Meeting' }
82-
];
83-
for(const e of dummyEvents) await memoryDriver.create('event', e);
84-
}
85-
86-
// Projects
87-
const tasks = await memoryDriver.find('project_task');
88-
if (!tasks || tasks.length === 0) {
89-
logger.info('🌱 Seeding Projects...');
90-
const dummyTasks = [
91-
{ name: 'Phase 1: Research', start_date: '2023-11-01', end_date: '2023-11-10', progress: 100, status: 'Completed', priority: 'High', color: '#4caf50' },
92-
{ name: 'Phase 2: Design', start_date: '2023-11-11', end_date: '2023-11-25', progress: 50, status: 'In Progress', priority: 'High', color: '#2196f3' }
93-
];
94-
for(const t of dummyTasks) await memoryDriver.create('project_task', t);
95-
}
57+
// Data is now seeded via manifest in objectstack.config.ts loaded by the app plugin
58+
// or handled by MSW in browser mode.
59+
// We can keep specific server-side seeding here if needed, but for now we rely on the manifest.
60+
logger.info('🌱 checking if data needs seeding...');
9661

9762
} catch (e) {
9863
logger.error(e, 'Failed to seed data');

examples/crm/src/objects/account.object.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export const AccountObject = ObjectSchema.create({
1313
website: Field.url({ label: 'Website' }),
1414
phone: Field.text({ label: 'Phone' }),
1515
billing_address: Field.textarea({ label: 'Billing Address' }),
16+
latitude: Field.number({ label: 'Latitude', scale: 6 }),
17+
longitude: Field.number({ label: 'Longitude', scale: 6 }),
1618
owner: Field.lookup('user', { label: 'Owner' })
1719
},
1820
list_views: {
@@ -21,10 +23,14 @@ export const AccountObject = ObjectSchema.create({
2123
columns: ['name', 'industry', 'type', 'phone', 'website']
2224
},
2325
map_view: {
24-
label: 'Account Map',
26+
label: 'Map View',
2527
type: 'map',
26-
locationField: 'billing_address',
27-
titleField: 'name'
28+
latitudeField: 'latitude',
29+
longitudeField: 'longitude',
30+
titleField: 'name',
31+
descriptionField: 'billing_address',
32+
zoom: 3,
33+
center: [37.7749, -122.4194] // SF
2834
} as any,
2935
customers: {
3036
label: 'Customers',

examples/crm/src/objects/contact.object.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export const ContactObject = ObjectSchema.create({
1313
account: Field.lookup('account', { label: 'Account' }),
1414
status: Field.select(['Active', 'Lead', 'Customer'], { label: 'Status' }),
1515
priority: Field.select(['High', 'Medium', 'Low'], { label: 'Priority', defaultValue: 'Medium' }),
16+
address: Field.textarea({ label: 'Address' }),
17+
latitude: Field.number({ label: 'Latitude', scale: 6 }),
18+
longitude: Field.number({ label: 'Longitude', scale: 6 }),
1619
is_active: Field.boolean({ label: 'Active', defaultValue: true }),
1720
notes: Field.textarea({ label: 'Notes' })
1821
},
@@ -21,6 +24,16 @@ export const ContactObject = ObjectSchema.create({
2124
label: 'All Contacts',
2225
columns: ['name', 'account', 'email', 'phone', 'title', 'status']
2326
},
27+
map_view: {
28+
label: 'Map View',
29+
type: 'map',
30+
latitudeField: 'latitude',
31+
longitudeField: 'longitude',
32+
titleField: 'name',
33+
descriptionField: 'title',
34+
zoom: 12,
35+
center: [-73.935242, 40.730610] // NYC
36+
} as any,
2437
mypending: {
2538
label: 'My Pending Contacts',
2639
columns: ['name', 'account', 'status', 'priority'],

0 commit comments

Comments
 (0)