Extending route

Hi Team,

Could you give me some guidance about extending a route for getting all records in the collection?

// Get a list of Users
router.get('/users', permissionMiddlewareCreator.list(), (request, response, next) => {
// Learn what this route does here: https://docs.forestadmin.com/documentation/v/v5/reference-guide/routes/default-routes#get-a-list-of-records
next();
});

We have one field which has numeric values from 0 to 5. Every value should be presented as a string. For example:
0 - val1
1 - val2
2 - val3

The question is how to convert the value from DB to some other value to be presented to the view?

Thank you,
Bojan

1 Like

Hi @Bojan_Antonijevic,

Thank you for your question.

Does this link help ? It shows the steps to a list route.

You should be able to add your logic in there.

1 Like

Hi @anon79585656,

Thank you on a quick answer. I checked the solution but didn’t help much.
I need basically:

  1. Get all records
  2. Foreach all records
  3. Check specific field value
  4. If is 0 set value as val1, if is 1set value as val2
  5. Return all records in the view with changed values.

Could you give me example of that if is in your support work scope?

Thanks

1 Like

Sorry I might have jumped too quickly to a “code” solution.

This post might help : Set label for Number field

The ForestAdmin already lets you setup a mapping between your DB values and what is displayed.
You can find the same subject in our documentation here: https://docs.forestadmin.com/documentation/reference-guide/fields/customize-your-fields#display-settings

Let me know if you prefer the code solution.

2 Likes

Thanks @anon79585656,

This is exactly what we need. At least for now.
Ping you if we need code solution.

1 Like