-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path5-api.mjs
More file actions
26 lines (21 loc) · 708 Bytes
/
Copy path5-api.mjs
File metadata and controls
26 lines (21 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// server: application/api/crm/createAccount.js
({
parameters: {
name: 'string',
age: { type: 'number', min: 16 },
address: 'Address',
},
method: async ({ name, age, address }) => {
const processed = await db.select('Account', { name });
if (processed) return { exists: true, status: 'registered' };
const cityId = await db.select('City', { name: address.city });
const accountId = await db.insert('Account', { name, age, city });
return { exists: true, status: 'inserted' };
},
returns: {
exists: 'boolean',
status: { enum: ['inserted', 'restricted', 'registered'] },
},
});
// client
const res = await api.crm.createAccount({ name, age, address });