Woodshop
Search…
Display Dwolla customers
This example shows you how to create a smart collection to list the customers of your Dwolla account.

1. Define the smart collection

Filterable fields are flagged using isFilterable: true. You will need to enable this option using the collection settings in the Layout Editor.
Customers have isSearchable flag enabled: it means the search input field will be activated on the collection UI.
1
// forest/dwolla-customers.js
2
const { collection } = require('forest-express-sequelize');
3
4
collection('dwollaCustomers', {
5
isSearchable: true,
6
actions: [],
7
fields: [
8
{
9
field: 'id',
10
type: 'String',
11
},
12
{
13
field: 'firstName',
14
type: 'String',
15
},
16
{
17
field: 'lastName',
18
type: 'String',
19
},
20
{
21
field: 'fullName',
22
type: 'String',
23
get: (customer) => {
24
return customer.firstName + ' ' + customer.lastName;
25
},
26
},
27
{
28
field: 'type',
29
type: 'Enum',
30
enums: ['unverified', 'personal', 'business', 'receive-only'],
31
},
32
{
33
field: 'email',
34
type: 'String',
35
isFilterable: true,
36
},
37
{
38
field: 'businessName',
39
type: 'String',
40
isFilterable: true,
41
},
42
{
43
field: 'created', //created_at
44
type: 'Date',
45
},
46
{
47
field: 'status',
48
type: 'Enum',
49
enums: ['unverified', 'suspended', 'retry', 'document', 'verified'],
50
isFilterable: true,
51
},
52
{
53
field: 'fundingSources',
54
type: ['String'],
55
reference: 'dwollaFundingSources.id',
56
},
57
{
58
field: 'transfers',
59
type: ['String'],
60
reference: 'dwollaTransfers.id',
61
},
62
],
63
segments: [],
64
});
Copied!

2. Implement the route

The Customers routes implement the Get List and Get One, plus the smart relationships (HasMany):
  • Funding Sources
  • Transfers
These routes use the Dwolla service described in another section.
1
// routes/customers.js
2
const express = require('express');
3
const { PermissionMiddlewareCreator, RecordSerializer } = require('forest-express-sequelize');
4
5
const DwollaService = require('../services/dwolla-service');
6
let dwollaService = new DwollaService(process.env.DWOLLA_APP_KEY, process.env.DWOLLA_APP_SECRET, process.env.DWOLLA_ENVIRONMENT);
7
8
const MODEL_NAME = 'dwollaCustomers';
9
10
const router = express.Router();
11
const permissionMiddlewareCreator = new PermissionMiddlewareCreator(`${MODEL_NAME}`);
12
13
// Get a list of Customers
14
router.get(`/${MODEL_NAME}`, permissionMiddlewareCreator.list(), (request, response, next) => {
15
16
dwollaService.getCustomers(request.query)
17
.then(async result => {
18
const recordSerializer = new RecordSerializer({ name: MODEL_NAME });
19
const recordsSerialized = await recordSerializer.serialize(result.list);
20
response.send({ ...recordsSerialized, meta:{ count: result.count }});
21
})
22
.catch(next);
23
24
});
25
26
// Get a Customer
27
router.get(`/${MODEL_NAME}/:recordId`, permissionMiddlewareCreator.details(), (request, response, next) => {
28
const recordId = request.params.recordId;
29
dwollaService.getCustomer(recordId)
30
.then(async record => {
31
const recordSerializer = new RecordSerializer({ name: MODEL_NAME });
32
const recordSerialized = await recordSerializer.serialize(record);
33
response.send(recordSerialized);
34
})
35
.catch(next);
36
37
});
38
39
router.get(`/${MODEL_NAME}/:recordId/relationships/fundingSources`, (request, response, next) => {
40
const recordId = request.params.recordId;
41
dwollaService.getCustomerFundingSources(recordId, request.query)
42
.then(async result => {
43
const recordSerializer = new RecordSerializer({ name: 'dwollaFundingSources' });
44
const recordsSerialized = await recordSerializer.serialize(result.list);
45
response.send({ ...recordsSerialized, meta:{ count: result.count }});
46
})
47
.catch(next);
48
});
49
50
router.get(`/${MODEL_NAME}/:recordId/relationships/transfers`, (request, response, next) => {
51
const recordId = request.params.recordId;
52
dwollaService.getCustomerTransfers(recordId, request.query)
53
.then(async result => {
54
const recordSerializer = new RecordSerializer({ name: 'dwollaTransfers' });
55
const recordsSerialized = await recordSerializer.serialize(result.list);
56
response.send({ ...recordsSerialized, meta:{ count: result.count }});
57
})
58
.catch(next);
59
});
60
61
module.exports = router;
Copied!
Last modified 9mo ago