Woodshop
Search…
View tickets related to a user
Now, let's say we want to access the tickets for a user of my database. We are going to use the email address as the foreign key between the database model (Users table) and Zendesk tickets.
First, we need to create the Smart Relationship between Users and zendesk_tickets as follows:
forest/users.js
1
collection('users', {
2
actions: [],
3
fields: [
4
{
5
field: 'ze_requested_tickets',
6
type: ['String'],
7
reference: 'zendesk_tickets.id',
8
},
9
],
10
segments: [],
11
});
Copied!
Then, we need to implement the Smart Relationship route. This route will query the Zendesk tickets related to the user's email (requested field on zendesk_tickets).
routes/users.js
1
const {getTickets} = require('../services/zendesk-tickets-service');
2
3
router.get('/users/:userId/relationships/ze_requested_tickets', async (request, response, next) => {
4
// Get the user email for filtering on requester
5
const user = await users.findByPk(request.params.userId);
6
const additionalFilter = `requester:${user.email}`;
7
getTickets(request, response, next, additionalFilter);
8
});
Copied!
Now, you should see the requested tickets for a user:
Copy link