Skip to content

Commit 94fd944

Browse files
committed
refactor: simplify data access methods in startMockServer and seedData functions
1 parent 914c407 commit 94fd944

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

examples/crm-app/src/mocks/runtime.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ export async function startMockServer() {
4343

4444
try {
4545
const objectql = kernel!.getService<any>('objectql');
46-
const user = (await objectql.getObject('user').findOne('current', {}, session)) || {};
47-
const contacts = await objectql.getObject('contact').find({}, session);
48-
const opportunities = await objectql.getObject('opportunity').find({}, session);
46+
// Use IDataEngine interface directly
47+
const user = (await objectql.findOne('user', 'current')) || {};
48+
const contacts = await objectql.find('contact', {});
49+
const opportunities = await objectql.find('opportunity', {});
4950
const stats = { revenue: 125000, leads: 45, deals: 12 };
5051

5152
return HttpResponse.json({
@@ -77,21 +78,21 @@ async function seedData(kernel: ObjectKernel) {
7778

7879
// Seed User
7980
if (mockData.user) {
80-
// ObjectQL insert usually needs specific structure, but we try simplest first
81-
await objectql.getObject('user').insert({ ...mockData.user, id: 'current', _id: 'current' }, session);
81+
// Use IDataEngine interface directly: insert(object, data)
82+
await objectql.insert('user', { ...mockData.user, id: 'current', _id: 'current' });
8283
}
8384

8485
// Seed Contacts
8586
if (mockData.contacts) {
8687
for (const contact of mockData.contacts) {
87-
await objectql.getObject('contact').insert({ ...contact, _id: contact.id }, session);
88+
await objectql.insert('contact', { ...contact, _id: contact.id });
8889
}
8990
}
9091

9192
// Seed Opportunities
9293
if (mockData.opportunities) {
9394
for (const opp of mockData.opportunities) {
94-
await objectql.getObject('opportunity').insert({ ...opp, _id: opp.id }, session);
95+
await objectql.insert('opportunity', { ...opp, _id: opp.id });
9596
}
9697
}
9798

@@ -103,7 +104,7 @@ async function seedData(kernel: ObjectKernel) {
103104
];
104105

105106
for (const acc of accounts) {
106-
await objectql.getObject('account').insert({ ...acc, _id: acc.id }, session);
107+
await objectql.insert('account', { ...acc, _id: acc.id });
107108
}
108109

109110
console.log('[MockServer] Data seeded successfully');

0 commit comments

Comments
 (0)